From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31445 invoked from network); 15 Apr 2021 11:11:35 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Apr 2021 11:11:35 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618485095; b=pLdtpmsfWtOJBQX3DSho4pNtydrJVU6kCUYLdkTZEhVLkZzd12aBpXyQIRCxCl5hQ3E+4lzuJr zmfoG9HfXh3RdUgyxGxpZyhnzWukKdij8rQmihqsb+r6rhpg4rv9HyS2bAU7e8kG2n949VL5Kl B+s2lj8BFAolF4GoGXaaGD0EaTYp/v0nK/jEUY69gtcv76wUZNsUudokmG0NgpPBtOpSwXfcmZ vivHT6MR1gnhbvY+dE4YI9nkJ80XXdcbstbVUywN1EYB/BKxzF8qSfL394feGHIMwIN6RVMVrN l/glsDnzd+118zVZQrydZxJpH2G1tQS+FhFfD0k5jB0pjQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1618485095; bh=NAePWiEaRyDXcZ/GKDuJ0PQ33RH1VsaTUu0mZlhO77s=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature: DKIM-Signature; b=nCOnJEwPMejRAezj5reuSJZ0gYSd9u4JbxLYgX+3FL0A3V4mOj6gpbVbjilBvgTLO9MzJLKfEn gBOfgtRADUzju2aETugiqN8g+eEnQ+SRJAI6fng4YghxwXLJ7CwUPlnS0QmeJQkAD+fkvKpS7G FVd0JROMHd4sRwbeL66jOF/UTPy+o3eWiLdU6YKYNM/kLkDftb0baUTVxnYCKAXs3VmXQXRhhx 7l0TN4OBu2ti6IHy6c2TARi23Il4MOWP8Eb4z+VPI+wKj5djJQokjrQHS/p+XxQSsac3S6+CrW ghIGCUx9A2DbDrfMaMLarRRzoz1Omxh6ZGrKQf9LxhzlnA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=fMRO5uTzbPZZAqS6Sc7uLaRbBM3UrBWEPFIQtMMQivo=; b=Tvri7QwkwNYgMrIH7ahY3L6Mcl jG209DTgMyzXRjrOM3L1B6kobFHLXcWNSlGS0ZNkGJURGJCYAbkTJrXU6n+wR6lA2STxjMXLe+12D j6h5aygAE8vi8cmMNDh0n9lC1IMHN+fBv1uH002pOAfHkFU3OxrU2EvxZ4o45hZFULbE87lxNnG5h U3R2VETpV5uxu4vUcQTSK5QV6WV4LUgjtQA11rwY3Vas1YVdG063xIRMGsmOTsSOZ7GKorEWcdwsd nHOMLRkobe5bGVUoMMIF3gip9yGyG6MdaD74N2nkdGzbGkmm0CnHyqYGWJBa2xrEjt7cYVQm+jbWo xVTcogvg==; Received: from authenticated user by zero.zsh.org with local id 1lWzuJ-0003aI-BZ; Thu, 15 Apr 2021 11:11:35 +0000 Authentication-Results: zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-io1-f54.google.com ([209.85.166.54]:44772) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lWzu3-0003M5-3y; Thu, 15 Apr 2021 11:11:20 +0000 Received: by mail-io1-f54.google.com with SMTP id p8so2428549iol.11 for ; Thu, 15 Apr 2021 04:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=fMRO5uTzbPZZAqS6Sc7uLaRbBM3UrBWEPFIQtMMQivo=; b=rI5VMVtuxDQXbJcv8m+W39tx3d1N3XFFcomfqZ8mr+KEm+YbLdq3a63MBalBuOyVqg xYmNNqoKis/z5fREQf3jR6b5CM2yrCceyfBwBr3QxxIwIHFMsldZwzBBXF44dxsvqHGw Hw+T8J7G2rUn6QAyPehB8kIYFVU1WWKudj8+ZjUVz2VTkVKKDc1Yje5C1QDas15G/b8q 1twtiI78OrITWgXCenDZHGu/RiHkapEsUKPcJnk3zfnyi1R4CVPaLQqUF4ITDNmWLekW 0Qoi2I+nhoTigQ1KyQryHFsFPsvX0Kh1VKNEdCrhdnSfbzlMLIKrQfAliRY/ySlbcDJF FvhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=fMRO5uTzbPZZAqS6Sc7uLaRbBM3UrBWEPFIQtMMQivo=; b=Gie3tH8312lpOEmHGUhhLWN4O5guvqACzjUVo2BR10E5bbeRCeY948OuW7yfvBnp2b tKj9AoOKscE+4J12cquOnET++BmONGawE4USfEfCnu+0FCm3tsg4GorsGC8Z1wxvokWi 9m7HGUrzqyNa/r8fT+6IohZZr5HJd7ah1KDr8Mis2qLOfLiDhSTydrS48hHfq42VaBWQ 7AMChH93gmSx+8mdvbR/DvXYSl6ArwAm8wGphG86lMKw1CFh+kZNUfHU+no187G3Yldh xm+Ju6GFFYMNSXGgm+1D/2OS8NTdJPHzMftKYjOnj6b4subV0zooR3VsCB3o0uDzfDXo Bs8w== X-Gm-Message-State: AOAM533xdmDOzTI0iFzek/Nho7ztY59orEJbyxahK6Ey42VfDFq5D4P8 uH56zz/skNWK209nDcxslieE7HXXkizilyJIRrs= X-Google-Smtp-Source: ABdhPJwwBGmGcZm5M5+4DfMNah+slDtDOa650Uh88rbwhR5uUPgPvi6INjLCoybOsa20+CWA4pRKwt6RqX00Q0Sw7I4= X-Received: by 2002:a5e:db4b:: with SMTP id r11mr2195387iop.21.1618485078016; Thu, 15 Apr 2021 04:11:18 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:cc46:0:0:0:0:0 with HTTP; Thu, 15 Apr 2021 04:11:16 -0700 (PDT) In-Reply-To: <20210414140909.GG3882@tarpaulin.shahaf.local2> References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@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> From: Mikael Magnusson Date: Thu, 15 Apr 2021 13:11:16 +0200 Message-ID: Subject: Re: [RFC][PATCH] `newuser` prompt theme To: Daniel Shahaf Cc: Marlon , Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 48586 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: [only vcs_info] On 4/14/21, Daniel Shahaf wrote: > Marlon wrote on Wed, Apr 14, 2021 at 16:17:02 +0300: >> On 14 Apr 2021, at 15:05, Daniel Shahaf 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 theme= s >> > should be doing that. >> >> Please show me another way to theme the VCS part of the prompt and I wil= l >> 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 =C2=AB:vcs_inf= o*=C2=BB, > 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=3D( cr percent sp ) >> >> + >> >> + zstyle -e ':vcs_info:*' formats ' >> >> + reply=3D( "%u%c$( prompt_newuser_format start branch repo )" ) >> >> + ' >> >> + zstyle -e ':vcs_info:*' actionformats ' >> >> + reply=3D( "%u%c$( prompt_newuser_format start action repo )" ) >> >> + ' >> >> + zstyle -e ':vcs_info:*' stagedstr ' >> >> + reply=3D( "$( prompt_newuser_format start staged )" ) >> >> + ' >> >> + zstyle -e ':vcs_info:*' unstagedstr ' >> >> + reply=3D( "$( 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=E2=80=99, 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]=3D( "${vcs_info_msg_0_:-}" ) psvar[4]=3D( "${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). --=20 Mikael Magnusson