1

I'm trying to have a prompt that looks like this:

$ some-folder (patch-name):

I was able to get that to work when I did the following:

hg_ps1() {
    hg prompt " ({patch})" 2> /dev/null
}

export PS1='$ \W$(hg_ps1): '

However, this is what it looks like when I don't have any patch applied:

$ some-folder ():

If there is no patch applied, I would prefer for it to just look like this:

$ some-folder: 

Is there a way I can do this?

2 Answers 2

3

You can make the output of hg_ps1 be conditional on the results of the hg command e.g.

hg_ps1()
{
  typeset prmpt=$(hg prompt "{patch}" 2>/dev/null)
  [[ -n "$prmpt" ]] && echo " ($prmpt)"
}
0
1

You can use the following to show applied and unapplied patches:

hg prompt --angle-brackets "<patches|join( → )|pre_applied(${COLOR_BROWN})|post_applied(${COLOR_NC})|pre_unapplied(${COLOR_BLACK})|post_unapplied(${COLOR_NC})>"

Choose the colours you want, e.g. I use the following:

COLOR_BROWN=$'\e[0;33m'
COLOR_NC=$'\e[0m' # No Color
COLOR_BLACK=$'\e[0;30m'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .