Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: prompt theme system improvements
- X-seq: zsh-workers 8684
- From: Oliver Kiddle <opk@xxxxxxxxxxxxx>
- To: Adam Spiers <adam@xxxxxxxxxx>
- Subject: Re: PATCH: prompt theme system improvements
- Date: Fri, 19 Nov 1999 11:42:22 +0000
- Cc: Zsh workers <zsh-workers@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <19991118145330.A22718@xxxxxxxxxxxxxxxxxxxxxxx>
Adam Spiers wrote:
> Changes in full gory detail:
> ----------------------------
>
> - Colours are now all in assoc arrays.
This is much better. We should maybe add the 'gray' spelling aswell as 'grey' to the associative arrays so people have the choice. I'd also put the other attributes in an associative array so instead of $boldcolor, we have $color_attr[reset, bold, underline, standout] etc.
> - `adam1', `fire', `elite' and `elite2' made colour-scheme-able.
I've patched the 'oliver' prompt to use the colour names aswell patch follows.
> - Fixed bug in Oliver's prompt; it doesn't work if you don't set up
Thanks.
> Known bugs:
> -----------
>
> - I notice that the _prompt completion function no longer works,
> presumably through one of the many changes to arguments. I'll try
> to fix this unless someone gets there first.
I suppose that we should allow the different prompts to specify completion for their parameters. Only trouble is that we can't get at any functions in the prompt until they have been setup.
> - Some of the colours are tasteless. Beauty is in the eye of the
> beholder ... Contributions from graphic designers/artists welcome :-)
I'd also say that it isn't exactly wise that the majority of the example prompts require a strange font.
> - It would be nice to be able control the `bold-ness' of the colours
> provided as theme provided.
I've done this with the 'oliver' prompt in the patch below - precede the colours with the word 'bold'.
> - precmd and preexec still get stomped on. I think the solution to
> this is to use Bart's addprecmd to add a hook to them both which
> calls prompt_pre{cmd,exec} respectively the first time promptinit
> is run, and then subsequent theme changes can alter these hook
> functions without messing up the original pre{cmd,exec}. Does
> that sound reasonable?
That sounds like the best solution.
I also think it would be sensible for promptinit to save the original PS2 and PS3 and set them back to the originals before changing prompt. This means that any prompts which don't set them will use the original settings instead of those set by the last theme.
The patch below makes a few of your prompts use prompt_opts insead of precmd. I've added 'true' to the end of the prompt function because it was returning an exit code of one half the time. It should probably return set_prompt's return code and set_prompt should return sensible exit codes and send its error messages to stderr but I haven't done this.
The typeset -g prompt_theme line echos the value of prompt_theme if it is set so I redirected it to /dev/null. I also updated my prompt with some other changes.
With respect to colour themes. It would be good to have a single way for defining colours across zsh. ZLS_COLOURS may be compatible with GNU ls but it isn't exactly the most readable way. One possible way would be to use an associative array for colours where the keys specify the context and the values specify the attributes. So for example, you might define:
zsh_colours[ls_directories]="bold blue on white"
zsh_colours[prompt_currentdir]="underlined green"
If different prompt themes use the same context words, you could share colour selections across prompts. It might also lead to a mechanism for defining the colours for different types of completion matches in the lists - not just for files.
Oliver Kiddle
diff -u Prompts.old/prompt_off_setup Prompts/prompt_off_setup
--- Prompts.old/prompt_off_setup Thu Nov 18 16:15:57 1999
+++ Prompts/prompt_off_setup Fri Nov 19 10:40:35 1999
@@ -4,7 +4,8 @@
PS1="%# "
PS2="> "
- precmd () { setopt promptsubst }
+ prompt_opts=( cr percent )
+ precmd () { }
preexec () { }
}
diff -u Prompts.old/prompt_oliver_setup Prompts/prompt_oliver_setup
--- Prompts.old/prompt_oliver_setup Thu Nov 18 17:40:39 1999
+++ Prompts/prompt_oliver_setup Fri Nov 19 10:11:22 1999
@@ -9,7 +9,8 @@
The colour of the prompt depends on two associative arrays -
$pcolour and $tcolour. Each array is indexed by the name of the
local host. Alternatively, the colour can be set with parameters
-to prompt.
+to prompt. To specify colours, use English words like 'yellow',
+optionally preceded by 'bold'.
The hostname and username are also included unless they are in the
$normal_hosts or $normal_users array.
@@ -17,21 +18,23 @@
}
prompt_oliver_setup() {
- prompt_opts=( percent )
+ prompt_opts=( cr subst percent )
[[ "${(t)pcolour}" != assoc* ]] && typeset -Ag pcolour
[[ "${(t)tcolour}" != assoc* ]] && typeset -Ag tcolour
- local pcol=$'\e['${1:-${pcolour[${HOST:=`hostname`}]:-33}}m
- local tcol=$'\e['${2:-${tcolour[$HOST]:-37}}m
+ local pcol=${1:-${pcolour[${HOST:=`hostname`}]:-yellow}}
+ local pcolr=$fg[${pcol#bold}]
+ [[ $pcol = bold* ]] && pcolr=$bold_color$pcolr
+
+ local tcol=${2:-${tcolour[$HOST]:-white}}
+ local tcolr=$reset_color$fg[${tcol#bold}]
+ [[ $tcol = bold* ]] && tcolr=$tcolr$bold_color
+
local a host="%M:" user="%n "
- for a in $normal_hosts; do
- [[ $HOST == $a ]] && host=""
- done
- for a in root $normal_users; do
- [[ ${USER:-`whoami`} == $a ]] && user=""
- done
+ [[ $HOST == (${(j(|))~normal_hosts}) ]] && host=""
+ [[ ${USER:-`whoami`} == (root|${(j(|))~normal_users}) ]] && user=""
- PS1="%{$pcol%}$user$host%~ [%h%0(?..:%?)]%# %{$tcol%}"
+ PS1="%{$pcolr%}$user$host%~%"'$((COLUMNS-12))'"(l.$prompt_newline. )[%h%0(?..:%?)]%# %{$tcolr%}"
}
prompt_oliver_setup "$@"
diff -u Prompts.old/prompt_redhat_setup Prompts/prompt_redhat_setup
--- Prompts.old/prompt_redhat_setup Fri Oct 15 10:38:21 1999
+++ Prompts/prompt_redhat_setup Fri Nov 19 10:36:25 1999
@@ -6,7 +6,8 @@
PS1="[%n@%m %1~]\\$ "
PS2="> "
- precmd () { setopt promptsubst }
+ prompt_opts=( cr percent )
+ precmd () { }
preexec () { }
}
diff -u Prompts.old/prompt_suse_setup Prompts/prompt_suse_setup
--- Prompts.old/prompt_suse_setup Thu Nov 18 16:15:57 1999
+++ Prompts/prompt_suse_setup Fri Nov 19 10:32:17 1999
@@ -6,7 +6,8 @@
PS1="%n@%m:%~/ > "
PS2="> "
- precmd () { setopt promptsubst }
+ prompt_opts=( cr percent )
+ precmd () { }
preexec () { }
}
diff -u Prompts.old/prompt_zefram_setup Prompts/prompt_zefram_setup
--- Prompts.old/prompt_zefram_setup Thu Nov 18 16:15:57 1999
+++ Prompts/prompt_zefram_setup Fri Nov 19 10:31:13 1999
@@ -10,7 +10,8 @@
PS1='[%(2L.%L/.)'$ZSH_VERSION']%(?..%B{%v}%b)%n%(2v.%B@%b.@)%m:%B%~%b%(!.#.>) '
PS2='%(4_:... :)%3_> '
- precmd () { prompt_zefram_precmd; setopt promptsubst }
+ prompt_opts=( cr subst percent )
+ precmd () { prompt_zefram_precmd }
preexec () { }
}
diff -u Prompts.old/promptinit Prompts/promptinit
--- Prompts.old/promptinit Thu Nov 18 16:15:57 1999
+++ Prompts/promptinit Fri Nov 19 10:58:51 1999
@@ -8,12 +8,12 @@
prompt_themes=()
typeset -gU prompt_themes
-typeset -g prompt_theme
+typeset -g prompt_theme >/dev/null
promptinit () {
emulate -L zsh
setopt extendedglob
- local ppath='' name
+ local ppath='' name theme
# Autoload all prompt_*_setup functions in fpath
for theme in $^fpath/prompt_*_setup(N); do
@@ -151,6 +151,8 @@
(( $#prompt_opts )) &&
setopt noprompt{bang,cr,percent,subst} prompt${^prompt_opts[@]}
+
+ true
}
prompt_preview_theme () {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author