Created
April 8, 2011 15:01
-
-
Save rociiu/910011 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 set_window_and_tab_title | |
{ | |
local title="$1" | |
if [[ -z "$title" ]]; then | |
title="root" | |
fi | |
local tmpdir=~/Library/Caches/${FUNCNAME}_temp | |
local cmdfile="$tmpdir/$title" | |
# Set window title | |
echo -n -e "\033]0;${title}\a" | |
# Set tab title | |
if [[ -n ${CURRENT_TAB_TITLE_PID:+1} ]]; then | |
kill $CURRENT_TAB_TITLE_PID | |
fi | |
mkdir -p $tmpdir | |
ln /bin/sleep "$cmdfile" | |
"$cmdfile" 10 & | |
CURRENT_TAB_TITLE_PID=$(jobs -x echo %+) | |
disown %+ | |
kill -STOP $CURRENT_TAB_TITLE_PID | |
command rm -f "$cmdfile" | |
} | |
PROMPT_COMMAND='set_window_and_tab_title "${PWD##*/}"' | |
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 | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/" | |
} | |
# set prompt: ``username@hostname:/directory $ '' | |
PS1="\u@\h \W \$(parse_git_branch) " | |
case `id -u` in | |
0) PS1="${PS1}# ";; | |
*) PS1="${PS1}$ ";; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment