dot/shell-rc: Calculate the hostname qualifiers once in advance.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 9 May 2020 23:45:20 +0000 (00:45 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 9 May 2020 23:45:20 +0000 (00:45 +0100)
The `qualifiers' here are things like the chroot or cross-environment
name.

dot/shell-rc

index 51abd6e..2478edb 100644 (file)
@@ -62,11 +62,12 @@ __mdw_runhook () {
 ### Prompt machinery.
 
 __mdw_host=$(hostname)
+__mdw_hqual=
+__mdw_hqual=$__mdw_hqual${SCHROOT_CHROOT_NAME+/$SCHROOT_CHROOT_NAME}
+__mdw_hqual=$__mdw_hqual${CROSS_BUILDENV+/$CROSS_BUILDENV}
 __mdw_set_prompt_hacks () { host=$__mdw_host; dir=""; }
 
 __mdw_set_prompt_pieces () {
-  local hqual
-  hqual=""
 
   ## Fancy highlighting in some terminals.
   local bold unbold nl gitcolour rccolour uncolour
@@ -108,11 +109,9 @@ __mdw_set_prompt_pieces () {
 
   ## If this is an schroot environment or some other interesting augmented
   ## environment then point this out.
-  hqual="$hqual${SCHROOT_CHROOT_NAME+/$SCHROOT_CHROOT_NAME}"
-  hqual="$hqual${CROSS_BUILDENV+/$CROSS_BUILDENV}"
 
   ## Put together the main pieces.
-  __mdw_prompt_left="$nl$bold$left$sec_l$u$host$hqual$sec_r$dir"
+  __mdw_prompt_left="$nl$bold$left$sec_l$u$host$__mdw_hqual$sec_r$dir"
   __mdw_prompt_git_left="$unbold$gitcolour"
   __mdw_prompt_git_right="$uncolour$bold"
   __mdw_prompt_rc_left="$unbold$rccolour"