Skip to content

Instantly share code, notes, and snippets.

@Dynnammo
Created September 24, 2022 15:55
Show Gist options
  • Save Dynnammo/2cd28710f89d7576199b2237e010f8fe to your computer and use it in GitHub Desktop.
Save Dynnammo/2cd28710f89d7576199b2237e010f8fe to your computer and use it in GitHub Desktop.
[...]
# PS1 setup
source ps1
PS1='$(set_prompt)'
#!/bin/bash
set_prompt()
{
local last_cmd=$?
local txtreset='$(tput sgr0)'
local txtblack='$(tput setaf 0)'
local txtred='$(tput setaf 1)'
local txtgreen='$(tput setaf 2)'
local txtyellow='$(tput setaf 3)'
local txtblue='$(tput setaf 4)'
local txtpurple='$(tput setaf 5)'
local txtcyan='$(tput setaf 6)'
local txtwhite='$(tput setaf 7)'
# unicode "✗"
local fancyx='\342\234\227'
# unicode "✓"
local checkmark='\342\234\223'
# Line 2: current path
PS1="\[$txtgreen\]\w "
# User color: red for root, yellow for others
if [[ $EUID == 0 ]]; then
PS1+="\[$txtred\]"
else
PS1+="\[$txtyellow\]"
fi
# Line 3: user@host
PS1+="\u\[$txtwhite\]@\h "
# Line 4: a red "✗" or a green "✓" and the error number
if [[ $last_cmd == 0 ]]; then
PS1+="\[$txtgreen\]$checkmark \[$txtwhite\](0)"
else
PS1+="\[$txtred\]$fancyx \[$txtwhite\]($last_cmd)"
fi
# Line 4: green git branch
PS1+="\[$txtgreen\]$(__git_ps1 ' (%s)')\[$txtwhite\]"
# Line 4: good old prompt, $ for user, # for root
PS1+=" \\$ "
}
@Dynnammo
Copy link
Author

Inspired from this thread on SO : https://stackoverflow.com/a/30963255/13879579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment