git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bash snippet to show branch and patch in bash prompt
@ 2006-10-30 10:42 Robin Rosenberg
  2006-10-30 10:46 ` Catalin Marinas
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Robin Rosenberg @ 2006-10-30 10:42 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Eran Tromer, git

From: Robin Rosenberg <robin.rosenberg@dewire.com>

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---

 contrib/stgbashprompt.sh |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/contrib/stgbashprompt.sh b/contrib/stgbashprompt.sh
new file mode 100755
index 0000000..792da53
--- /dev/null
+++ b/contrib/stgbashprompt.sh
@@ -0,0 +1,16 @@
+# 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\$ '
+

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30 10:42 [PATCH] Bash snippet to show branch and patch in bash prompt Robin Rosenberg
@ 2006-10-30 10:46 ` Catalin Marinas
  2006-10-30 10:57 ` Robin Rosenberg
  2006-10-30 10:59 ` Robin Rosenberg
  2 siblings, 0 replies; 7+ messages in thread
From: Catalin Marinas @ 2006-10-30 10:46 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: Eran Tromer, git

Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> From: Robin Rosenberg <robin.rosenberg@dewire.com>
>
> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
> ---
>
>  contrib/stgbashprompt.sh |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/contrib/stgbashprompt.sh b/contrib/stgbashprompt.sh
> new file mode 100755
> index 0000000..792da53
> --- /dev/null
> +++ b/contrib/stgbashprompt.sh
> @@ -0,0 +1,16 @@
> +# 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

Isn't this the same patch? "stg refresh" :-)?

-- 
Catalin

P.S. could you please send them to my catalin.marinas@gmail.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30 10:42 [PATCH] Bash snippet to show branch and patch in bash prompt Robin Rosenberg
  2006-10-30 10:46 ` Catalin Marinas
@ 2006-10-30 10:57 ` Robin Rosenberg
  2006-10-30 10:59 ` Robin Rosenberg
  2 siblings, 0 replies; 7+ messages in thread
From: Robin Rosenberg @ 2006-10-30 10:57 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Eran Tromer, git

måndag 30 oktober 2006 11:42 skrev Robin Rosenberg:
> From: Robin Rosenberg <robin.rosenberg@dewire.com>
>
> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>

This was a "reply" using stgit, but the reference missed the ange brackets. 

Anyway thanks for the feedback on the prompt.

-- robin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30 10:42 [PATCH] Bash snippet to show branch and patch in bash prompt Robin Rosenberg
  2006-10-30 10:46 ` Catalin Marinas
  2006-10-30 10:57 ` Robin Rosenberg
@ 2006-10-30 10:59 ` Robin Rosenberg
  2 siblings, 0 replies; 7+ messages in thread
From: Robin Rosenberg @ 2006-10-30 10:59 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Eran Tromer, git

Oops, didn't refresh before sending.. 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30  9:57 [StGIT PATCH] " Eran Tromer
@ 2006-10-30 10:59 ` Robin Rosenberg
  2006-10-30 15:03   ` Eran Tromer
  0 siblings, 1 reply; 7+ messages in thread
From: Robin Rosenberg @ 2006-10-30 10:59 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: Eran Tromer, git

From: Robin Rosenberg <robin.rosenberg@dewire.com>

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---

 contrib/stgbashprompt.sh |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/contrib/stgbashprompt.sh b/contrib/stgbashprompt.sh
new file mode 100755
index 0000000..a79561e
--- /dev/null
+++ b/contrib/stgbashprompt.sh
@@ -0,0 +1,18 @@
+# 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
+    {
+	git_dir=$(git-rev-parse --git-dir 2> /dev/null)
+	ref=$(git-symbolic-ref HEAD 2> /dev/null)
+	br=${ref/refs\/heads\//}
+	top=$(cat $git_dir/patches/$br/current 2>/dev/null)
+	if [[ -n "$br$top" ]];then
+	    echo "[$top@$br]"
+	    return
+	fi
+    }
+    PS1='\u@\h$(stgtag)\w\$ '
+

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30 10:59 ` [PATCH] " Robin Rosenberg
@ 2006-10-30 15:03   ` Eran Tromer
  2006-11-02 11:24     ` Catalin Marinas
  0 siblings, 1 reply; 7+ messages in thread
From: Eran Tromer @ 2006-10-30 15:03 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Bash snippet to show branch and patch in bash prompt
  2006-10-30 15:03   ` Eran Tromer
@ 2006-11-02 11:24     ` Catalin Marinas
  0 siblings, 0 replies; 7+ messages in thread
From: Catalin Marinas @ 2006-11-02 11:24 UTC (permalink / raw)
  To: Eran Tromer; +Cc: Robin Rosenberg, git

Eran Tromer <git2eran@tromer.org> wrote:
> Corresponding modified version:

Thanks for your comments. I included them in the patch.

-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-11-02 11:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-30 10:42 [PATCH] Bash snippet to show branch and patch in bash prompt Robin Rosenberg
2006-10-30 10:46 ` Catalin Marinas
2006-10-30 10:57 ` Robin Rosenberg
2006-10-30 10:59 ` Robin Rosenberg
  -- strict thread matches above, loose matches on Subject: below --
2006-10-30  9:57 [StGIT PATCH] " Eran Tromer
2006-10-30 10:59 ` [PATCH] " Robin Rosenberg
2006-10-30 15:03   ` Eran Tromer
2006-11-02 11:24     ` Catalin Marinas

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).