From febd0c25036dcc102dc95b95bec453cb91c0d697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C5=82azie=C5=84ski?= Date: Sat, 15 Oct 2016 22:02:29 +0200 Subject: [PATCH] Test if dircolors or whoami commands exists before calling them --- .zshrc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.zshrc b/.zshrc index 4dae5b6..33c5f96 100644 --- a/.zshrc +++ b/.zshrc @@ -59,6 +59,10 @@ find_up () { done } +command-exists () { + return [[ -n $commands[$1] ]]; +} + #---------------------------------- Tab completion ---------------------------- # Force a reload of completion system if nothing matched; this fixes installing @@ -215,7 +219,10 @@ prompt_root() { # Different username prompt_user() { - local user=$(whoami) + local user=$USER + if command-exists whoami && [[ -z $user ]] then + user=$(whoami) + fi if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then print -n $user fi @@ -334,7 +341,9 @@ case $(uname -s) in LSOPTS="${LSOPTS} -G" ;; Linux) - eval "$(dircolors -b)" + if command-exists dircolors; then + eval "$(dircolors -b)" + fi LSOPTS="$LSOPTS --color=auto" LLOPTS="$LLOPTS --color=always" # so | less is colored