small formatting fix, refactor, remove 1st line
authorIan Kelling <ian@iankelling.org>
Wed, 28 May 2014 18:10:47 +0000 (11:10 -0700)
committerIan Kelling <ian@iankelling.org>
Fri, 9 Sep 2016 21:06:16 +0000 (14:06 -0700)
ll-function

index 2776ff400399a2658954c000d2c81beb561e6fb8..f2ccb1c004cbddee625c97cd40ebc42a71e7399a 100644 (file)
@@ -33,17 +33,17 @@ ll() {
     #  or blank for no other kind of acl
     #  I don't want to see this generally.
     while read line; do
-        lines+=("$line")
-        [[ ! ${line:10:11} == " " ]] && aclchar=true
+       if $first; then
+           first=false
+        else
+            # if we did want the first line, it would need to be stripped of non-printing chars:
+           # line=${line#$'\E[00m'}
+            lines+=("$line")
+            [[ ! ${line:10:1} == " " ]] && aclchar=true
+        fi
     done< <( "$binls" -lAh --color=always "--time-style=+%m-%d     %Y
 %m-%d %I:%M %P" "$@" )
-    
     for line in "${lines[@]}"; do
-       # very first line starts with some non printing chars
-       if $first; then
-           line=${line#$'\E[00m'}
-           first=false
-       fi
        if ! [[ $line == [-dscbl][-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT]* ]]; then
            printf "%s\n" "$line"
        else
@@ -62,9 +62,10 @@ ll() {
             else
                 y="${line:10}"
             fi
-            t="${y#"${y%%[![:space:]]*}"}" # remove any initial spaces
-            hardLinks="${t%%[[:space:]]*}" # remove everything beyond first word
-            z=$(( ${#y} - ${#t} + ${#hardLinks} )) # length of hardlink string including padding
+            initial_space="${y%%[![:space:]]*}"
+            hardLinks="${y#$initial_space}" # remove any initial spaces
+            hardLinks="${hardLinks%%[[:space:]]*}" # remove everything beyond first word
+            hardLink_spacing=$(( ${#initial_space} + ${#hardLinks} )) # length of hardlink string including padding
            middle=${y#*[^ ]* }
            size=${middle#*[^ ]* *[^ ]* }
            middle=${middle%"$size"}
@@ -80,7 +81,7 @@ ll() {
                 hardLinks=$(( hardLinks - 1 ))
             fi
            [[ $hardLinks == 0 ]] && hardLinks=
-           printf "%s%4o%${z}s%s%${sizePadding}s%s\n" \
+           printf "%s%4o%${hardLink_spacing}s%s%${sizePadding}s%s\n" \
                   "${line:0:1}" $perm "$hardLinks" " $middle" "$size" " $tail"
        fi
     done