Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: precmd, preexec, and supplied prompt themes
- X-seq: zsh-workers 23947
- From: Clint Adams <clint@xxxxxxx>
- To: wgscott@xxxxxxxxxxxxxxxxxx
- Subject: Re: precmd, preexec, and supplied prompt themes
- Date: Sat, 13 Oct 2007 09:30:57 -0400
- Cc: Matthew Wozniski <godlygeek@xxxxxxxxx>, zsh-workers@xxxxxxxxxx
- In-reply-to: <20071012152257.91edf6d3.wgscott@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: wgscott@xxxxxxxxxxxxxxxxxx, Matthew Wozniski <godlygeek@xxxxxxxxx>, zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <DD973F2C-E6A0-4FCA-96F5-6C96701DC677@xxxxxxxxxxxxxxxxxx> <20071012215906.GA8935@mastermind> <20071012152257.91edf6d3.wgscott@xxxxxxxxxxxxxxxxxx>
[moving to -workers]
> Check out the zsh man page, section SPECIAL FUNCTIONS, or just search
> for 'hook function'. The long and short of it is that the prompt
> themes should be using
>
> typeset -a precmd_functions
> precmd_functions += my_prompt_precmd
Since there is no unregistration hook, how would you avoid the problem
of precmd_functions containing (my_prompt_precmd her_prompt_precmd
his_prompt_precmd my_prompt_precmd) when switching back and forth?
The clobbering below should now appear more explicit.
Index: Functions/Prompts/prompt_clint_setup
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Prompts/prompt_clint_setup,v
retrieving revision 1.6
diff -u -r1.6 prompt_clint_setup
--- Functions/Prompts/prompt_clint_setup 7 Sep 2006 18:09:44 -0000 1.6
+++ Functions/Prompts/prompt_clint_setup 13 Oct 2007 13:26:07 -0000
@@ -36,7 +36,7 @@
[[ -n "$WINDOW" ]] && p_win="$pc['\(']%{$fg_bold[$pcc[4]]%}$WINDOW$pc['\)']"
p_userpwd="$pc['<']%{$fg_no_bold[$pcc[3]]%}%n@%m$p_win%{$fg_bold[$pcc[5]]%}:%{$fg_no_bold[$pcc[4]]%}%~$pc['>']"
- [[ -f /proc/apm ]] && p_apm="%(2v.-%2v-.)"
+ p_git="%(2v.-%U%2v%u-.)"
p_shlvlhist="%{$reset_color%}zsh%(2L./$SHLVL.) %B%h%b "
p_rc="%(?..[%?%1v] )"
@@ -46,34 +46,28 @@
prompt="$p_date$p_tty$p_plat$p_ver
$p_userpwd
-$p_shlvlhist$p_rc$p_apm$p_end"
+$p_shlvlhist$p_rc$p_git$p_end"
PS2='%(4_.\.)%3_> %E'
- [[ -f /proc/apm ]] &&
- precmd () { prompt_clint_precmd ; prompt_clint_apm_precmd } ||
- precmd () { prompt_clint_precmd }
+ precmd () { prompt_clint_precmd }
preexec () { }
}
prompt_clint_precmd () {
setopt noxtrace noksharrays localoptions
local exitstatus=$?
+ local git_dir git_ref
+ psvar=()
[[ $exitstatus -ge 128 ]] && psvar[1]=" $signals[$exitstatus-127]" ||
psvar[1]=""
[[ -o interactive ]] && jobs -l
-}
-
-prompt_clint_apm_precmd () {
- setopt noxtrace noksharrays localoptions
- local bat ac
-
- bat=${${="$(</proc/apm)"}[7]/%/%%}
- [[ ${${="$(</proc/apm)"}[4]} == "0x01" ]] && ac="AC+"
+ git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return
+ git_ref=$(git-symbolic-ref HEAD 2> /dev/null) || git_ref="(no branch)"
+ psvar[2]=${ref#refs/heads/}
- [[ $bat == ("100%"|"-1%") ]] && psvar[2]=() || psvar[2]="$ac$bat"
}
prompt_clint_setup "$@"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author