Skip to content

Instantly share code, notes, and snippets.

@papaben
Created August 15, 2013 19:03
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 papaben/6243750 to your computer and use it in GitHub Desktop.
Save papaben/6243750 to your computer and use it in GitHub Desktop.
Bash PS1
# Red if last command failed
function __last_cmd_code_ps1() {
local red='\033[00;31m' # red
if [ $1 -ne 0 ]; then
echo -e "${red}*!!**${1}**!!*${red}"
return
fi
}
function prompt() {
local nc='\033[0m' # no color
local green='\033[00;32m'
local purple='\033[01;35m'
local cyan='\033[00;36m'
# User@hostname date time directory\nCommand Number $ - me, # - root
# __git_ps1 - show current git branch; http://blog.jasonmeridth.com/2010/05/22/git-ps1.html
local ps1=$(echo $cyan'{{'$green'\u@$SHORTNAME \D{%Y-%m-%d} \t '$cyan'\w'$purple'$(__git_ps1 " (%s)" 2>/dev/null)'$cyan'}}')
PS1=$(echo '$(__last_cmd_code_ps1 $?)'"$ps1""$nc"'\n[\!]\$ ');
}
prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment