From fde3353fbc08069652329af2bd3d4755da385451 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 8 May 2020 23:43:31 +0100 Subject: [PATCH] dot/shell-rc: Cache whether we're running as root. Organization: Straylight/Edgeware From: Mark Wooding Rather than running `id' every time. What was I thinking? --- dot/shell-rc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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="}" ;; -- [mdw]