Skip to content

Instantly share code, notes, and snippets.

@ehlertij
Last active October 13, 2015 16:48
Show Gist options
  • Save ehlertij/4226405 to your computer and use it in GitHub Desktop.
Save ehlertij/4226405 to your computer and use it in GitHub Desktop.
Set OSX terminal window to git repo name or current directory
# Set terminal window name to current git repo (and branch) or current directory
git-repo() {
git remote -v | grep '(fetch)' | grep -o "\/[a-z,A-Z,\_,\-]*\." | tail -1 | cut -c 2- | grep -o ^[a-z,A-Z,\_,\-]*
}
git-branch() {
git branch | grep \* | cut -c 3-
}
git-term() {
echo -n -e "\033]0;`git-repo`\007"
}
term-tab-name() {
git remote >/dev/null 2>&1
if (($?)); then
echo -n -e "\033]0;`pwd | grep -o -e [\-,\_,a-z,A-Z]*$`\007"
else
git-term
fi
}
# Use a bash hook rather than aliasing 'cd'
export PROMPT_COMMAND="term-tab-name; $PROMPT_COMMAND"
@jphenow
Copy link

jphenow commented Dec 19, 2012

Could probably just awk '{ print $2 }' on the second, long grep in git-repo

@jphenow
Copy link

jphenow commented Dec 19, 2012

I'm redoing part of this because for whatever reason Its hating on me. so far I'm at:

git remote -v | grep '(fetch)' | awk '{ print $2 }' | awk -F/ '{print $NF }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment