Rejustify columns after replacing with user sym with a little ruby golf

This commit is contained in:
Nathan Broadbent
2012-10-14 13:35:10 +13:00
parent e6ad742cc7
commit b7b3272270

View File

@@ -85,7 +85,11 @@ if [ "$_uname" = "Linux" ]; then
# 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
# After : -rw-rw-r-- 1 𝐍 𝐍 1.1K Sep 19 21:39 scm_breeze.sh # After : -rw-rw-r-- 1 𝐍 𝐍 1.1K Sep 19 21:39 scm_breeze.sh
if [ -e $HOME/.user_sym ]; then if [ -e $HOME/.user_sym ]; then
_ll_command+=" | sed \"s/$USER/\$(/bin/cat $HOME/.user_sym)/g\"" # Little bit of ruby golf to rejustify the user/group/size columns after replacement
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]}}"
}
_ll_command+=" | sed 1d | sed \"s/$USER/\$(/bin/cat $HOME/.user_sym)/g\" | _rejustify_ls_columns"
fi fi
elif [ "$_uname" = "Darwin" ]; then elif [ "$_uname" = "Darwin" ]; then
# OS X ls commands # OS X ls commands