aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/tree.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-26 14:03:41 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-26 14:08:32 +1200
commitd2020a162649b00fbab66283c61cb57985c3cc4f (patch)
treeba9fcb7884709c938154f47adb5c4d67f77f0318 /sh/shrc.d/tree.sh
parentAdd tree() (diff)
downloaddotfiles-d2020a162649b00fbab66283c61cb57985c3cc4f.tar.gz
dotfiles-d2020a162649b00fbab66283c61cb57985c3cc4f.zip
Improvements to tree() to handle color options
Diffstat (limited to 'sh/shrc.d/tree.sh')
-rw-r--r--sh/shrc.d/tree.sh28
1 files changed, 25 insertions, 3 deletions
diff --git a/sh/shrc.d/tree.sh b/sh/shrc.d/tree.sh
index 5feb8ca3..dd78f8ee 100644
--- a/sh/shrc.d/tree.sh
+++ b/sh/shrc.d/tree.sh
@@ -2,8 +2,30 @@
# color its output by default without it; this will coax it into doing so with
# the default colors when writing to a terminal.
tree() {
- [ -t 1 ] &&
- [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
+
+ # Subshell will run the tests to check if we should color the output
+ if (
+
+ # Not if -n is in the arguments and -C isn't
+ while getopts 'nC' opt ; do
+ case $opt in
+ n) n=1 ;;
+ C) C=1 ;;
+ esac
+ done
+ [ -z "$C" ] || exit 0
+ [ -z "$n" ] || exit 1
+
+ # Not if output isn't a terminal
+ [ -t 1 ] || exit
+
+ # Not if output terminal doesn't have at least 8 colors
+ [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] || exit
+
+ ) ; then
set -- -C "$@"
- command "$@"
+ fi
+
+ # Run the command with the determined arguments
+ command tree "$@"
}