Skip to content

Instantly share code, notes, and snippets.

@nathan-v
Created March 14, 2020 00:54
Show Gist options
  • Save nathan-v/dc57a9beb79b6d5bee7e3ddc1a48b5bc to your computer and use it in GitHub Desktop.
Save nathan-v/dc57a9beb79b6d5bee7e3ddc1a48b5bc to your computer and use it in GitHub Desktop.
Handy little title setter that makes sure that the title always reflects where you are and what is going on it git in that directory
# Title setting function
function git_title {
# See if we're in a git path
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) = true ]]; then
# Set the title to <git parent folder name>:<current branch> like "mycoollib:master"
echo -ne "\033]0;$(basename `git rev-parse --show-toplevel`):$(git rev-parse --abbrev-ref HEAD)\007"
else
# Set the title to the present working directory
echo -ne "\033]0;$PWD\007"
fi
}
PROMPT_COMMAND=git_title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment