Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Alternate patch Re: PATCH: New prompt themes

On Oct 19,  8:11pm, Oliver Kiddle wrote:
} Subject: PATCH: New prompt themes
} The trouble is that the prompt function uses emulate -L so I can't set
} options in my prompt setup function. The following patch is a possible
} solution. It uses an associative array to return the prompt options to
} a wrapper function which sets them. For example, you can do:
} prompt_opts=( subst set percent set bang unset )

There doesn't seem to be any reason to put the set_prompt function inside
the prompt function, so I suggest the following smaller patch.  It's the
same code Oliver sent, without a lot of the reindentation, so it would be
used in place of Oliver's original.

I'm not sure that it's that useful to factor out the prefix "prompt" from
each of the strings in prompt_opts, but I'm not going to change that here.
Further, I might suggest that instead of an assoc. array with both set and
unset values, just use a regular array of only the values that are meant to
be set; e.g. one command instead of a loop:

  setopt noprompt{bang,cr,percent,subst} prompt$^prompt_opts

However, I didn't make that change either.

Index: Functions/Prompts/promptinit
@@ -34,7 +34,7 @@
   prompt_newline=$(echo -ne "\n%{\r%}")
-prompt () {
+set_prompt() {
   emulate -L zsh
   local opt preview theme usage old_theme
@@ -103,6 +103,23 @@
+prompt () {
+  local -A prompt_opts
+  local opt
+  set_prompt "$@"
+  # Set prompt options
+  for opt in ${(k)prompt_opts}; do
+    if [[ $prompt_opts[$opt] != (|un)set ]]; then
+      echo "${0##*/}: value of prompt option must be 'set' or 'unset'" >&2
+      return 1
+    else
+      $prompt_opts[$opt]opt prompt$opt
+    fi
+  done
 promptinit "$@"

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Messages sorted by: Reverse Date, Date, Thread, Author