-
-
Save lodestone/981501 to your computer and use it in GitHub Desktop.
A bash prompt with useful information, including popping up a growl notification when commands are done.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo '✏ ' | |
} | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | grep \* | awk '{print $2}' | |
} | |
function parse_hg_branch { | |
hg branch 2>/dev/null | |
} | |
function latest_command { | |
history | tail -n 1 | sed 's/[0-9 ]*\(.*\)/\1/' | |
} | |
function growl_latest_command { | |
priority="Normal" | |
if (( $1 != 0 )); then | |
priority="Emergency" | |
fi | |
latest_command | growlnotify -p $priority -n "Command Prompt $priority" `pwd` 1>/dev/null 2>&1 | |
} | |
function prompt_command_function | |
{ | |
last_result=$? | |
growl_latest_command $last_result | |
last_result="\[\e[33m\]$last_result\[\e[0m\]" | |
titlebar_last_command="\[\e]2;$(latest_command)\a\]" | |
rvm_prompt="\[\e[33m\]$(rvm-prompt s i v p g)\[\e[0m\]" | |
git_branch=$(parse_git_branch) | |
hg_branch=$(parse_hg_branch) | |
git_dirty= #$(parse_git_dirty) | |
hg_dirty= | |
git_dirty=${git_dirty:+" \[\e[31m\]$git_dirty\[\e[0m\]"} | |
git_branch=${git_branch:+" (\[\e[35m\]${git_branch}\[\e[0m\]${git_dirty})"} | |
hg_branch=${hg_branch:+" (\[\e[36m\]${hg_branch}\[\e[0m\]${hg_dirty})"} | |
PS1="$titlebar_last_command$last_result \h:\[\e[32m\]\w\[\e[0m\] $rvm_prompt \u$git_branch$hg_branch\$ " | |
} | |
export PROMPT_COMMAND=prompt_command_function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment