summaryrefslogtreecommitdiff
path: root/Functions/Prompts/promptinit
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Prompts/promptinit')
-rw-r--r--Functions/Prompts/promptinit37
1 files changed, 19 insertions, 18 deletions
diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index df3d30649..f68191dd2 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -30,9 +30,8 @@ promptinit () {
fi
done
- # Color definitions come in handy
- autoload -U colors
- colors
+ # To manipulate precmd and preexec hooks...
+ autoload -U add-zsh-hook
# Variables common to all prompt styles
prompt_newline=$'\n%{\r%}'
@@ -40,7 +39,7 @@ promptinit () {
prompt_preview_safely() {
emulate -L zsh
- print $reset_color
+ print -P "%b%f%k"
if [[ -z "$prompt_themes[(r)$1]" ]]; then
print "Unknown theme: $1"
return
@@ -48,7 +47,7 @@ prompt_preview_safely() {
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
+ local -a precmd_functions preexec_functions
# The next line is a bit ugly. It (perhaps unnecessarily)
# runs the prompt theme setup function to ensure that if
@@ -85,7 +84,7 @@ Use prompt -h <theme> for help on specific themes.'
# Not using a prompt theme; save settings
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
+ local precmd_functions preexec_functions
else
trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0
fi
@@ -130,7 +129,7 @@ Use prompt -h <theme> for help on specific themes.'
[[ "$theme" == "$prompt_theme[*]" ]] && continue
prompt_preview_safely "$=theme"
done
- print $reset_color
+ print -P "%b%f%k"
;;
s) print "Set and save not yet implemented. Please ensure your ~/.zshrc"
print "contains something similar to the following:\n"
@@ -153,21 +152,21 @@ Use prompt -h <theme> for help on specific themes.'
print "$usage"
return
fi
- prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" )
- # Avoid screwing up the environment listing
- PSZZZZ=$reset_color
- RPSZZZZ=$reset_color
- PROMPTZZZZ=$reset_color
- RPROMPTZZZZ=$reset_color
- promptzzzz=$reset_color
+ # Reset some commonly altered bits to the default
+ add-zsh-hook -D precmd "prompt_*_precmd"
+ add-zsh-hook -D preexec "prompt_*_preexec"
+ set -A zle_highlight ${zle_highlight:#default:*}
+ (( ${#zle_highlight} )) || unset zle_highlight
+
+ prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" )
;;
esac
}
prompt () {
local prompt_opts
-
+
set_prompt "$@"
(( $#prompt_opts )) &&
@@ -180,16 +179,18 @@ 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
+ local precmd_functions preexec_functions
print -n "$1 theme"
(( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'"
print ":"
prompt_${1}_setup "$@[2,-1]"
- typeset +f precmd >&- && precmd
+ [[ -n ${precmd_functions[(r)prompt_${1}_precmd]} ]] &&
+ prompt_${1}_precmd
[[ -o promptcr ]] && print -n $'\r'; :
print -P "${PS1}command arg1 arg2 ... argn"
- typeset +f preexec >&- && preexec
+ [[ -n ${preexec_functions[(r)prompt_${1}_preexec]} ]] &&
+ prompt_${1}_preexec
}
[[ -o kshautoload ]] || promptinit "$@"