Jump to content


Photo
- - - - -

Alias for colorized `ls` for GNU and BSD ls


  • Please log in to reply
No replies to this topic

#1 systems_glitch

systems_glitch

    Dangerous free thinker

  • Moderating Team
  • 1,660 posts
  • Gender:Male

Posted 01 August 2013 - 10:29 AM

I recently committed my dotfiles to a git repo, and discovered that GNU ls and BSD ls use different switches to colorize output. Using the GNU switch with BSD ls results in ls not working until you unalias it! Here's a snippet from my .bashrc that takes care of it:

# alias `ls` for color mode
if ls --color=auto / >/dev/null 2>&1
then
alias ls='ls --color=auto' # GNU ls
else
alias ls='ls -G' # BSD ls
fi

Basically, if the GNU switch works, use the GNU switch; otherwise, use the BSD switch.






BinRev is hosted by the great people at Lunarpages!