lh and lt compatible with macOS
dblume

dblume commited on 2024-01-21 22:15:33
Showing 1 changed files, with 10 additions and 5 deletions.

... ...
@@ -151,19 +151,24 @@ alias clip="expand | cut -b1-\$COLUMNS"
151 151
 # I'm often interested in just the most recently changed file
152 152
 # N.B. If changing -l to -1, remove tail, because "total" line is only for -l
153 153
 lh() {
154
-#    ls --color=always -1tqh "$@" | head -$(($LINES/3))
155
-    ls --color=always -ltqh "$@" | head -$(($LINES/3)) | tail --lines=+2
156
-    if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/3)) ]; then
154
+    if [[ $(uname -s) != Darwin* ]]; then
155
+        readonly color_always="--color=always"
156
+    fi
157
+    ls $color_always -ltqh "$@" | head -$(($LINES/4)) | tail -n +2
158
+    if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/4)) ]; then
157 159
         echo ...
158 160
     fi
159 161
 }
160 162
 
161 163
 # lh = "ls | head" (newest at top), lt = "ls | tail" (newest at the bottom)
162 164
 lt() {
163
-    if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/3)) ]; then
165
+    if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/4)) ]; then
164 166
         echo ...
165 167
     fi
166
-    ls --color=always -rltqh "$@" | tail --lines=$(($LINES/3))
168
+    if [[ $(uname -s) != Darwin* ]]; then
169
+        readonly color_always="--color=always"
170
+    fi
171
+    ls $color_always -rltqh "$@" | tail -n $(($LINES/4))
167 172
 }
168 173
 
169 174
 # For httpie: https://github.com/jakubroztocil/httpie#installation
170 175