Hi,
there is an additional, related, bug report in this one. The actual bug
report starts below the three dashes.
If I use the color-enabling "zstyle ':vcs_info:*' formats" string from
zshcontrib(1), it does not only add colors, but also slightly modifies
the format. In the example below, a space is removed and a minus is
replaced with a space. I would expect that such an documented example
format only modifies the colors - but YMMV.
~% setopt prompt_percent prompt_subst
~% autoload -Uz add-zsh-hook vcs_info
~% add-zsh-hook precmd vcs_info
~% PROMPT='%~$vcs_info_msg_0_%# '
~% cd gittest
~/gittest (git)-[master]-% zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
~/gittest(git)-[master] %
The above format string without the trailing space is used (if
uncommented) in the improved newuser.zshrc.recommended and I think at
least in this file should a format string be used that only adds colors
and changes nothing else. OTOH, I think the default trailing minus does
not make that much sense, but I also assume that it won't be removed.
Anyway this detail of the improved newuser.zshrc.recommended can still
be changed in future.
The same possible documentation issue might, or might not, apply to the
example actionformats and branchformat strings.
It would be great if there would be a way to get a colorful vcs_info
without copying around (or alternatively, understanding) format strings;
for example running vcs_info --setup-only --enable-colors could set up
colorful format strings, but not execute vcs_info's vcs foo. Such
options could be used in the improved newuser.zshrc.recommended. The
obvious generalisation of --enable-colors is adding support for themes
that can be enabled via command line option.
---
Clint did a great job with his newuser.zshrc.recommended, he even added
proper integration into zsh upstream and added instructions for
inexperienced users (Hit TAB ...). Anyway, there are still some small
issues that could be fixed and things that could be improved (I might
have missed to list some things I changed):
* On white terminals, the recommended prompt for new users looks like
the broken hourly cron syslog entry - both contain three characters
equivalent to spaces in a row. The obvious fix for the prompt is
not using white text on white background.
* On white terminals, default foreground color on blue background is
suboptimal too, white on blue is way better.
* There is no (non-insane) way to add vcs_info to the used adam1
prompt.
* debian_chroot support is missing and can't easily be added to the
used prompt either.
* An exit code != 0 is not displayed, but IMHO this is useful. There
are two common ways how this is done, either added to the prompt in
some way, or using printexitvalue (known from tcsh) - I prefer the
latter.
* Menu select is only enabled if there are a lot of matches, I first
assumed that this might be a bug, but it looks like this was done by
intension. I agree that it is more useful if there are a lot of
matches, but it is still useful otherwise; and either always
enabling or always disabling this feature makes zsh feel more
consistent.
* A completion with _correct and _approximate might be useful for some
users and confuse others - presumably especially long time
unix/linux users, but also some new users don't expect their shell
to behave like a desktop word processor. I think such a feature
should be out-in.
* Some default aliases could be useful, at least ll seems to be used
all around. I also added h=history. l and la could be added too.
* The .zshrc could use a layout that is more consistent to itself and
zshall(1):
+ One comment line ends with a colon (I think I wrote this line),
the others don't.
+ History related options and history related variables should be
part of the same part of the file, but are split by bindkeys -e.
+ One comment is followed by an empty line, others don't.
+ zshall(1) writes option names with _ between the words, which
improves readability, and, if used the same way in a .zshrc,
eases searching for the option in the man page.
The two files can be found at:
http://stateful.de/~carsten/tmp/150717QVwIxjFQx9U/prompt_debian_setup
http://stateful.de/~carsten/tmp/150717QVwIxjFQx9U/newuser.zshrc.recommended
prompt_debian_setup should be submitted for inclusion in zsh after being
added to Debian's zsh.
The design and the source code of prompt_debian_setup was originally
based on prompt_adam1_setup and there might still be some lines from it.
Anything copyrightable (if there is something copyrightable in it at
all) in it that is not copied from prompt_adam1_setup is published under
the most liberal, public domain equivalent, license possible. On
request, I'll assign copyright to zsh's upstream. The changes I did to
newuser.zshrc.recommended are obviously not copyrightable - choose
a license of your choice if you disagree.
Since promptinit lacks a way to check if a prompt is available,
(( ${+prompt_themes[(r)debian]} )) is used to check this with a fallback to
adam1. After the next Debian release this line could be replaced with
"prompt debian".
actionformats and branchformat are missing in newuser.zshrc.recommended
since they would add clutter to it, and this .zshrc is not intended as
main .zshrc of people that need such things. vcs_info is also disabled
by default, which lowers the need to add these format strings.
There are different ways to use colors in zsh prompts, I randomly choose
one. This choice might be suboptimal and changing it might make sense.
The color foo that adds 255 or 256 aliases in a loop would presumably be
the wrong choice. I noticed that %b is not sufficient to end %K and %F
in a robust way.
2 vcs_info variables are used in PROMPT (since the default for
max-exports is 2), the second one might make sense as RPROMPT or
appended to the first one (i.e., remove the space with default
background). Knowing what the intension of this second variable is
might help to judge this.
All changes I made were done for a reason, even if they include "I don't
fully understand how KSH_ARRAYS influences zsh's parser" and "being set
-e safe can't be wrong". Please consider discussing additional changes
you might do before the initial commit in this bug report or on IRC.
Carsten
* Carsten Hey [2015-07-17 18:22 +0200]: c894f695cc02f16af429c7506bb78354dcd9a1e3 looks like the final PROMPT+= line in prompt_debian_setup could be replaced with this shorter one: PROMPT+='%(!:#:\$)%b%f%k '
If you add the attached files you do not read the other two mails :)
The attached prompt_debian_setup is updated all around:
* The prompt is not color-scheme-able anymore (the way all prompts do
it is ugly, and introducing a new way to do this is beyond the scope
of this bug report) - this also makes the funtion quite small.
* It now looks like adam1 on black terminals, but much better on light
terminals.
* $vcs_info_msg_1_ should not be part of $PROMPT, therefore I removed
it.
* Setting debian_chroot to '' disables displaying it.
* The help function is improved.
The h=history alias is removed from the attached newuser.zshrc.recommended.
Possible things to discuss after this file has been added to the package:
* dircolors:
- Use colored ls by default, i.e., use an according ls alias; or
at least make it easier to enable by adding "#alias ls='ls
--color=auto"?
- Should dircolors really be run w/o checking if it is available?
- Use ~/.dircolors if available?
* Add some additional aliases?
* Set the exit code of the most recent executed command to 0, i.e.,
run : at the end of the file (we use print_exit_value ...)?
* Use /etc/zsh_command_not_found is available, but only after this
package is updated?
A new prompt_debian_setup that no longer tries to mimic adam1 is attached. I think "#setopt no_beep" and "#stty -ixon" should also be added to newuser.zshrc.recommended, but maybe we should concentrate on the prompt for now.
Hi Carsten, I looked through the suggestions from your last mail; comments inline. Carsten Hey wrote: [...] The latter might better be replaced by zsh's "no_flow_control" option. [...] 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. Good! I like it when people refrain from polluting the global parameter name space just for prompt colours. This is good. :-) [...] Makes sense. [...] Maybe make these configurable via styles? I think that looks reasonable. 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. Assembling a non-trivial prompt like always looks unreadable. I've seen worse than this. I don't understand this. "transientrprompt" can — and IMO should be — set outside a prompt setup. I'd do this in an "if ...; then...; fi" to improve readability. [...] 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
[ 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]:
Indeed, setopt no_flow_control is much better.
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.
Hmm, even if * matches :, this could be changed to ':prompt:debian:*:*'
(one * for the host name and one for the user name).
At least for the examples shown in the help text %F{green} is much more
readable.
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.
"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.
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
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.
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
Hi,
I attached a new prompt_debian_setup and an RCS format diff between the
former one and this one.
The zstyle pattern now is :prompt:debian:${HOST-}:${USERNAME-}:${TERM-}:
in order to implement a variant of the suggested terminal blacklist in
future. The final : allows additional future extensions, if needed.
Additional configurable things would make the prompt more complex, thus
I skipped implementing them for now (the suggested ones and additional
ones can be implemented later). Franks other suggestions and some minor
changes are applied to the new prompt_debian_setup.
I think a recommended Debian .zshrc should also work on other systems,
at least in future releases of other Linux distributions. Therefore,
submitting this prompt_debian_setup upstream would be great, but only
a Debian zsh maintainer would be able to say "We plan to add this prompt
to the Debian zsh package and enable it in the recommended .zshrc for
new users. Please consider applying this patch.". According to the
channel topic, the zsh 5.0.9 release is expected to happen soonish.
Carsten
* Carsten Hey [2015-08-13 12:02 +0200]: Unconditionally using zstyle or other things available in zsh modules only does not make that much sense for the intended purpose ... I already adapted the vcs_info part of the prompt accordingly and will send a new version after I also updated the other parts. Regards Carsten