commit d7bd99706263b7dc93fdb92cfebafda805850586
parent 7ebaa28eeefcccf83384f979724cc118a8e284b3
Author: spacehobo <spacehobo@web>
Date: Thu, 14 May 2026 20:18:22 +0200
Sharing my cool low-intensity high-information bash prompt
Diffstat:
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/spacehobo.mdwn b/spacehobo.mdwn
@@ -0,0 +1,28 @@
+# Just a Rum-Soaked Space Hobo with a Heart full of Love
+
+Hey, check out my neat `bash` prompt:
+
+ GIT_PS1_SHOWCOLORHINTS='y'
+ GIT_PS1_SHOWDIRTYSTATE='y'
+ GIT_PS1_SHOWSTASHSTATE='y'
+ GIT_PS1_SHOWUNTRACKEDFILES='y'
+ GIT_PS1_DESCRIBE_STYLE='contains'
+ GIT_PS1_SHOWUPSTREAM='auto'
+
+ _noop[0]='array accesses turn 0/nonzero into defined/undef!'
+ PS1='\[\e[$(($?==0?1:5));$(($?==0?0:91))m\]\$\[\e[0m\] ' # $?-coloured $
+ PS1='$(__git_ps1 "\[\e[1;33m\]{%s\[\e[1;33m\]}")'$PS1 # Gold git
+ PS1='\[\e[1;34m\]\w'$PS1 # Blue CWD
+ PS1='\[\e[1;33m\]:'$PS1 # Gold colon
+ PS1='\[\e[1;32m\]\h'$PS1 # Green hostname
+ PS1='\[\e[1;33m\]@'$PS1 # Gold at-sign
+ PS1='\[\e[1;35m\]\u'$PS1 # Purple username
+ PS1='\[\e[1;36m\]${debian_chroot:+($debian_chroot)}'$PS1 # Cyan chroot
+ PS1='${_noop[$((\j==0))]:+\[\e[1;33m\][\j]}'$PS1 # gold nonzero jobs
+ PS1='${_noop[$(($?==0))]:+\[\e[1;91m\]($?)}'$PS1 # Red nonzero $?
+
+The prompt environment is fairly limited. It can do parameter expansion, reference expansion, arithmetic expansion, and a couple other neat tricks. You can shell out, but if you do that overwrites the variable that contains the exit code of the last program you ran (`$?`). Tools such as the `__git_ps1` hacks do their best to only use features of bash that work internally to bash itself.
+
+This prompt uses the `_noop` array (with only `${_noop[0]}` defined) to turn arithmetic expressions into defined/undefined responses. This lets us use some of the brace-expansion features to specify alternate output, so we can display the error code or number of jobs in the background *only* if they're non-zero, and we can style them with a high degree of freedom.
+
+I just think it's neat!