git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [StGIT PATCH] Bash snippet to show branch and patch in bash prompt

From
CMCatalin Marinas <catalin.marinas@arm.com>
Date
Oct 30, 2006, 10:24 UTC
Message-ID
<tnxlkmy2j9p.fsf@arm.com>
In-Reply-To
<4545CC6F.90001@tromer.org>
Eran Tromer <git2eran@tromer.org> wrote:
Show 20 quoted lines
> On 2006-10-30 01:37, Robin Rosenberg wrote:
>> +# 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\$ '
>> +
>> +fi
>
> That's an annoying 430ms delay at every prompt, on my box. Does StGIT do
> something expensive on every invocation?

Well, there are some forks. For every "stg" command, "git-symbolic-ref HEAD" and "git-rev-parse --git-dir" are invoked to get the name of the main branch and the .git directory. There is also the delay of invoking python and loading the command modules in main.py (maybe I should modify this to import the modules on demand, based on what command was given).

Since the repository format is stable, you could use something like this (it should be faster):

git_dir=$(git-rev-parse --git-dir 2> /dev/null) ref=$(git-symbolic-ref HEAD 2> /dev/null) br=${ref##*/} top=$(cat $git_dir/patches/$br/current)

Previous: Eran TromerNext: Robin Rosenberg
Message 3 of 7 in “Bash snippet to show branch and patch in bash prompt”
  1. Bash snippet to show branch and patch in bash promptRobin Rosenberg, Oct 29, 2006
  2. Eran TromerOct 30, 2006
  3. Catalin MarinasOct 30, 2006
  4. Robin RosenbergOct 30, 2006
  5. Bash snippet to show branch and patch in bash promptRobin Rosenberg, Oct 30, 2006
  6. Eran TromerOct 30, 2006
  7. Catalin MarinasNov 2, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.