* precmd, preexec, and supplied prompt themes
@ 2007-10-12 21:47 William Scott
2007-10-12 21:59 ` Matthew Wozniski
0 siblings, 1 reply; 12+ messages in thread
From: William Scott @ 2007-10-12 21:47 UTC (permalink / raw)
To: zsh-users
Hi folks:
I noticed most of the prompt themes use precmd and often preexec.
If either or both of these two functions are defined upstream, they
get clobbered.
Is there a simple way to prepend or append additional arguments to
these (or any) functions? I've been doing something like this, but
it seems hackish:
precmdarray=( $(which precmd | grep -v precmd | grep -v \}) )
function precmd { $precmdarray "all the other stuff" }
Thanks.
Bill Scott
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-12 21:47 precmd, preexec, and supplied prompt themes William Scott
@ 2007-10-12 21:59 ` Matthew Wozniski
2007-10-12 22:22 ` wgscott
2007-10-13 1:50 ` Bart Schaefer
0 siblings, 2 replies; 12+ messages in thread
From: Matthew Wozniski @ 2007-10-12 21:59 UTC (permalink / raw)
To: zsh-users; +Cc: wgscott
On Fri, Oct 12, 2007 at 02:47:23PM -0700, William Scott wrote:
> Is there a simple way to prepend or append additional arguments to these
> (or any) functions? I've been doing something like this, but it seems
> hackish:
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
and
typeset -a preexec_functions
preexec_functions += my_prompt_preexec
If you're talking about prompt themes supplied with zsh, I would
consider it a bug in the package if those aren't defined that way.
~Matt
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-12 21:59 ` Matthew Wozniski
@ 2007-10-12 22:22 ` wgscott
2007-10-13 1:50 ` Bart Schaefer
1 sibling, 0 replies; 12+ messages in thread
From: wgscott @ 2007-10-12 22:22 UTC (permalink / raw)
To: Matthew Wozniski; +Cc: zsh-users
On Fri, 12 Oct 2007 17:59:06 -0400
Matthew Wozniski <godlygeek@gmail.com> wrote:
On Fri, Oct 12, 2007 at 02:47:23PM -0700, William Scott wrote:
> Is there a simple way to prepend or append additional arguments to these
> (or any) functions? I've been doing something like this, but it seems
> hackish:
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
and
typeset -a preexec_functions
preexec_functions += my_prompt_preexec
If you're talking about prompt themes supplied with zsh, I would
consider it a bug in the package if those aren't defined that way.
~Matt
Thanks. That seems like a good approach.
These for example all appear to just define a precmd function:
prompt_bigfade_setup
prompt_elite2_setup
prompt_elite_setup
prompt_fade_setup
prompt_fire_setup
prompt_off_setup
prompt_redhat_setup
prompt_suse_setup
prompt_zefram_setup
The adam1,2, bart and clint ones seem to be doing something else that I suspect is designed to prevent clobbering the function.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-12 21:59 ` Matthew Wozniski
2007-10-12 22:22 ` wgscott
@ 2007-10-13 1:50 ` Bart Schaefer
2007-10-13 2:09 ` William Scott
1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2007-10-13 1:50 UTC (permalink / raw)
To: zsh-users
On Oct 12, 5:59pm, Matthew Wozniski wrote:
}
} themes should be using
}
} typeset -a precmd_functions
} precmd_functions += my_prompt_precmd
}
} and
}
} typeset -a preexec_functions
} preexec_functions += my_prompt_preexec
}
} If you're talking about prompt themes supplied with zsh, I would
} consider it a bug in the package if those aren't defined that way.
Most of the prompt themes pre-date the existence of the pre*_functions
arrays, and aren't being maintained because their inventors are no longer
zsh-* list participants.
Stomping precmd is the least of the problems with several of those
themes; they rely on now-ancient Linux console fonts for color shading,
assume light-colored text on a dark background, etc. We need some new
ones.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 1:50 ` Bart Schaefer
@ 2007-10-13 2:09 ` William Scott
2007-10-13 3:27 ` Bart Schaefer
0 siblings, 1 reply; 12+ messages in thread
From: William Scott @ 2007-10-13 2:09 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote:
> On Oct 12, 5:59pm, Matthew Wozniski wrote:
> }
> } themes should be using
> }
> } typeset -a precmd_functions
> } precmd_functions += my_prompt_precmd
> }
> } and
> }
> } typeset -a preexec_functions
> } preexec_functions += my_prompt_preexec
> }
> } If you're talking about prompt themes supplied with zsh, I would
> } consider it a bug in the package if those aren't defined that way.
>
> Most of the prompt themes pre-date the existence of the pre*_functions
> arrays, and aren't being maintained because their inventors are no longer
> zsh-* list participants.
>
> Stomping precmd is the least of the problems with several of those
> themes; they rely on now-ancient Linux console fonts for color shading,
> assume light-colored text on a dark background, etc. We need some new
> ones.
>
OK, here's two:
http://xanana.ucsc.edu/Library/init/zsh/local-functions/general/prompt_kerbaugh_setup
in honor of Gary Kerbaugh, who introduced me to zsh (I'll clean it up for
zsh if you want it), and
http://xanana.ucsc.edu/Library/init/zsh/local-functions/general/prompt_simple_setup
my very own minimalistic/nihilistic theme.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 2:09 ` William Scott
@ 2007-10-13 3:27 ` Bart Schaefer
2007-10-13 20:58 ` wgscott
0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2007-10-13 3:27 UTC (permalink / raw)
To: zsh-users
On Oct 12, 7:09pm, William Scott wrote:
}
} Bart Schaefer wrote:
} > We need some new ones.
}
} OK, here's two:
These are fine prompts, but they aren't quite themes, yet.
The prompt_ZZZ_setup file for any theme ZZZ ought to define at least
two functions:
prompt_ZZZ_help
prompt_ZZZ_setup
See Functions/Prompts/prompt_oliver_setup for a simple example. One
other function may be defined as well:
prompt_ZZZ_preview
See Functions/Prompts/prompt_elite_setup for a short example of that.
Any other prompt_*_function or precmd/preexec are just helpers; the
theme system only uses the above three.
I know, some of the existing themes don't define help or preview, but
that doesn't mean they shouldn't.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 3:27 ` Bart Schaefer
@ 2007-10-13 20:58 ` wgscott
2007-10-13 21:40 ` Bart Schaefer
0 siblings, 1 reply; 12+ messages in thread
From: wgscott @ 2007-10-13 20:58 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
On Fri, 12 Oct 2007 20:27:21 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
These are fine prompts, but they aren't quite themes, yet.
Well, that pretty much ensured I wouldn't get any work done this weekend.
I've tried to whip my "simple" prompt into shape. I think it is almost there, but I am
having two difficulties that I am afraid I need to ask help with:
http://xanana.ucsc.edu/Library/init/zsh/local-functions/general/prompt_simple_setup
The first is that the prompt_simple_preview function doesn't work.
The second, and more fundamental one, is that I can't get the dynamic updating to work
unless I issue these six lines in the shell itself, in addition to the prompt function:
typeset -a preexec_functions
preexec_functions+=mypreexec
typeset -a precmd_functions
precmd_functions+=myprecmd
typeset -a chpwd_functions
chpwd_functions+=mychpwd
After I do that, it all works fine. But I can't seem to do this from within a function, which leads me to believe I am missing something obvious (that I can't find in the manual -- sorry).
Thanks.
Bill Scott
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 20:58 ` wgscott
@ 2007-10-13 21:40 ` Bart Schaefer
2007-10-13 21:53 ` William Scott
0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2007-10-13 21:40 UTC (permalink / raw)
To: zsh-users
On Oct 13, 1:58pm, wgscott@chemistry.ucsc.edu wrote:
}
} Well, that pretty much ensured I wouldn't get any work done this weekend.
:-)
} The first is that the prompt_simple_preview function doesn't work.
"Doesn't work" how?
Note that the prompt_simple_setup file needs to be found in a directory
in your $fpath to be loaded as a recognized theme by "promptinit". If
it's not in $fpath, you'll get
% prompt -p simple
Unknown theme: simple
%
Is that what's happening?
Also your attempt to display the available colors in prompt_simple_help
is not working for me; "black" compes out white, and neither it nor
"white" are visible on the white background of my xterm. I'd suggest
restricting the help to bare text and leaving the color demonstrations
to the preview.
} The second, and more fundamental one, is that I can't get the dynamic
} updating to work unless I issue these six lines in the shell itself,
} in addition to the prompt function:
}
} typeset -a preexec_functions
Try "typeset -ga preexec_functions" as was pointed out somewhere on this
thread.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 21:40 ` Bart Schaefer
@ 2007-10-13 21:53 ` William Scott
2007-10-13 23:11 ` Bart Schaefer
0 siblings, 1 reply; 12+ messages in thread
From: William Scott @ 2007-10-13 21:53 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote:
> } The first is that the prompt_simple_preview function doesn't work.
>
> "Doesn't work" how?
zsh-% prompt_simple_preview
prompt_preview_theme:2: bad pattern: PS1=%B%{^[[39m%}zsh-%# %{^[[39m%}%b
> Also your attempt to display the available colors in prompt_simple_help
> is not working for me; "black" compes out white, and neither it nor
> "white" are visible on the white background of my xterm. I'd suggest
> restricting the help to bare text and leaving the color demonstrations
> to the preview.
Ok. (Mine made them grey.) But it cleverly hides non-viable options from
the user.
> Try "typeset -ga preexec_functions"
That worked. (I knew it had to be something to do with "global".)
>as was pointed out somewhere on this thread.
Sorry, I somehow missed it. (Matt just had the -a).
Thanks.
Bill
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 21:53 ` William Scott
@ 2007-10-13 23:11 ` Bart Schaefer
2007-10-13 23:39 ` William Scott
0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2007-10-13 23:11 UTC (permalink / raw)
To: zsh-users
On Oct 13, 2:53pm, William Scott wrote:
}
} zsh-% prompt_simple_preview
} prompt_preview_theme:2: bad pattern: PS1=%B%{^[[39m%}zsh-%# %{^[[39m%}%b
You have 'setopt globsubst', which prompt_preview_theme is not prepared
to deal with. That should probably be considered a bug.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 23:11 ` Bart Schaefer
@ 2007-10-13 23:39 ` William Scott
2007-10-14 2:49 ` Bart Schaefer
0 siblings, 1 reply; 12+ messages in thread
From: William Scott @ 2007-10-13 23:39 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote:
> On Oct 13, 2:53pm, William Scott wrote:
> }
> } zsh-% prompt_simple_preview
> } prompt_preview_theme:2: bad pattern: PS1=%B%{^[[39m%}zsh-%# %{^[[39m%}%b
>
> You have 'setopt globsubst', which prompt_preview_theme is not prepared
> to deal with. That should probably be considered a bug.
>
Unsetting it masked perhaps another (in promptinit):
zsh-% prompt_simple_preview
simple theme:
prompt_preview_theme:9: command not found: precmd
zsh-% command arg1 arg2 ... argn
prompt_preview_theme:12: command not found: preexec
simple theme with parameters `default yellow green':
prompt_preview_theme:9: command not found: precmd
zsh-% command arg1 arg2 ... argn
prompt_preview_theme:12: command not found: preexec
zsh-%
Sorry for opening this can of worms...
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: precmd, preexec, and supplied prompt themes
2007-10-13 23:39 ` William Scott
@ 2007-10-14 2:49 ` Bart Schaefer
0 siblings, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2007-10-14 2:49 UTC (permalink / raw)
To: zsh-users
On Oct 13, 4:39pm, William Scott wrote:
}
} Sorry for opening this can of worms...
It probably needed opening.
Index: Functions/Prompts/promptinit
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Functions/Prompts/promptinit,v
retrieving revision 1.3
diff -c -r1.3 promptinit
--- promptinit 1 Oct 2006 02:38:52 -0000 1.3
+++ promptinit 14 Oct 2007 02:47:52 -0000
@@ -39,6 +39,7 @@
}
prompt_preview_safely() {
+ emulate -L zsh
print $reset_color
if [[ -z "$prompt_themes[(r)$1]" ]]; then
print "Unknown theme: $1"
@@ -165,6 +166,7 @@
}
prompt () {
+ emulate -L zsh
local prompt_opts
set_prompt "$@"
@@ -176,6 +178,7 @@
}
prompt_preview_theme () {
+ emulate -L zsh
local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick
local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1
trap "${$(functions precmd):-:} ; ${$(functions preexec):-:}" 0
@@ -184,10 +187,10 @@
(( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'"
print ":"
prompt_${1}_setup "$@[2,-1]"
- precmd
+ typeset +f precmd >&- && precmd
[[ -o promptcr ]] && print -n $'\r'; :
print -P "${PS1}command arg1 arg2 ... argn"
- preexec
+ typeset +f preexec >&- && preexec
}
[[ -o kshautoload ]] || promptinit "$@"
--
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2007-10-14 2:50 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-12 21:47 precmd, preexec, and supplied prompt themes William Scott
2007-10-12 21:59 ` Matthew Wozniski
2007-10-12 22:22 ` wgscott
2007-10-13 1:50 ` Bart Schaefer
2007-10-13 2:09 ` William Scott
2007-10-13 3:27 ` Bart Schaefer
2007-10-13 20:58 ` wgscott
2007-10-13 21:40 ` Bart Schaefer
2007-10-13 21:53 ` William Scott
2007-10-13 23:11 ` Bart Schaefer
2007-10-13 23:39 ` William Scott
2007-10-14 2:49 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).