From 9820de29e08156b39b0f3afcc59c0e8f2f544b2b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 26 Aug 2016 13:48:38 +1200 Subject: Add tree() --- README.markdown | 2 ++ sh/shrc.d/tree.sh | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 sh/shrc.d/tree.sh 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 "$@" +} -- cgit v1.2.3