From: Mark Wooding Date: Fri, 8 May 2020 22:43:31 +0000 (+0100) Subject: dot/shell-rc: Cache whether we're running as root. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/fde3353fbc08069652329af2bd3d4755da385451?ds=inline dot/shell-rc: Cache whether we're running as root. Rather than running `id' every time. What was I thinking? --- diff --git a/dot/shell-rc b/dot/shell-rc index ee9161d..9857a82 100644 --- a/dot/shell-rc +++ b/dot/shell-rc @@ -70,6 +70,11 @@ __mdw_set_prompt_hacks () { host=$__mdw_host; dir=""; } : ${USER-${LOGNAME-$(id -un)}} __mdw_user=$USER +case $(id -u) in + 0) __mdw_rootp=t ;; + *) __mdw_rootp=nil ;; +esac + __mdw_set_prompt_pieces () { ## Fancy highlighting in some terminals. @@ -82,12 +87,12 @@ __mdw_set_prompt_pieces () { ## highlight when I'm running as some other user. Highlight when this ## isn't the outermost shell on the terminal. local left right u tty - case $(id -u) in - 0) + case $__mdw_rootp in + t) left=$(echo « | iconv -f UTF-8 -t //translit) right=$(echo » | iconv -f UTF-8 -t //translit) ;; - *) + nil) case $USER in mdw | mwooding | nemo) u="" left="[" right="]" ;; *) u="$__mdw_user@" left="{" right="}" ;;