From b7b3272270f9e83805ca66bc296a4e1620f19625 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sun, 14 Oct 2012 13:35:10 +1300 Subject: [PATCH] Rejustify columns after replacing with user sym with a little ruby golf --- lib/git/shell_shortcuts.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 916499d..0a3a2fc 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -85,7 +85,11 @@ if [ "$_uname" = "Linux" ]; then # 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 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 elif [ "$_uname" = "Darwin" ]; then # OS X ls commands