zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: Alternate patch Re: PATCH: New prompt themes
Date: Wed, 20 Oct 1999 04:16:21 +0000	[thread overview]
Message-ID: <991020041621.ZM6569@candle.brasslantern.com> (raw)
In-Reply-To: <380CC25A.BC019EC7@u.genie.co.uk>

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 @@
        promptzzzz=$reset_color
        ;;
   esac
+}
+
+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


  parent reply	other threads:[~1999-10-20  6:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-19 19:11 Oliver Kiddle
1999-10-20  0:40 ` Bart Schaefer
1999-10-20  4:16 ` Bart Schaefer [this message]
1999-10-21  8:54   ` Alternate patch " Oliver Kiddle
1999-10-21 15:09     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=991020041621.ZM6569@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).