Skip to content

Instantly share code, notes, and snippets.

@carmat
Last active August 29, 2015 13:57
Show Gist options
  • Save carmat/9476158 to your computer and use it in GitHub Desktop.
Save carmat/9476158 to your computer and use it in GitHub Desktop.
## Set title on each tab
## ====================================
## Gets the repository directory
## name and current branch name
##
## If the current directory is not a
## git repo, a tabname can be specified
## ====================================
## @usage: tabname (git)
## @usage: tabname name (non-git)
function tabname {
if [ "$1" ]; then
printf "\e]1;$1\a"
elif [ -d .git ]; then
repo=$(basename `git rev-parse --show-toplevel`)
branch="$(git symbolic-ref --short -q HEAD)" ||
branch="(unnamed branch)" # detached HEAD
printf "\e]1;("$repo") "$branch"\a"
else
printf "\e]1;$1\a"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment