diff options
author | Jakob Kaivo <jkk@ung.org> | 2018-10-08 12:31:22 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2018-10-08 12:31:22 -0400 |
commit | c96a1c7f9cea82470a99691d2832c6599c8eff10 (patch) | |
tree | ea286319deba02ff13f6daa1dbf0e4cb09530dc5 | |
parent | 0561efd31a7161d611bb9bcd6ff16b27ba32e14d (diff) |
move some variable processing to BEGIN
-rwxr-xr-x | color-ls | 11 | ||||
-rwxr-xr-x | color-ls.awk | 8 |
2 files changed, 11 insertions, 8 deletions
@@ -25,24 +25,19 @@ # TODO: handle recursive stuff # TODO: change this back to -C when that is fixed output=x -long=0 trim=1 while getopts ACFHLRSacdfgiklmnopqrstux1 option do case $option in - l|o|n|g) output=${option}; long=1;; - C|m|x) output=${option}; long=0;; + l|o|n|g) output=${option};; + C|m|x) output=${option};; 1) output=1;; F) trim=0;; ?) ;; esac done -if [ ${long} == 0 ]; then - dash_F=-F -fi - # FIXME: the script returns 0 even if ls does not # FIXME: always pass -1 when needed, but do it before operands -ls $dash_F ${1+$@} | awk -vwidest=0 -vlong=${long} -vtrim=${trim} -voutput=${output} -f $(dirname $0)/color-ls.awk +ls -F ${1+$@} | awk -vtrim=${trim} -voutput=${output} -f $(dirname $0)/color-ls.awk diff --git a/color-ls.awk b/color-ls.awk index fc5855c..e19c77a 100755 --- a/color-ls.awk +++ b/color-ls.awk @@ -22,6 +22,14 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +BEGIN { + long = 0; + widest = 0; + if (output == "l" || output == "o" || output == "n" || output == "g") { + long = 1; + } +} + function columns_down() { widest++; column = 0; |