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

Re: [RFC][PATCH] `newuser` prompt theme



On Wed, Apr 14, 2021 at 7:09 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> Make defaults overridable.
>
> Don't trample user settings (e.g., someone explicitly setting that style
> to a false value for that same context, or for the context «:vcs_info*»,
> which is less specific than the context you use and thus would be shadowed).

I have a half-finished script to initialize interesting completion
styles.  In that script I test the styles to be set by using "zstyle
-g", and then only if that fails, set the value I want.

emulate zsh -o extendedglob -c 'default_zstyle() {
  local -a patstyle defn
  if [[ "$1" = (-e|-|--) ]]
  then patstyle=( "$2" "$3" )
  else patstyle=( "$1" "$2" )
  fi
  ! zstyle -T "${patstyle[@]}" ||
   zstyle -g defn "${patstyle[@]}" ||
    zstyle "$@"
}'

Thus:

default_zstyle -e ':vcs_info:*' formats '
  reply=( "%u%c$( prompt_newuser_format start branch repo )" )
'

The "zstyle -T" treats the new style's pattern as a context and tries
to look up an existing style; that mostly works.  "zstyle -g" is just
a failsafe.




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