Reorganized code, added la alias to show all files

This commit is contained in:
Nathan Broadbent
2012-10-14 13:43:22 +13:00
parent b7b3272270
commit 8a330465b4

View File

@@ -80,6 +80,13 @@ if [ "$_uname" = "Linux" ]; then
_ll_command="ls -lhv --group-directories-first --color" _ll_command="ls -lhv --group-directories-first --color"
_ll_sys_command="ls -v --group-directories-first --color=never" _ll_sys_command="ls -v --group-directories-first --color=never"
_abs_path_command="readlink -f" _abs_path_command="readlink -f"
elif [ "$_uname" = "Darwin" ]; then
# OS X ls commands
_ll_command="ls -l -G"
_ll_sys_command="ls"
# Use perl abs_path, since readlink -f isn't available on OS X
_abs_path_command="perl -e 'use Cwd \"abs_path\"; print abs_path(shift)'"
fi
# Replace user/group with user symbol, if defined at ~/.user_sym # Replace user/group with user symbol, if defined at ~/.user_sym
# Before : -rw-rw-r-- 1 ndbroadbent ndbroadbent 1.1K Sep 19 21:39 scm_breeze.sh # Before : -rw-rw-r-- 1 ndbroadbent ndbroadbent 1.1K Sep 19 21:39 scm_breeze.sh
@@ -89,22 +96,16 @@ if [ "$_uname" = "Linux" ]; then
function rejustify_ls_columns(){ function rejustify_ls_columns(){
ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}" ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}"
} }
_ll_command+=" | sed 1d | sed \"s/$USER/\$(/bin/cat $HOME/.user_sym)/g\" | _rejustify_ls_columns" _ls_processor="| sed \"s/$USER/\$(/bin/cat $HOME/.user_sym)/g\" | rejustify_ls_columns"
fi
elif [ "$_uname" = "Darwin" ]; then
# OS X ls commands
_ll_command="ls -l -G"
_ll_sys_command="ls"
# Use perl abs_path, since readlink -f isn't available on OS X
_abs_path_command="perl -e 'use Cwd \"abs_path\"; print abs_path(shift)'"
fi fi
if [ -n "$_ll_command" ]; then if [ -n "$_ll_command" ]; then
# Function wrapper around 'll' # Function wrapper around 'll'
# Adds numbered shortcuts to output of ls -l, just like 'git status' # 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 unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
function ll { function ll {
local ll_output="$(eval $_ll_command $@)" local ll_output="$(eval $_ll_command $@ $_ls_processor)"
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
echo -e "\e[33mToo many files to create shortcuts. Running plain ll command...\e[0m" echo -e "\e[33mToo many files to create shortcuts. Running plain ll command...\e[0m"
@@ -133,3 +134,6 @@ EOF
IFS="$OLDIFS" IFS="$OLDIFS"
} }
fi fi
# Alias to list all files
alias la="ll -A"