about summary refs log tree commit diff
path: root/Functions/Prompts/promptinit
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-11-19 09:15:31 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-11-19 09:15:31 +0000
commit1ed30d4586030141eb57ff5d2ba285cac45633dc (patch)
tree70bd26e66610acc3462ff03e1647af9b1a08816f /Functions/Prompts/promptinit
parentc996001c28bad6ec35f27588c5199e00dcd97b8a (diff)
downloadzsh-1ed30d4586030141eb57ff5d2ba285cac45633dc.tar.gz
zsh-1ed30d4586030141eb57ff5d2ba285cac45633dc.tar.xz
zsh-1ed30d4586030141eb57ff5d2ba285cac45633dc.zip
zsh-workers/8672
Diffstat (limited to 'Functions/Prompts/promptinit')
-rw-r--r--Functions/Prompts/promptinit49
1 files changed, 34 insertions, 15 deletions
diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index 2786f9ac7..cfab990df 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -81,10 +81,11 @@ Use prompt -h <theme> for help on specific themes.'
        print $prompt_themes
        return
        ;;
-    p) if (( ! $+prompt_theme )); then
-         print "Cannot preview; current prompt is non-themeable and would"
-         print "be destroyed."
-         return
+    p) if [[ -z "$prompt_theme[1]" ]]; then
+         # Not using a prompt theme; save settings
+         prompt_non_theme=( "$PS1" "$PS2" "$PS3" "$PS4" "$RPS1" )
+         prompt_old_precmd="$(functions precmd)"
+         prompt_old_preexec="$(functions preexec)"
        fi
        preview=( $prompt_themes )
        (( $#* > 1 )) && preview=( "$@[2,-1]" )
@@ -97,10 +98,10 @@ Use prompt -h <theme> for help on specific themes.'
          fi
          print
 
-	 # The next line is a bit ugly.  It (perhaps unnecessarily)
-	 # runs the prompt theme setup function to ensure that if
-	 # the theme has a _preview function that it's been autoloaded.
-	 prompt_${theme_args[1]}_setup
+         # The next line is a bit ugly.  It (perhaps unnecessarily)
+         # runs the prompt theme setup function to ensure that if
+         # the theme has a _preview function that it's been autoloaded.
+         prompt_${theme_args[1]}_setup
 
          if functions prompt_${theme_args[1]}_preview >&/dev/null; then
            prompt_${theme_args[1]}_preview "${(@)theme_args[2,-1]}"
@@ -109,7 +110,25 @@ Use prompt -h <theme> for help on specific themes.'
          fi
        done
        print
-       prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"
+       if [[ -z "$prompt_theme[1]" ]]; then
+         PS1="$prompt_non_theme[1]"
+         PS2="$prompt_non_theme[2]"
+         PS3="$prompt_non_theme[3]"
+         PS4="$prompt_non_theme[4]"
+         RPS1="$prompt_non_theme[5]"
+         if [[ -z "$prompt_old_precmd" ]]; then
+           precmd () { }
+         else
+           eval "$prompt_old_precmd"
+         fi
+         if [[ -z "$prompt_old_preexec" ]]; then
+           preexec () { }
+         else
+           eval "$prompt_old_preexec"
+         fi
+       else
+         prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"
+       fi
        ;;
     s) print "Set and save not yet implemented.  Please ensure your ~/.zshrc"
        print "contains something similar to the following:\n"
@@ -118,12 +137,12 @@ Use prompt -h <theme> for help on specific themes.'
        print "  prompt $*[2,-1]"
        ;;
     *) if [[ "$1" == 'random' ]]; then
-	 local random_themes
-	 if (( $#* == 1 )); then
-	   random_themes=( $prompt_themes )
-	 else
-	   random_themes=( "$@[2,-1]" )
-	 fi
+         local random_themes
+         if (( $#* == 1 )); then
+           random_themes=( $prompt_themes )
+         else
+           random_themes=( "$@[2,-1]" )
+         fi
          local i=$(( ( $RANDOM % $#random_themes ) + 1 ))
          argv=( "${=random_themes[$i]}" )
        fi