diff options
author | Jakob Kaivo <jkk@ung.org> | 2018-10-07 23:09:59 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2018-10-07 23:09:59 -0400 |
commit | 29a453aec64d3833be2ceb109ac4a9c6c31d3ec2 (patch) | |
tree | 21b6c7ef0d5a169dd344802d44cfe4edb5baa7f3 | |
parent | c6b6dc4083f8330be9576d13f317a054405c17d3 (diff) |
better support for long format output
-rwxr-xr-x | color-ls | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -25,9 +25,8 @@ # TODO: handle recursive stuff output=x # TODO: change this back to -C when that is fixed +long=0 dash_F_specified= -need_dash_F=1 -dash_1= _columns_down () { awk -vwidest=0 ' @@ -48,7 +47,7 @@ _columns_down () { ncolumns = columns / widest; i = 1; - while (i < NR) { + while (i <= NR) { # FIXME: this is all jacked up printf("%-*s", widest, all[(row * ncolumns) + (i % ncolumns)]); column += widest; @@ -84,7 +83,7 @@ _columns_across () { } i = 1; - while (i < NR) { + while (i <= NR) { printf("%-*s", widest, all[i]); column += widest; if (column > columns) { @@ -117,20 +116,19 @@ _output () { C) _columns_down;; x) _columns_across;; m) _commas;; - 1|g|l|n|o) cat;; + 1|l|o|n|g) cat;; esac } # TODO: grab first character from long listings _colorize () { - awk -vcolor=0 ' + awk -vcolor=0 -vlong=${long} ' { color=39; } - /\/$/ { color=34; } + /\/$/ || (long && /^d/) { color=34; } /\*$/ { color=32; } - /\|$/ { color=33; } - /@$/ { color=35; } - / -> / { color=35; } - { printf("\033\[%sm%s\033\[0m\n", color, $0); }' + /\|$/ || (long && /^p/) { color=33; } + /@$/ || (long && /^l/) { color=35; } + long { printf("\033\[%sm%s\033\[0m\n", color, $0); }' } _remove_symbols () { @@ -144,15 +142,15 @@ _remove_symbols () { while getopts ACFHLRSacdfgiklmopqrstux1 option do case $option in - g|l|n|o) output=${option}; dash_1=''; need_dash_F=0;; - C|m|x) output=${option}; dash_1=-1; need_dash_F=1;; - 1) output=1; dash_1='';; + l|o|n|g) output=${option}; long=1;; + C|m|x) output=${option}; long=0;; + 1) output=1;; F) dash_F_specified=-F;; ?) ;; esac done -if [ ${need_dash_F} == 1 ]; then +if [ ${long} == 0 ]; then dash_F=-F fi |