small formatting fix, refactor, remove 1st line
[small-misc-bash] / ll-function
index 6fb746bc0fe9f67190b0bdd9285d833cd61ec5a3..f2ccb1c004cbddee625c97cd40ebc42a71e7399a 100644 (file)
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 
-# ls -lA with enhanced formatting
+# ls -lA with enhanced output
 # octal permissions
 # omited acl type specifier
 # better hard link count: number of subdirectories or number of linked files or omitted if 0
@@ -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
-    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
+        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
        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