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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27672 invoked from network); 14 Apr 2021 12:06:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Apr 2021 12:06:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618401982; b=Rlk6+sj2tTLg7W5eHjZPCTIXOhZFPU6LwLUWwD4ePWNLpZGhfDbx8rpOAd9q1y3jlLFeJLtKwN 3ggZjSUi53Syub2jtCFMPD1BznmsZ/2k1CNK2/lwcyxL3C5quBmIw/XjvhtWkyXnXhen2m0Q8X NTLfrKU3TEQ0e0Lw4EYZ/nM5JNd0TA+DPw3cLmjuhM1TDBgkgrLJiztWjKfjvn4NcYt96roIVn ye+WLTTVZA8DFrQqBp72ANGoDo36yEU42zbkRWwbu0hc24nv0+Z/R/DJL6TS6yzUR1/vMyf0Y3 q+4qdPiMrWCMTPyOA1v9wtSSXqdMRueZ8O5GdaVMWFlnwA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.20; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1618401982; bh=ysy/tRC6czAs8YWBAiwgYe3ve1kpvLFzalkDisiET1U=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=HaZcucRGjsSxb08JlNUEdDnKCd19jNj5o0SulfKe+9WpQCNb7fGG/zH/BeeUQIaS35F0sgqoB/ /N+b3XVe41kNCNotWSpYGGnkZZ1QFFQv4D1x902X1iWB3U3kzacfs1EkbkTHmKwY1FN8EPiYjz AL1weyT7nQ/xepB8Fbw7MQRJ2ffSL8pHxy8fvltQfzt0neWbKtyHc+re0YpX/0mXHXT5TX2K1n RFtjYr0CIHhZg6bYqgbLkSE2T/oMAqsKddcsmwWp/VwiMZa4avYw4n0uGnCWRMQ+zseNEHnm7S e/QJhZc8Nl/Ueom1VKt/D+Kptmo0lPIOrLB5vdpsZu6wpQ==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=91ow/Ph/1fP3PK+IPouZQ1OdwDnL6r/yDx6VqKeEgNk=; b=Sx3YQ95ueMX+npzy0aP4SLQSjf 224JPkpfmCINZX+Kt0MIvpBtiBXrxTsCjw2VOB7KjTbPcO8d2YP7tZP7rwhv9qsqv8kPOuMHRA1Et VFuNHTgkUQRYlZ1htT9ZPYGI5oonlh9JhPVZAyav6+wao3mPkzHg9QKDtpFRyr8hU3Qt2xgJNKWUd 3zeyHTEyVBQ80Y+iXlBi5N8sxhvIo+BM6HASybSzBxqDACF8BQnWsiGfxwLUfKM+3cpfHaFyZgZAY pHSuBStnpsb1usQeiD5stv8fpYq3nP4U2SZsZuGn1tCxdXA0LkngJZOLODwoi3bsnd0UNWrU2OM/9 QdDQMCtA==; Received: from authenticated user by zero.zsh.org with local id 1lWeHl-000PY5-LE; Wed, 14 Apr 2021 12:06:21 +0000 Authentication-Results: zsh.org; iprev=pass (wout4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.20; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:57729) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lWeHT-000PJ7-7G; Wed, 14 Apr 2021 12:06:04 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id CF07F12DF; Wed, 14 Apr 2021 08:05:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 14 Apr 2021 08:05:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm3; bh=91ow/Ph/1fP3PK+IPouZQ1OdwDnL6r/yDx6VqKeE gNk=; b=E4GkzUSeGblpmMaBfUUWMlGwqz3MoIUYUYOCeljjfjqSc2RvpW0vF2v5 YdqSkWg5hYnRxNILVO+J/44YDnPioF7eF2Pe+9rArAbZzjEIS4XwZ1R4HR2z04RM Fox5otKDxVXvJDAkV8aRLEVyrsAs4+zwircQQdCmKhnDa1Yt9Rcnue0L2FdR5rMy Ew9587flPpAlsnuwYdavEHTCnMvLrKv1lPktXRexLlxg02wyg0DOhAWn6ODK20+N DANfnaA6WgDSth7U2YCEOfUpmZYWslrHXTTqOZYzpKWAsaOLDCoac9rmFe93xDBM 5L8pP+DyVA85yAcY9ooQxrxl8wdb2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=91ow/Ph/1fP3PK+IPouZQ1OdwDnL6r/yDx6VqKeEg Nk=; b=mgGk9EZRkLchASEgeQ5ENZmulPHBhj5mC/ZUq44klfPxjmBbSoIN+m7wq 8t8AYDIKVo+Ll8gSpmYSLth8+d0SEofXoWzmFK+WteWlw39xvaMntoU/pmezBftS uFEdLPkFRYWDJYrK/OZVZTia7fj5NXuwUT7sFi403ivcDjXFjk8bcI6qbI8L5Dbi kCcCFXLnKDifvgrtVhePsAHj8BJUWxv6x8MJFibBDN9V1nbNXW9IzSb9zSOAXZF7 b3wvc1vJjcpWcTbfagXqVgDslNg87I2K8YlAHxR3ENhzUoWJoPFf7IyWOQFRWFLu S/L4MlmVdQ3twcoLT4T0ASv6DTZ2Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeluddggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggugfgjfgesth ektddttderjeenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhepueejuefgudeile ejgfehleefvdevheehleduffefudetudehgeefvdfhieeihfevnecuffhomhgrihhnpeii shhhrdhorhhgnecukfhppedutdelrdeiiedrieefrddvfedtnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgr hhgrfhdrnhgrmhgv X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-109-66-63-230.red.bezeqint.net [109.66.63.230]) by mail.messagingengine.com (Postfix) with ESMTPA id DF735240054; Wed, 14 Apr 2021 08:05:54 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4FL1QS0Dvtz43s; Wed, 14 Apr 2021 12:05:51 +0000 (UTC) Date: Wed, 14 Apr 2021 12:05:51 +0000 From: Daniel Shahaf To: Marlon Cc: Zsh hackers list Subject: Re: [RFC][PATCH] `newuser` prompt theme Message-ID: <20210414120551.GA3882@tarpaulin.shahaf.local2> References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48564 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: > new file mode 100644 > +++ b/Functions/Prompts/prompt_newuser_setup At the risk of bikeshedding, I don't think that's a good name. A name should describe what a thing *is*, not what its intended use is; and I'm not particularly fond of the implication that new users should be wary of trying _other_ themes. Besides, what if someone else were to come along and post an alternative theme aimed at new users? > @@ -0,0 +1,197 @@ > +readonly -ga sysexits=( > + USAGE ⋮ > + CONFIG Two interrelated scripts on zsh.org hardcode these constants too. I wonder if we should provide these constants in a standard autoloaded function or preset variable. > +prompt_newuser_precmd() { > + local exitstatus=$? It's not documented that precmd hooks can rely on $? to be the exit code of the last command. That does work, though (because callhookfunc() calls doshfunc(noreturnval=1)), and seems useful, and I guess we won't want to change it, so shall we document it? > + emulate -L zsh > + > + psvar[1]= > + case $exitstatus in > + <128-> ) > + psvar[1]="SIG$signals[exitstatus-127] " > + ;| > + <64-78> ) > + psvar[1]="EX_$sysexits[exitstatus-63] " Nice, I might adopt this. Or, come to think of it, I might teach PRINT_EXIT_VALUE to do this ☺ > + ;| > + <1-> ) > + psvar[1]+="($exitstatus)" > + esac > + > + 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. 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. Also, there are literally zero comments in the code. That makes it rather unmaintainable by anyone other than you — and I wonder if I shouldn't say "other than present-you", since future-you may not fare any better than present-me at understanding the code without comments. > + vcs_info > + if [[ -n $vcs_info_msg_0_ ]]; then > + RPS1="$vcs_info_msg_0_" > + else > + RPS1="$( prompt_newuser_format start right )" > + fi > + fi > +} > + > +prompt_newuser_line-init() { > + emulate -L zsh > + > + case $CONTEXT in > + start ) Nitpick, but could we please use both parentheses in new code? That helps my $EDITOR's jump-to-matching-paren functionality happier. > +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. That appears to be NIH. Why shouldn't the theme just advise people to set the vcs_info directly? > +prompt_newuser_setup "$@" Sorry, but I'm not at all sure I support accepting this part of the patch. More below. > +++ b/Functions/Prompts/promptinit > @@ -178,8 +177,13 @@ Use prompt -h for help on specific themes.' > > # Reset some commonly altered bits to the default > local hook > - for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do > - add-zsh-hook -D "${hook}" "prompt_*_${hook}" > + for hook in chpwd precmd preexec periodic zshaddhistory zshexit \ > + zsh_directory_name; do > + add-zsh-hook -D "$hook" "prompt_*_$hook" > + done > + for hook in isearch-exit isearch-update line-pre-redraw line-init \ > + line-finish history-line-set keymap-select; do > + add-zle-hook-widget -D "$hook" "prompt_*_$hook" All these should be documented, like prompt_${foo}_preview is. Recommend to name these prompt_${foo}_bar-{isearch-exit,isearch-update,…,keymap-select} for some fixed value of «bar» to avoid namespace issues (i.e., name collisions between existing prompts and future hooks). The promptinit changes are independent of the new theme. They should be a separate patch and could conceivably be applied separately.