My Mercurial Prompt

This has come up a few times and so I thought I would post this. I use Steve Losh’s hg-prompt extension and I have it configured so that it displays the revision and the patch number if I am using Mercurial queues: Like so:

My Mercurial Prompt

To get this paste the following into your .bashrc file:

############################################################################# # Set up Prompt ############################################################################# noColor='\[\033[0m\]' blackColor='\[\033[0;30m\]' redColor='\[\033[0;31m\]' greenColor='\[\033[0;32m\]' yellowColor='\[\033[0;33m\]' blueColor='\[\033[0;34m\]' purpleColor='\[\033[0;35m\]' cyanColor='\[\033[0;36m\]' greyColor='\[\033[0;37m\]' boldGrayColor='\[\033[1;30m\]' boldRedColor='\[\033[1;31m\]' boldGreenColor='\[\033[1;32m\]' boldYellowColor='\[\033[1;33m\]' boldBlueColor='\[\033[1;34m\]' boldPurpleColor='\[\033[1;35m\]' boldCyanColor='\[\033[1;36m\]' boldWhiteColor='\[\033[1;37m\]' # Change the prompt to be user@host:path$ with some colors # simple version would be say # export PS1="${noColor}[${yelloColor}\h${noColor}:${greenColor}\w${noColor}] \$ " # Function that returns the last n path components of the specified path after # replacing $HOME with ~. Call like: # pathComponents path n nameColor seperatorColor function pathComponents { echo `python -c\ "import string,re; pth=re.sub('^$HOME','~',r\"$1\",1); n = string.atoi(r\"$2\"); nc=r\"$3\"; sc=r\"$4\";\ print nc + string.join(pth.split('/')[-n:], sc + '/' + nc);"` } # this is my mercurial prompt. It relies on the hg-prompt extension : http://stevelosh.com/projects/hg-prompt/ # its basically: basename rev(tip) on branch at bookmark patchnum#/patchcount# hg_ps1() { # hg prompt "{ on ${greenColor}{branch}${noColor}}{ at {bookmark}}" 2> /dev/null hg prompt "${cyanColor}{root|basename}${noColor}\ { ${blueColor}{rev}${greyColor}}\ {(${cyanColor}{tip}${greyColor})${noColor}}\ { ${greyColor}on:${cyanColor}{branch|quiet}${noColor}}\ { ${greyColor}at:${noColor}{bookmark}${noColor}}\ { ${greyColor}mq:${purpleColor}{patch|applied|quiet}${noColor}}{/${purpleColor}{patch|count|quiet}${noColor}} " 2> /dev/null } #export PS1='\u at \h in \w$(hg_ps1)\n$ ' function myPromptCommand { local newPWD=`pathComponents "\${PWD}" 4 \${blueColor} \${redColor}` # the trimed colored path echo -ne "\033]0;${HOSTNAME%%.*}:${PWD/$HOME/~}\007" # this sets the title export PS1="${noColor}[${greenColor}\h${noColor}:${newPWD}${noColor}] $(hg_ps1)⌘ " } PROMPT_COMMAND=myPromptCommand # Change the title of each window, and PS1 to reflect where we are

Leave a Comment