Skip to content

Instantly share code, notes, and snippets.

@brianm
Last active May 16, 2023 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianm/7684710 to your computer and use it in GitHub Desktop.
Save brianm/7684710 to your computer and use it in GitHub Desktop.
Encode $0 into color of hostname in PS1
# assumes 256 color support, do your normal case thing, etc
local green="\[\033[38;5;156m\]"
local blue="\[\033[38;5;153m\]"
local red="\[\033[38;5;009m\]"
local reset="\[\033[00m\]"
local git_stuff='$(__git_ps1 "\[\033[31m\]<\[\033[01m\]%s\[\033[22m\]>\[\033[00m\]")'
local status_color="\$(if [ \$? = 0 ]; then echo \"${green}\"; else echo \"${red}\"; fi )"
PS1="${status_color}\h${reset}:${blue}\w${git_stuff}${reset}$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment