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

Frank Terbeck ft at bewatermyfriend.org
Sat Aug 8 15:28:34 UTC 2015


Hi Carsten,

I looked through the suggestions from your last mail; comments inline.

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.

[...]
> 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.

> To configure the prompt's colors, this command can be used (don't forget to
> run 'prompt debian' again to activate the changes):
>
>   zstyle ':prompt:debian:*' STYLE COLOR

Good! I like it when people refrain from polluting the global parameter
name space just for prompt colours. This is good. :-)

[...]
> Displaying version control information via vcs_info and displaying the name of
> a Debian chroot is supported by this prompt, but only the latter is enabled by
> default.  To enable vcs_info with the user-context 'prompt_debian', run:
>
>   add-zsh-hook precmd prompt_debian_precmd_vcsinfo

Makes sense.

[...]
>   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}

> EOF
> }
>
> prompt_debian_precmd_vcsinfo () {
>     setopt localoptions noxtrace
>     vcs_info prompt_debian || return $?
> }
>
> prompt_debian_setup () {
>     prompt_opts=(cr subst percent)
>
>     local zstyle_pattern=":prompt:debian:${HOST:-unknown}:${USERNAME:-unknown}"
>
>     local pwd_max_length=60
>     local pwd_max_subdirs=5
>     local wrap_at_char='-25'

Maybe make these configurable via styles?

>
>     local p_exit='${${options[printexitvalue]#on}:+%0(?..%? )}'
>     local p_pwd="%${pwd_max_length}<...<%$(( pwd_max_subdirs + 1
>                                           ))(~:.../:)%${pwd_max_subdirs}~%<<"
>     local p_space_or_newline="%${wrap_at_char}(l: :${prompt_newline})"
>     local p_vcsinfo='${vcs_info_msg_0_-}'
>     local p_reset='%b%f%k'
>     local p_2nd_newline="%1(l:%${wrap_at_char}(l..${prompt_newline}):)"

I think that looks reasonable.

>     if [[ ${TERM-} == dumb ]]; then
>         PROMPT="$p_exit\${debian_chroot:+(\$debian_chroot)}%n@%m $p_pwd"
>         PROMPT+="$p_space_or_newline$p_vcsinfo$p_reset$p_2nd_newline%# "
>     else
>         # 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.

>
>         PROMPT="%B%{%0(#:%F{$exitcolor_root}:%F{$exitcolor})%}$p_exit"
>         PROMPT+="%{%F{$dircolor}%}\${debian_chroot:+(}"
>         PROMPT+="%{%0(#:%F{$usercolor_root}:%F{$usercolor})%}\${debian_chroot-}"
>         PROMPT+="%{%F{$dircolor}%}\${debian_chroot:+)}"
>         PROMPT+="%{%0(#:%F{$usercolor_root}:%F{$usercolor})%}%n@%m "
>         PROMPT+="%{%F{$dircolor}%}$p_pwd%b%f"
>         PROMPT+="$p_space_or_newline$p_vcsinfo$p_reset$p_2nd_newline%B%#%b "

Assembling a non-trivial prompt like always looks unreadable. I've seen
worse than this.

>         ##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.

>         #PS2='${${options[singlelinezle]#off}:+%_> }'

I'd do this in an "if ...; then...; fi" to improve readability.

>         #RPS2=${RPS2:-"%B<%{%F{$rps2color}%}%^%f%b"}

[...]
>     # Autoload and configure vcs_info:
>     # The format strings 'formats' and 'actionformats' should end with a space
>     # to fit into the prompt's design.
>     # Colors: 1:=red, 2:=green, 3:=yellow, 4:=blue, 5:=magenta, 6:=cyan, ...

Again, you can use the colour names instead of the numbers instead.

[...]

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


Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



More information about the Pkg-zsh-devel mailing list