Skip to content

Instantly share code, notes, and snippets.

@jcn
Created January 16, 2011 08:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcn/781651 to your computer and use it in GitHub Desktop.
Save jcn/781651 to your computer and use it in GitHub Desktop.
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
function breadcrumb()
{
echo $1 | sed "s|^$HOME|~|" | awk -v n=$2 '{
# Split the path into components
count = split($0, components, "/")
# If there are less than n components, just print the whole path
if (count <= n) {
print $0
} else {
# print the last n components
for (i = count - n + 1; i < count; i++) {
printf "%s/", components[i]
}
printf "%s", components[count]
}
}'
}
PS1='[\h:$(breadcrumb "$PWD" 3)] $(parse_git_branch)\u\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment