git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eran Tromer <git2eran@tromer.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Bash snippet to show branch and patch in bash prompt
Date: Mon, 30 Oct 2006 17:03:05 +0200	[thread overview]
Message-ID: <45461429.4020108@tromer.org> (raw)
In-Reply-To: <20061030105926.14328.55180.stgit@lathund.dewire.com>

On 2006-10-30 12:59, Robin Rosenberg wrote:
> From: Robin Rosenberg <robin.rosenberg@dewire.com>

> +    function stgtag
> +    {
> +	git_dir=$(git-rev-parse --git-dir 2> /dev/null)
> +	ref=$(git-symbolic-ref HEAD 2> /dev/null)

Abort early if we're not in a git repo:
	git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return
	ref=$(git-symbolic-ref HEAD 2> /dev/null) || return


> +	br=${ref/refs\/heads\//}

You want to strip a prefix only, so this is safer:
	br=${ref#refs/heads/}


> +	top=$(cat $git_dir/patches/$br/current 2>/dev/null)

All variables should be declared local to avoid polluting the bash
variable namespace. Likewise, the function name deserves a couple of
underscores.


> +	if [[ -n "$br$top" ]];then
> +	    echo "[$top@$br]"

It seems better to put the StGIT top after the tag, so that stg push/pop
shifts less of the prompt, making it easier to see the change visually.


Corresponding modified version:

-------------------------------------------
if [ "$PS1" ]; then
    function __prompt_git()
    {
        local git_dir ref br top;
	git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return
	ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
	br=${ref#refs/heads/}
	top=$(cat $git_dir/patches/$br/current 2>/dev/null) \
		&& top="#$top"
	echo "[$br$top]"
    }
    PS1='\u@\h$(__prompt_git)\w\$ '
fi
-------------------------------------------

Conditionally prepending the "#" to $top can be done more concisely via
${top:+#$top} but I used the more readable version.


  reply	other threads:[~2006-10-30 15:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-29 23:37 [StGIT PATCH] Bash snippet to show branch and patch in bash prompt Robin Rosenberg
2006-10-30  9:57 ` Eran Tromer
2006-10-30 10:24   ` Catalin Marinas
2006-10-30 10:32   ` Robin Rosenberg
2006-10-30 10:59   ` [PATCH] " Robin Rosenberg
2006-10-30 15:03     ` Eran Tromer [this message]
2006-11-02 11:24       ` Catalin Marinas
  -- strict thread matches above, loose matches on Subject: below --
2006-10-30 10:42 Robin Rosenberg
2006-10-30 10:46 ` Catalin Marinas
2006-10-30 10:57 ` Robin Rosenberg
2006-10-30 10:59 ` Robin Rosenberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45461429.4020108@tromer.org \
    --to=git2eran@tromer.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).