Re: [StGIT PATCH] Bash snippet to show branch and patch in bash prompt
- From
- Eran Tromer <git2eran@tromer.org>
- Date
- Oct 30, 2006, 09:57 UTC
- Message-ID
- <4545CC6F.90001@tromer.org>
- In-Reply-To
- <20061029233745.24899.1470.stgit@lathund.dewire.com>
On 2006-10-30 01:37, Robin Rosenberg wrote:
Show 16 quoted lines
> +# include this in your bashrc or copy to /etc/bash_completions.d
> +
> +if [ "$PS1" ]; then
> + # trap 'PS1="\u@\h [$(stg top)] \w]\$ "' DEBUG
> + function stgtag
> + {
> + br=$(stg branch 2>/dev/null)
> + top=$(stg top 2>/dev/null)
> + if [[ -n "$br$top" ]];then
> + echo "[$top@$br]"
> + return
> + fi
> + }
> + PS1='\u@\h$(stgtag)\w\$ '
> +
> +fiThat's an annoying 430ms delay at every prompt, on my box. Does StGIT do something expensive on every invocation?
Ben Clifford'd solution is pretty much instantaneous, and the following extends it to StGIT (in a less clean but much faster way):
----------------------------------------------
__prompt_githead() {
__PS_GIT="$(git-symbolic-ref HEAD 2>/dev/null)" || exit
__PS_GIT="$(basename $__PS_GIT)"
echo -n " $__PS_GIT"
__PS_GIT=$(cat "${GIT_DIR:-.git}/patches/$__PS_GIT/current" \
2>/dev/null) || exit
echo -n ":$__PS_GIT"
}
PS1='[\u@\h \W$(__prompt_githead)]\$ '
----------------------------------------------