Skip to content

Instantly share code, notes, and snippets.

@jphenow
Forked from ehlertij/.bash_profile
Created December 19, 2012 16:42
Show Gist options
  • Save jphenow/4338135 to your computer and use it in GitHub Desktop.
Save jphenow/4338135 to your computer and use it in GitHub Desktop.
function title {
#[ "$DISABLE_AUTO_TITLE" != "true" ] || return
if [[ "$TERM" == screen* ]]; then
print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" #set window name
print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal)
fi
}
# Set terminal window name to current git repo (and branch) or current directory
git-repo() {
git remote -v | grep '(fetch)' | awk '{ print $2 }' | awk -F/ '{print $NF }' | sed "s,\.git,,"
}
git-branch() {
git branch | grep \* | cut -c 3-
}
git-term() {
title "`git-repo`: `git-branch`"
}
mpwd () {
pwd | sed "s,$HOME,~,"
}
term_tab_name() {
git remote >/dev/null 2>&1
if (($?)); then
title "`mpwd`"
else
git-term
fi
}
# Use a bash hook rather than aliasing 'cd'
#export PROMPT_COMMAND="term-tab-name; $PROMPT_COMMAND"
precmd() {
term_tab_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment