Skip to content

Instantly share code, notes, and snippets.

@mohokh67
Last active February 12, 2019 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohokh67/87b3ec8368ea49497048bdd7b9fc1051 to your computer and use it in GitHub Desktop.
Save mohokh67/87b3ec8368ea49497048bdd7b9fc1051 to your computer and use it in GitHub Desktop.
Customise terminal prompt

Customise terminal prompt in ubuntu

This one will only prompt the current directory

export PS1='\W > '

Git branch

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

smily face

green smily face if previous command was sucessful and red if something went wrong:

export smily_face='$(if [[ $? == 0 ]]; then echo "\[\e[32m\]:)"; else echo "\[\e[31m\]:("; fi)'

use all above in this way:

export PS1="$smily_face \[\033[33m\]\[\e[1m\]\W\[\e[0m\]\[\e[31m\]\$(parse_git_branch)\[\e[0m\] > "

Better version:

export PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment