From 3e64d543178e352c7d5e1bd6f902e27c6eb5af04 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 4 Mar 2018 18:19:01 +0100 Subject: [PATCH] [bash] improve `ls` aliases When the GNU version of `ls` is not installed (e.g. on a new Mac), the previous alias causes problems because the --group-directories-first option is not supported and makes `ls` fail. This commit fixes that by checking which version is installed and creating the alias accordingly. --- bashrc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bashrc b/bashrc index d23a1e3..6241494 100644 --- a/bashrc +++ b/bashrc @@ -24,13 +24,18 @@ do done # Useful aliases +if ls --group-directories-first >/dev/null 2>&1 +then + ls_dir_group="--group-directories-first" # GNU version +else + ls_dir_group="" # BSD version, doesn't support directory grouping +fi + alias g="git" -alias ls="ls -F --color=auto --group-directories-first" +alias ls="ls -hF --color=auto ${ls_dir_group}" alias la="ls -a" alias ll="ls -l" alias lla="ls -la" -alias llh="ls -lh" -alias llha="ls -lha" alias grep="grep --color=auto"; alias egrep="egrep --color=auto"; alias fgrep="fgrep --color=auto";