Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [RFC][PATCH] `newuser` prompt theme
- X-seq: zsh-workers 48586
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Cc: Marlon <marlon.richert@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [RFC][PATCH] `newuser` prompt theme
- Date: Thu, 15 Apr 2021 13:11:16 +0200
- Archived-at: <https://zsh.org/workers/48586>
- In-reply-to: <20210414140909.GG3882@tarpaulin.shahaf.local2>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7am=oS7FEpOOc=vUDLWN3iVQ8--ewqDOJLS2TheDag6TQ@mail.gmail.com> <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> <CAH+w=7ZBsfiJwC-PYBvOVgrgGmC4RTYt9rRroGiqo_rzVSBJHQ@mail.gmail.com> <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> <20210414120551.GA3882@tarpaulin.shahaf.local2> <6CEA4F3E-9A64-44E1-9121-FA9D5E053AB5@gmail.com> <20210414140909.GG3882@tarpaulin.shahaf.local2>
[only vcs_info]
On 4/14/21, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Marlon wrote on Wed, Apr 14, 2021 at 16:17:02 +0300:
>> On 14 Apr 2021, at 15:05, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>> >> +
>> >> + if ! [[ -v vcs_info_msg_0_ ]]; then
>> >> + zstyle ':vcs_info:*' check-for-staged-changes yes
>> >
>> > First, no other prompt theme sets styles, so I'm not sure prompt themes
>> > should be doing that.
>>
>> Please show me another way to theme the VCS part of the prompt and I will
>> use that.
>
> You seem to have checked your manners in at the door.
>
> In any case, what you've implemented is that you re-set a style on the
> first precmd after every chdir. I don't think these semantics should be
> implemented in the first place.
>
>> > Second, even if a prompt were to set styles, doing so in a precmd and
>> > behind what _looks_ like a "first run" condition but is actually a "we
>> > just changed directory" condition isn't exactly best practice.
>>
>> What would be a better practice?
>
> Don't surprise/mislead code readers.
>
> Don't surprise/mislead users.
>
> Document your code.
>
> 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).
>
> These are all such ground rules that I'm surprised I have to spell them
> out.
>
>> >> +prompt_newuser_setup() {
>> >> + prompt_opts=( cr percent sp )
>> >> +
>> >> + zstyle -e ':vcs_info:*' formats '
>> >> + reply=( "%u%c$( prompt_newuser_format start branch repo )" )
>> >> + '
>> >> + zstyle -e ':vcs_info:*' actionformats '
>> >> + reply=( "%u%c$( prompt_newuser_format start action repo )" )
>> >> + '
>> >> + zstyle -e ':vcs_info:*' stagedstr '
>> >> + reply=( "$( prompt_newuser_format start staged )" )
>> >> + '
>> >> + zstyle -e ':vcs_info:*' unstagedstr '
>> >> + reply=( "$( prompt_newuser_format start unstaged )" )
>> >> + '
>> >
>> > Your theme does _nothing_ with the 'unstaged' style other than
>> > pass it through verbatim.
>>
>> After setting it to '%B%F{red}*%b%f’, yes.
>>
>
> Hmm. That's a good question: how _should_ a theme set an overrideable
> default for stagedstr?
It's actually very easy to do so (somewhat pseudocodified actual code):
setup() {
zstyle ':vcs_info:*:prompt-mikachu:*' actionformats %b %a
zstyle ':vcs_info:*:prompt-mikachu:*' formats %b
zstyle ':vcs_info:*:prompt-mikachu:*' max-exports 2
zstyle ':vcs_info:(hg|svn):prompt-mikachu:*' formats '%b[%s]'
autoload -Uz vcs_info
}
precmd() {
local vcs_info_msg_{0..1}_
vcs_info prompt-mikachu
psvar[3]=( "${vcs_info_msg_0_:-}" )
psvar[4]=( "${vcs_info_msg_1_:-}" )
}
eg, the first argument to vcs_info is used as a context to look up
values of styles, so you can very easily namespace all your settings
to your theme. localing vcs_info_msg_*_ is also important so that you
don't interfere with any commandline usage of vcs_info (I didn't check
if you do this).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author