From: Simon Ruderich Date: Fri, 3 Oct 2008 16:33:26 +0000 (+0200) Subject: Use colorized output with normal ls when GNU ls is not available. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=044ed79a3c32ea656b80a3dc933400e585e23d67;p=config%2Fdotfiles.git Use colorized output with normal ls when GNU ls is not available. --- diff --git a/shell/env b/shell/env index a7f7405..84705b6 100644 --- a/shell/env +++ b/shell/env @@ -13,13 +13,29 @@ export EDITOR PAGER=less export PAGER -# Set colors for ls (and zsh completions). This colors files normal (fi), +# Set colors for GNU ls (and zsh completions). This colors files normal (fi), # directories blue bold (di), symbolic links cyan (ln), named pipes normal # (pi), sockets normal (so), block devices normal (bd), character devices # normal (cd) and executables bold red (ex). # See `dircolors --print-database` for possible colors. LS_COLORS='no=00:fi=00:di=34;01:ln=36:pi=00:so=00:bd=00:cd=00:ex=31;01' export LS_COLORS +# Set the same colors for non GNU ls. +LSCOLORS='ExgxxxxxBxxxxxBxBxExEx' +# ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ +# | | | | | | | | | | | +# | | | | | | | | | | *- directory writable to others, without sticky bit +# | | | | | | | | | *--- directory writable to others, with sticky bit +# | | | | | | | | *----- executable with setgid bit set +# | | | | | | | *------- executable with setuid bit set +# | | | | | | *--------- character special +# | | | | | *----------- block special +# | | | | *------------- executable +# | | | *--------------- pipe +# | | *----------------- socket +# | *------------------- symbolic link +# *--------------------- directory +export LSCOLORS # Sources a configuration file if it exists; loads a fallback .local file if diff --git a/zsh/rc b/zsh/rc index 618e7d1..b16a5ca 100644 --- a/zsh/rc +++ b/zsh/rc @@ -98,6 +98,17 @@ alias -g G='| grep' # Improved ls which displays the files in columns (-C), visualises directories, # links and other special files (-F) and pages everything through less (L). +# +# If available use GNU ls with colorized output. If it isn't available use +# normal ls which needs CLICOLOR_FORCE so it displays colors when used with a +# pager. +ls --color &> /dev/null +if [[ $? -eq 0 ]]; then + alias ls='ls --color' +else + alias ls='CLICOLOR_FORCE=1 ls -G' +fi +# Main ls function. function ls() { command ls -C -F $* L }