aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-26 13:48:38 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-26 13:48:38 +1200
commit9820de29e08156b39b0f3afcc59c0e8f2f544b2b (patch)
tree1ae3ef2a38a9a1d7fdc3496d2cc21ed22debdf1f
parentAdd subsection for dotfiles(7df) (diff)
downloaddotfiles-9820de29e08156b39b0f3afcc59c0e8f2f544b2b.tar.gz
dotfiles-9820de29e08156b39b0f3afcc59c0e8f2f544b2b.zip
Add tree()
-rw-r--r--README.markdown2
-rw-r--r--sh/shrc.d/tree.sh9
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 "$@"
+}