# HG changeset patch # User IBBoard # Date 1692818788 -3600 # Node ID 8bf9fc90ce51d237f53080a16e68fd5fc46f33de # Parent 1c3ec0b529c45522a55ecd89bdda6cbaa5ae8994 Streamline HG Prompt with `inout` command This avoids a second Mercurial invocation, which takes a couple of seconds on a Raspberry Pi. Also exported PS1 variants to make it easier to enable/disable the VCS checks but keep the rest of the formatting diff -r 1c3ec0b529c4 -r 8bf9fc90ce51 bashrc --- a/bashrc Tue May 30 18:49:56 2023 +0100 +++ b/bashrc Wed Aug 23 20:26:28 2023 +0100 @@ -54,13 +54,7 @@ VCS_EXTRA=$(__git_ps1 "%s") if [[ "x$VCS_EXTRA" == "x" ]]; then - VCS_EXTRA=$(hg prompt "{branch}{ {status|modified}}" 2>/dev/null) - HG_EXTRA=$(hg prompt "{-{incoming|count}}{+{outgoing|count}}" 2>/dev/null) - if [[ "x$HG_EXTRA" != "x" ]]; then - VCS_EXTRA="${VCS_EXTRA} u${HG_EXTRA}" - elif [[ "x$VCS_EXTRA" != "x" ]]; then - VCS_EXTRA="${VCS_EXTRA} u=" - fi + VCS_EXTRA=$(hg prompt "{branch}{ {status|modified}}{ u{inout}}" 2>/dev/null) fi if [[ "x$VCS_EXTRA" != "x" ]]; then echo -n " ($VCS_EXTRA)" @@ -71,7 +65,9 @@ PROMPT_DIRTRIM=2 # Bold the command prompt and standardise on SUSE format # With colour! -export PS1='\[\033[01;38;5;34m\]\u\[\033[01;38;5;28m\]@\[\033[01;38;5;34m\]\h\[\033[39m\]:\[\033[01;38;5;26m\]\w$(test "$PWD" != / && echo -n /)\[\033[39m\]\[\033[01;38;5;247m\]$(vcs_status)\[\033[39m\]>\[\033[00m\] ' +export PS1_VCS='\[\033[01;38;5;34m\]\u\[\033[01;38;5;28m\]@\[\033[01;38;5;34m\]\h\[\033[39m\]:\[\033[01;38;5;26m\]\w$(test "$PWD" != / && echo -n /)\[\033[39m\]\[\033[01;38;5;247m\]$(vcs_status)\[\033[39m\]>\[\033[00m\] ' +export PS1_NOVCS='\[\033[01;38;5;34m\]\u\[\033[01;38;5;28m\]@\[\033[01;38;5;34m\]\h\[\033[39m\]:\[\033[01;38;5;26m\]\w$(test "$PWD" != / && echo -n /)\[\033[39m\]\[\033[01;38;5;247m\]\[\033[39m\]>\[\033[00m\] ' +export PS1=$PS1_VCS # Fix "less" highlighting export LESS_TERMCAP_so=$'\033[30;48;5;247m' diff -r 1c3ec0b529c4 -r 8bf9fc90ce51 prompt.py --- a/prompt.py Tue May 30 18:49:56 2023 +0100 +++ b/prompt.py Wed Aug 23 20:26:28 2023 +0100 @@ -270,6 +270,20 @@ return _with_groups(g, out) if out else b'' + def _inout(m): + g = m.groups() + class FakeMatch: + def __init__(self, groups): + self.__groups = groups + def groups(self): + return self.__groups + incoming = _remote(b'incoming')(FakeMatch([b"-{", b"|count", b"}"])) + outgoing = _remote(b'outgoing')(FakeMatch([b"+{", b"|count", b"}"])) + if not incoming and not outgoing: + return _with_groups(g, b'=') + else: + return _with_groups(g, incoming + outgoing) + def _remote(kind): def _r(m): g = m.groups() @@ -435,6 +449,7 @@ b'incoming(\|count)?': _remote(b'incoming'), b'outgoing(\|count)?': _remote(b'outgoing'), + b'inout': _inout, } if opts.get("cache_incoming"):