Skip to content

Instantly share code, notes, and snippets.

@jzimdars
Created August 4, 2011 19:31
Show Gist options
  • Save jzimdars/1126023 to your computer and use it in GitHub Desktop.
Save jzimdars/1126023 to your computer and use it in GitHub Desktop.
Set tab title and bash prompt
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))/"
}
export PS1="\[\033[01;32m\]\h\[\033[00m\]: \[\033[01;36m\]\w\[\033[00m\] \[\033[01;37m\]\$(parse_git_branch)\[\033[00m\] "
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