From e1a6e3db0b8e15f9fd576341642acfebe0f13b68 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Fri, 1 May 2009 16:06:07 +0200 Subject: [PATCH] first attempt to use vcs_info --- .zsh/zshrc/50_prompt | 25 ++++++++++++++++++++++++ .zsh/zshrc/60_vcsprompt | 2 +- .zsh/zshrc/75_vcsinfo | 43 ++++++++++++++++++++++++++++++++--------- .zsh/zshrc/80_prompt | 26 ------------------------- 4 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 .zsh/zshrc/50_prompt delete mode 100644 .zsh/zshrc/80_prompt diff --git a/.zsh/zshrc/50_prompt b/.zsh/zshrc/50_prompt new file mode 100644 index 0000000..c039d00 --- /dev/null +++ b/.zsh/zshrc/50_prompt @@ -0,0 +1,25 @@ +# zshrc/80_prompt +# +# Formats the shell prompt +# +# Copyright © 1994–2008 martin f. krafft +# Released under the terms of the Artistic Licence 2.0 +# +# Source repository: git://git.madduck.net/etc/zsh.git +# + +is_root && _PS1_HL=U +_PS1_PREFIX="%(2L.+.)%${_PS1_HL:=B}%m%${(L)_PS1_HL}" +_PS1_PREFIX="$_PS1_PREFIX${debian_chroot:+/%S$debian_chroot%s}:" + +_PS1_SUFFIX='%# ' + +_make_ps1() { + PS1="${_PS1_PREFIX}$@${_PS1_SUFFIX}" +} + +[[ $PS1 = '%m%# ' ]] && _make_ps1 '%25<..<%~%<<' + +: ${RPS1:="#%(0?..%?,)%!"} + +# vim:ft=zsh diff --git a/.zsh/zshrc/60_vcsprompt b/.zsh/zshrc/60_vcsprompt index 399d344..237f6c0 100644 --- a/.zsh/zshrc/60_vcsprompt +++ b/.zsh/zshrc/60_vcsprompt @@ -205,7 +205,7 @@ __vcs_print_preprompt() esac } -if ! is_root; then +if false && ! is_root; then # too dangerous to be run as root _update_vcs_prompt_vars_if_vcs_ran() { diff --git a/.zsh/zshrc/75_vcsinfo b/.zsh/zshrc/75_vcsinfo index 5592fc1..fb7bb74 100644 --- a/.zsh/zshrc/75_vcsinfo +++ b/.zsh/zshrc/75_vcsinfo @@ -12,15 +12,40 @@ autoload -Uz vcs_info -zstyle ':vcs_info:*' actionformats \ - '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' -zstyle ':vcs_info:*' formats \ - '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f ' -zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' - -#PS1=’%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}’"%f%# ’ +# %s The vcs in use (git, hg, svn etc.) +# %b Information about the current branch. +# %a An identifier, that describes the action. Only makes sense in actionformats. +# %i The current revision number or identifier. +# %c The string from the stagedstr style if there are staged changes in the repository. +# %u The string from the unstagedstr style if there are unstaged changes in the repository. +# %R base directory of the repository. +# %r repository name. If %R is /foo/bar/repoXY, %r is repoXY. +# %S subdirectory within a repository. If $PWD is /foo/bar/reposXY/beer/tasty, %S is +# beer/tasty. +# %m A "misc" replacement. It is at the discretion of the backend to decide what this +# replacement expands to. It is currently used only by the hg backend. The hg backend +# replaces %m with the global hash value of the current revision. zstyle ':vcs_info:*' disable cdv darcs mtn svk p4 tla +zstyle ':vcs_info:*' check-for-changes true +zstyle ':vcs_info:*' max-exports 6 +zstyle ':vcs_info:*' formats '%R' '%s' '%b' '' '%c%u' '%S' +zstyle ':vcs_info:*' actionformats '%R' '%s' '%b' '%a' '%c%u' '%S' + +__vcs_info_precmd() { + vcs_info + + local prefix="${vcs_info_msg_0_/$HOME/~}" + local suffix="$vcs_info_msg_5_" + [[ $suffix = . ]] && suffix='' + + local type="$vcs_info_msg_1_" + [[ $type = git ]] && type='' + local branch="$vcs_info_msg_2_" + local action="$vcs_info_msg_3_" + local changes="$vcs_info_msg_4_" + local vcsinfo="${type:+${type}:}%B${branch}%b${action:+|%B${action}%b}" -#this enables vcs_info -#precmd_functions+=vcs_info + _make_ps1 "$prefix|$vcsinfo|$suffix${changes:+|%S${changes}%s}" +} +precmd_functions+=__vcs_info_precmd diff --git a/.zsh/zshrc/80_prompt b/.zsh/zshrc/80_prompt deleted file mode 100644 index d687dd6..0000000 --- a/.zsh/zshrc/80_prompt +++ /dev/null @@ -1,26 +0,0 @@ -# zshrc/80_prompt -# -# Formats the shell prompt -# -# Copyright © 1994–2008 martin f. krafft -# Released under the terms of the Artistic Licence 2.0 -# -# Source repository: git://git.madduck.net/etc/zsh.git -# - -if [ "${PS1:-}" = '%m%# ' ]; then - local _MIDDLE="%1v%(2v.|%B%2v%b|.)%(3v.%3v.)" - if is_root; then - _MIDDLE="%25<..<%~%<<" - local _PS1_HL=U - fi - - local _MACHINE_NAME="${_PS1_HL:=B}%m%${(L)_PS1_HL}" - _MACHINE_NAME="$_MACHINE_NAME${debian_chroot:+/%S$debian_chroot%s}" - - PS1="%(2L.+.)%${_MACHINE_NAME}:${_MIDDLE}%# " -fi - -: ${RPS1:="#%(0?..%?,)%!"} - -# vim:ft=zsh -- 2.39.5