]> git.madduck.net Git - etc/zsh.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

add git branch to prompt
authormartin f. krafft <madduck@madduck.net>
Mon, 5 May 2008 18:50:03 +0000 (19:50 +0100)
committermartin f. krafft <madduck@madduck.net>
Mon, 5 May 2008 18:50:03 +0000 (19:50 +0100)
.zsh/zshrc/85_git_prompt [new file with mode: 0644]
.zsh/zshrc/90_prompt

diff --git a/.zsh/zshrc/85_git_prompt b/.zsh/zshrc/85_git_prompt
new file mode 100644 (file)
index 0000000..9d05cca
--- /dev/null
@@ -0,0 +1,46 @@
+# zshrc/85_git_prompt
+#
+# Make git information available to the prompt
+#
+# Copyright © 1994–2008 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+# Source repository: http://git.madduck.net/v/etc/zsh.git
+#
+# Shamelessly adapted from http://www.jukie.net/~bart/conf/zsh.d/S55_git
+#
+
+_get_git_cur_branch() {
+  git branch --no-color | sed -rne 's,^\* ,,p'
+}
+
+_is_git_repo() {
+  [ $(git rev-parse --is-inside-work-tree) = true ]
+}
+
+_set_git_psvar() {
+  if _is_git_repo; then
+    psvar[1]="$(_get_git_cur_branch)"
+  else
+    unset "psvar[1]"
+  fi
+}
+
+update_git_vars_if_git_ran() {
+  # if the last command included the word git, the branch may have changed.
+  # checkout should be alright, but you never know...
+  case "$(history $(($HISTCMD - 1)))" in
+    *git*) _set_git_psvar;;
+  esac
+}
+precmd_functions+=update_git_vars_if_git_ran
+
+update_git_vars() {
+  _set_git_psvar
+}
+chpwd_functions+=update_git_vars
+
+# call it once
+update_git_vars
+
+# vim:ft=zsh
index 0abe13248a9ce6ba4beebdecadb0beddc0dfb913..afd13b22a8827063391beabfcb9addbb95aa4dda 100644 (file)
@@ -11,6 +11,6 @@
 is_root && PS1_HL=U
 PS1="%${PS1_HL:=B}%m%${(L)PS1_HL}:%25<..<%~%# "
 unset PS1_HL
-RPS1="#[%(0?..%?,)%!]%v"
+RPS1="#%(1v.%1v,.)%(0?..%?,)%!"
 
 # vim:ft=zsh