[Pkg-zsh-devel] Bug#792703: zsh: please improve newuser.zshrc.recommended and add new prompt_debian_setup

Carsten Hey carsten at debian.org
Sat Aug 8 17:29:25 UTC 2015


[ dropping #756138 again from CC, people reading
  it should now know that there is a related bug ]

Hi Frank,

thanks a lot for you insightful feedback :)

I noticed, that I should add a note how to disable displaying the name
of a debian chroot (i.e., set it to "" or unset it).

* Frank Terbeck [2015-08-08 17:28 +0200]:
> Carsten Hey wrote:
> [...]
> > I think "#setopt no_beep" and "#stty -ixon" should also be added to
>
> The latter might better be replaced by zsh's "no_flow_control" option.

Indeed, setopt no_flow_control is much better.

> [...]
> > This prompt color-scheme-able via zstyle.  If the variabale TERM is set to
> > 'dumb', colors are disabled, though.  You can invoke the prompt thus:
> >
> >   prompt debian
> >   TERM=dumb prompt debian
>
> You could also check something like a "blacklist" style, that could be a
> list of term names (or better yet, patterns). That way you could
> blacklist $TERMs like "emacs" for colours as well.

Looks like emacs used to set TERM to dumb (see #143361), but this might
have changed.  Anyway, the blacklist is a great idea, the default
blacklist would currently contain emacs and dumb.

> >   zstyle ':prompt:debian:*' STYLE COLOR

Hmm, even if * matches :, this could be changed to ':prompt:debian:*:*'
(one * for the host name and one for the user name).

> >   PROMPT='%B!%!%b '"$PROMPT"
> >   zstyle ':vcs_info:*' nvcsformats '%B%F{2}%(1j.j%j .)%(2L.L%L .)%b%f'
>
> Maybe use a name rather than a number here: %F{green}

At least for the examples shown in the help text %F{green} is much more
readable.

> >     local pwd_max_length=60
> >     local pwd_max_subdirs=5
> >     local wrap_at_char='-25'
>
> Maybe make these configurable via styles?

It was configurable, but I assumed that nobody would care about being
able to configure this and removed it again - looks like I was wrong.
The additional file I attached contains a part of what is required to
make it configurable via styles, just in case I'll need it in the
future.  I'll also add "local enable_exit_status=1" again in order to
make this configurable too.

> >         # color config:
> >         local dircolor= usercolor= usercolor_root= exitcolor= exitcolor_root=
> >         zstyle -s "$zstyle_pattern" dircolor       dircolor
> >         zstyle -s "$zstyle_pattern" usercolor      usercolor
> >         zstyle -s "$zstyle_pattern" usercolor-root usercolor_root
> >         zstyle -s "$zstyle_pattern" exitcolor      exitcolor
> >         zstyle -s "$zstyle_pattern" exitcolor-root exitcolor_root
> >         : "${dircolor:=4}" "${usercolor:=2}" "${usercolor_root:=1}"
> >         : "${exitcolor:=1}" "${exitcolor_root:=2}"
>
> To set defaults you can do:
>
>   zstyle -s "$zstyle_pattern" dircolor dircolor || dircolor=4
>
> And again, maybe rather use names instead of numbers:
>
>   zstyle -s "$zstyle_pattern" dircolor dircolor || dircolor=blue
>
> You also don't need to initialise to the empty string in the "local"
> above.

"zstyle -s ... || dircolor=..." looks a lot cleaner than what I had.

I'm undecided, but easily convincible, whether color names or numbers
should be used in a string that users won't see (unless they do print -r
-- "$PROMPT" and try to understand the output), given that the numbers
are shorter.

> >         ##TODO uncomment if setopt transientrprompt works in a prompt function
> >         ## Ease copying multi-line commands with the mouse.
> >         ## <http://www.zsh.org/mla/workers/2015/msg01767.html>
> >         #local rps2color=$dircolor
> >         #setopt transient_rprompt
>
> I don't understand this. "transientrprompt" can — and IMO should be —
> set outside a prompt setup.

Without transient_rprompt, the painless multiline copying won't work and
therefore there would be no reason to set PS2 and RPS2 accordingly.
I assume one has to read the linked thread to fully understand what the
purpose of this four lines is (or try it interactively).

Alternative approaches are:
 * setting PS2 and RPS2 and expecting the user to set transient_rprompt
   (which is fine for a default .zshrc, but might not be the best idea
   if used in a hand-written .zshrc)
 * providing a function users are able to call if they want this
   behaviour - this sounds like a good approach if it is done
   independent from a specific prompt

> >         #PS2='${${options[singlelinezle]#off}:+%_> }'
>
> I'd do this in an "if ...; then...; fi" to improve readability.

An if condition would not catch cases when singlelinezle is set after
the prompt's setup function is run (we don't build the prompt in
a precmd) - OTOH this is not an option many people would set.

> The contents of the ".thisfiledoesnotexist" file seems very similar to
> the one of the "prompt_debian_setup" file. Attached by mistake?

It contains some additional lines (as mentioned above) I expected to
need in some years, if at all - but apparently I need them in this year.


Carsten



More information about the Pkg-zsh-devel mailing list