Skip to content

Instantly share code, notes, and snippets.

@spleenteo
Created April 17, 2012 08:48
Show Gist options
  • Save spleenteo/2404693 to your computer and use it in GitHub Desktop.
Save spleenteo/2404693 to your computer and use it in GitHub Desktop.
bash function to build a path like this: ../jobs/mywebsite/www(git::master)>
# I like to have a PATH in my shell
# to show the last 3 dirs of the whole PATH and the git (or hg) repo at the end (if exists)
# here an example:
#
# ../jobs/mywebsite/www(git::master)>
#
# Put these few lines in your .bash_profile:
hg_ps1() {
hg prompt " [{rev}{;{rev|merge}}{ on {branch|quiet}}{ {status|modified}}]" 2> /dev/null
}
git_ps1() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/'
}
short_path() {
OFS=$IFS
IFS=/
splitted=($PWD)
IFS=$OFS
if [ ${#splitted[@]} -gt 4 ]; then
pos=$(( ${#splitted[@]} - 3 ))
IFS=/
echo "../${splitted[*]:$pos}"
IFS=$OFS
else
echo $PWD
fi
}
export PS1='$(short_path)\[\033[34m\]$(git_ps1)$(hg_ps1)\[\033[00m\]>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment