summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2018-10-08 12:31:22 -0400
committerJakob Kaivo <jkk@ung.org>2018-10-08 12:31:22 -0400
commitc96a1c7f9cea82470a99691d2832c6599c8eff10 (patch)
treeea286319deba02ff13f6daa1dbf0e4cb09530dc5
parent0561efd31a7161d611bb9bcd6ff16b27ba32e14d (diff)
move some variable processing to BEGIN
-rwxr-xr-xcolor-ls11
-rwxr-xr-xcolor-ls.awk8
2 files changed, 11 insertions, 8 deletions
diff --git a/color-ls b/color-ls
index 9840e7f..ca23c87 100755
--- a/color-ls
+++ b/color-ls
@@ -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;