diff options
-rw-r--r-- | README.markdown | 2 | ||||
-rw-r--r-- | sh/shrc.d/tree.sh | 9 |
2 files changed, 11 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 0a3cabfd..5ec7556a 100644 --- a/README.markdown +++ b/README.markdown @@ -200,6 +200,8 @@ in `sh/shrc.d` to be loaded by any POSIX interactive shell. Those include: preserved; I hate having `root`-owned files in my home directory. * `tmux()` changes the default command for `tmux(1)` to `attach-session -d` if a session exists, or creates a new session if one doesn't. +* `tree()` colorizes GNU `tree(1)` output if possible (without having + `LS_COLORS` set). * `ud()` changes into an indexed ancestor of a directory. * `vim()` defines three functions to always use `vim(1)` as my `ex(1)`, `vi(1)` and `view(1)` implementation if it's available. diff --git a/sh/shrc.d/tree.sh b/sh/shrc.d/tree.sh new file mode 100644 index 00000000..5feb8ca3 --- /dev/null +++ b/sh/shrc.d/tree.sh @@ -0,0 +1,9 @@ +# I don't like the LS_COLORS environment variable, but GNU tree(1) doesn't +# 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 ] && + set -- -C "$@" + command "$@" +} |