Support both BSD and GNU ls commands (for OS X and Linux, respectively)

This commit is contained in:
Nathan Broadbent
2012-08-21 13:22:03 +12:00
parent dba367d7f1
commit 4ac4cba757

View File

@@ -49,13 +49,27 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
_git_wrap_commands _git_wrap_commands
fi fi
# Function wrapper around 'll'
# Adds numbered shortcuts to output of ls -l, just like 'git status' # BSD ls is different to Linux (GNU) ls
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1 _uname="$(uname)"
function ll { if [ "$_uname" = "Linux" ]; then
# Linux ls commands
_ll_command="ls -l --group-directories-first --color"
_ll_sys_command="ls --color=never"
elif [ "$_uname" = "Darwin" ]; then
# OS X ls commands
_ll_command="ls -l -G"
_ll_sys_command="ls"
fi
if [ -n "$_ll_command" ]; then
# Function wrapper around 'll'
# Adds numbered shortcuts to output of ls -l, just like 'git status'
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
function ll {
# Use ruby to inject numbers into ls output # Use ruby to inject numbers into ls output
ruby -e "$( cat <<EOF ruby -e "$( cat <<EOF
output = %x(ls -lv --group-directories-first --color) output = %x($_ll_command)
output.lines.each_with_index do |line, i| output.lines.each_with_index do |line, i|
puts line.sub(/^(([^ ]* +){8})/, "\\\1\e[2;37m[\e[0m#{i}\e[2;37m]\e[0m" << (i < 10 ? " " : " ")) puts line.sub(/^(([^ ]* +){8})/, "\\\1\e[2;37m[\e[0m#{i}\e[2;37m]\e[0m" << (i < 10 ? " " : " "))
end end
@@ -64,9 +78,10 @@ EOF
# Set numbered file shortcut in variable # Set numbered file shortcut in variable
local e=1 local e=1
for file in $(ls -v --group-directories-first --color=never); do for file in $($_ll_sys_command); do
export $git_env_char$e="$(readlink -f $file)" export $git_env_char$e="$(readlink -f $file)"
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
let e++ let e++
done done
} }
fi