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 17132 invoked from network); 14 Apr 2021 05:45:45 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Apr 2021 05:45:45 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618379145; b=rLNvgIYMwOlFFfnfp7PKnbxXS7/VxPyrfZIe2yRwusLxgZx9ioW7bXYcBKj5AM4SQDk2xRBQ+T Ahd2P7BOrEnR3nWWBAjbgw6BBtjoz5vZPJOGYpycSUtmeq0wnjval8Y1nfcsMWb25NrRW3YzrN 9E0Cvl3g4W2WD1nedwFZIc3B3C88es4hCeG1QC+qtqgGUsn+umg1IPFJOsYyK/ERkwM7/dCb5t seZh01svhH2z+eEhr8W6fcdDYTiY1D0Y+ZJVYtGIjpDZqeYfrUOBDL+1e/SFNnK9zXtN6mtQ14 2w5O/NuBlzCsf3HzwA0q4SR/vcugvsmTBIikE7e5mhYN9A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f47.google.com) smtp.remote-ip=209.85.167.47; 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=1618379145; bh=YbE2BzAsw8hv+s/mTtyhxWpQnWW11NK8XjrEKi16OzM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:References:To:Cc:In-Reply-To:Date:Subject:MIME-Version: Content-Type:Message-ID:From:DKIM-Signature:DKIM-Signature; b=PTCM8RXiV13NdtZietr6yAR3CxI5r/7wOVgVBXqWLFPLWlaQTB74/1lYHC/kk6uiPa/Dm+Iaik 5UOm6NRbuzNdBBhbyn7ylF48es0ArJx+yvmJRUntBPg/aP0bpeZZD7MwDUm+uk4cdAsvzS0i2w tVnOLD0q6EWKRXSp2VpCDfGTf8MCDgiuCAD263t0R5FmVLWo3iy9WIyDAYWtr4LhEUwNmK/WK1 //DMfmd621e7ssBk4s9uID7QKr8JvdFPy0JsHl8SrtPKLkp0tvg+PvgVeRbElSPi/PG6lyQvmY Q2y4Q7rbe1FcpdmWhvsIrAWNpSijP+z1gXnEZqZVbdGvow==; 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:References:To:Cc:In-Reply-To:Date: Subject:Mime-Version:Content-Type:Message-Id:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=07QXa1aSiYgkhTnVCq08Fx/ZI/S1ubJKVsIaFuSIVJU=; b=F45SoqYttkry8CF0jCUMnYFygB k1f74Zek8fsfUtihwIUld8qH/OpWD7ZC7KAtagNeJhYQr7WYo7M2ml0lc/OH/E24aDpcSlanNq6bf OKf77jQuoJFFkHx4PXN9lifNU4PZPx7dHNKsGTcRcI+SIi0RdHHoR+5QeQcwI3/jYPGwVzRIneeqX MNJv94nxtTUxgNllp8I3qGdljD9u/Fqw/p+be16aYqvTj/e/1KdzlTYGVC8vBaXDRSHffNnLlkrCP /Cvr1bXiGiC3l81LxVZyb5KMoAdnNFmNkYbzKGe3Jbn+2u0cWm88epXNcG5vDz91cEdWEESkblEgX zR0yVytw==; Received: from authenticated user by zero.zsh.org with local id 1lWYLR-000C7v-5v; Wed, 14 Apr 2021 05:45:45 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f47.google.com) smtp.remote-ip=209.85.167.47; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f47.google.com ([209.85.167.47]:44562) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lWYKv-000BtA-SQ; Wed, 14 Apr 2021 05:45:14 +0000 Received: by mail-lf1-f47.google.com with SMTP id e14so18372798lfn.11 for ; Tue, 13 Apr 2021 22:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=07QXa1aSiYgkhTnVCq08Fx/ZI/S1ubJKVsIaFuSIVJU=; b=XVKtcmiITrgsRlAwHtrg1zNdJGa493KZ0rGKp5gRrv/4l6wJZL2XsqHxIlQxlVfZOe OFyV34DrawmzbD5ryATLx+CjDyvKBg2nXioZ62Amk/FuIejI5+QAF9nx+a2KzcNdPKDx DW9OFWpqYd4isRFeAdYmUAxjlllbqMZvjAZns+EKW5YNT5D+euxgewAAtGswcI4N9ILZ Sdk5eKqKSpUJeA8ZWuBjVYedQMoDq7++5wyOGQXiy2Au3MtCnK1pMuFMKd6d3E++Bgue vWqRBEFd9afO4pzlBBCRIvBrqSPkOqfGlCNKfW1A6FleIzqBIS3AJglT2qpSP714+SCf etaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=07QXa1aSiYgkhTnVCq08Fx/ZI/S1ubJKVsIaFuSIVJU=; b=DQkla5wHCFHrHyszpxcNb9KgjWGxWfp3AFjlUD6ITafoeMEipkCh7O0+hMwsqMZvoF XHPaN0W4106uzQksy51XzlfO2LEvHFhM5xpOvw3ozL2mC98gsshFQxL/FyZtv6QjFSVC Gd3imIlZhSGaLLybR5t0Xx+jf9M8yLAFpein318pxtDb99XPmcTRhf7ctHYO9mftUcjJ oMB1eaSKc7c28PGXcu6Bk7ux6F8gYNT9B8U6VDHQWWgmoU7i9pmrORU8QRjNsbBKL5mq 1U0OhAl+FweZNVE334RaHIiw353LJMrUv2F85LS2XUWr8gBXhS2cgtbIpIbDF0aMCUJM 2JEQ== X-Gm-Message-State: AOAM531OQ4GVcDZncoL2yDimoajngTaHYjcMKWPc48pHj7JsX0scBolc hOCKkuP+OKQF9ea8cOwC51c= X-Google-Smtp-Source: ABdhPJwmNlaIgWcsvFoRyw5MvIjjkN57fJXIkpxGa8+aKPmR2DEwt0BKYumLX8A/wFltmOqo7u7r0A== X-Received: by 2002:a05:6512:234c:: with SMTP id p12mr10021837lfu.45.1618379113352; Tue, 13 Apr 2021 22:45:13 -0700 (PDT) Received: from [192.168.1.15] (hag-tkubng22-50df3e-132.dhcp.inet.fi. [80.223.62.132]) by smtp.gmail.com with ESMTPSA id y6sm2561291lfl.25.2021.04.13.22.45.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Apr 2021 22:45:12 -0700 (PDT) From: Marlon Message-Id: <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_05C1B2E7-DEF0-477B-BC57-063687C2997B" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [RFC][PATCH] `newuser` prompt theme Date: Wed, 14 Apr 2021 08:45:11 +0300 In-Reply-To: Cc: Zsh hackers list To: Bart Schaefer References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48559 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: --Apple-Mail=_05C1B2E7-DEF0-477B-BC57-063687C2997B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On 14 Apr 2021, at 08:17, Bart Schaefer = wrote: >=20 > On Tue, Apr 13, 2021 at 10:09 PM Marlon Richert > wrote: >>=20 >>> On 13 Apr 2021, at 23:45, Bart Schaefer = wrote: >>>=20 >>> Is it possible to do that without the massive re-indent of the >>> existing "case" branches? >>=20 >> Sure. The original indent was an odd number of spaces, though. I = thought that didn=E2=80=99t fit the style guide/code conventions? >=20 > Possibly, but we prefer to keep functional changes separate from > whitespace changes for semantic clarity. OK, here=E2=80=99s the patch without the reindent. See attachment. --Apple-Mail=_05C1B2E7-DEF0-477B-BC57-063687C2997B Content-Disposition: attachment; filename=0001-Add-newuser-prompt-theme.txt Content-Type: text/plain; x-unix-mode=0644; name="0001-Add-newuser-prompt-theme.txt" Content-Transfer-Encoding: quoted-printable =46rom 86bffc40bdd3676e4f90b8604e68356799fd6e63 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Wed, 14 Apr 2021 08:39:51 +0300 Subject: [PATCH] Add `newuser` prompt theme --- Functions/Prompts/prompt_newuser_setup | 197 +++++++++++++++++++++++++ Functions/Prompts/promptinit | 14 +- 2 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 Functions/Prompts/prompt_newuser_setup diff --git a/Functions/Prompts/prompt_newuser_setup = b/Functions/Prompts/prompt_newuser_setup new file mode 100644 index 000000000..a4167a8c8 --- /dev/null +++ b/Functions/Prompts/prompt_newuser_setup @@ -0,0 +1,197 @@ +autoload -Uz add-zle-hook-widget add-zsh-hook vcs_info +readonly -gHA _prompt_newuser_formats=3D( + start:chpwd $'\n%B%F{blue}%~%b%f/\n' + start:left $'%(?,%F{green},%F{red}%v%k\n%B%S)%#%b%f%s ' + start:right '%B%F{blue}%n%b%f%k@%F{magenta}%m%f' + start:staged '%B%F{green}+%b%f' + start:unstaged '%B%F{red}*%b%f' + start:action '%B%F{red}%a%%b%f' + start:branch '%B%F{cyan}%b%%b%f' + start:repo '|%B%F{blue}%r%%b%f' + cont:indent ' ' + cont:left '' + cont:right '%F{red}%^%f' +) +readonly -ga sysexits=3D( + USAGE + DATAERR + NOINPUT + NOUSER + NOHOST + UNAVAILABLE + SOFTWARE + OSERR + OSFILE + CANTCREAT + IOERR + TEMPFAIL + PROTOCOL + NOPERM + CONFIG +) + +prompt_newuser_help() { + print -r -- \ +"To customize your prompt, copy-paste any of the following to your = .zshrc file +and edit it in there: + + # Start prompt: + zstyle ':prompt:*:start' left = ${(q+)_prompt_newuser_formats[start:left]} + zstyle ':prompt:*:start' right = ${(q+)_prompt_newuser_formats[start:right]} + + # Prepended to left side of start prompt if we changed dirs: + zstyle ':prompt:*:start' chpwd = ${(q+)_prompt_newuser_formats[start:chpwd]} + + # Replaces right side of start prompt when in a repo: + zstyle ':prompt:*:start' unstaged = ${(q+)_prompt_newuser_formats[start:unstaged]} + zstyle ':prompt:*:start' staged = ${(q+)_prompt_newuser_formats[start:staged]} + zstyle ':prompt:*:start' branch = ${(q+)_prompt_newuser_formats[start:branch]} + zstyle ':prompt:*:start' action = ${(q+)_prompt_newuser_formats[start:action]} + zstyle ':prompt:*:start' repo = ${(q+)_prompt_newuser_formats[start:repo]} + + # Continuation prompt: + zstyle ':prompt:*:cont' left = ${(q+)_prompt_newuser_formats[cont:left]} + zstyle ':prompt:*:cont' right = ${(q+)_prompt_newuser_formats[cont:right]} + + # Used to indent left side of continuation prompt: + zstyle ':prompt:*:cont' indent = ${(q+)_prompt_newuser_formats[cont:indent]} + +For an explanation of the % codes, see +http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html and the = end of = +http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#vcs_005fin= fo-Configuration" +} + +prompt_newuser_format() { + local ctx=3D$1 arg fmt out + shift + for arg; do + zstyle -s :prompt:newuser:$ctx $arg fmt || + fmt=3D"$_prompt_newuser_formats[${ctx}:$arg]" + out+=3D"$fmt" + done + print -r -- "$out" +} + +prompt_newuser_chpwd() { + emulate -L zsh + unset vcs_info_msg_0_ + PS1=3D"$( prompt_newuser_format start chpwd left )" +} + +prompt_newuser_precmd() { + local exitstatus=3D$? + emulate -L zsh + + psvar[1]=3D + case $exitstatus in + <128-> ) + psvar[1]=3D"SIG$signals[exitstatus-127] " + ;| + <64-78> ) + psvar[1]=3D"EX_$sysexits[exitstatus-63] " + ;| + <1-> ) + psvar[1]+=3D"($exitstatus)" + esac + + if ! [[ -v vcs_info_msg_0_ ]]; then + zstyle ':vcs_info:*' check-for-staged-changes yes + vcs_info + if [[ -n $vcs_info_msg_0_ ]]; then + RPS1=3D"$vcs_info_msg_0_" + else + RPS1=3D"$( prompt_newuser_format start right )" + fi + fi +} + +prompt_newuser_line-init() { + emulate -L zsh + + case $CONTEXT in + start ) + local -i fd=3D-1 + exec {fd}< <( + zstyle ':vcs_info:*' check-for-changes yes + vcs_info + print -rNC1 -- "$PWD" "${vcs_info_msg_0_}" + ) + zle -Fw "$fd" prompt_newuser_async + ;; + cont ) + local fmt=3D"$( prompt_newuser_format cont indent )" + local -a indent=3D( '%('{1..$(( COLUMNS / ${(m)#fmt} = ))}"_,$fmt,)" ) + PS2=3D"${(j::)indent}$( prompt_newuser_format cont left )" + RPS2=3D"$( prompt_newuser_format cont right )" + ;; + esac +} + +prompt_newuser_async() { + emulate -L zsh + { + zle -F "$1" + + [[ $2 !=3D (|hup) ]] && + return + + () { + local pwd null + IFS=3D$'\0' read -ru "$1" pwd vcs_info_msg_0_ null + + [[ $pwd =3D=3D $PWD ]] + } "$@" || return + + if [[ -n $vcs_info_msg_0_ ]]; then + RPS1=3D"$vcs_info_msg_0_" + else + RPS1=3D"$( prompt_newuser_format start right )" + fi + zle .reset-prompt + + } always { + exec {1}<&- + } +} + +prompt_newuser_line-finish() { + emulate -L zsh + PS1=3D"$( prompt_newuser_format start left )" +} + +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 )" ) + ' + PS4=3D$'# ?=3D%(?,%F{green},%B%F{red}%S)%?%b%f%s e=3D%e = %F{green}%1N%f:%I %(1_,%F{yellow}%K{black}%_%f%k ,)' + SPROMPT=3D'Correct %B%F{red}%U%R%b%f%u to %B%F{green}%r%b%f? = [%Sy%ses|%Sn%so|%Se%sdit|%Sa%sbort] ' + PROMPT_EOL_MARK=3D'%S%F{cyan}%#%s%f' + zle_highlight=3D( + isearch:fg=3Dblack,bg=3Dyellow + special:fg=3Dcyan,bold + region:bg=3Dblue + suffix:bg=3Dblue + paste:none + ) + zle -N prompt_newuser_async + + add-zsh-hook chpwd prompt_newuser_chpwd + add-zsh-hook precmd prompt_newuser_precmd + add-zle-hook-widget line-init prompt_newuser_line-init + add-zle-hook-widget line-finish prompt_newuser_line-finish + + prompt_newuser_chpwd +} + +prompt_newuser_setup "$@" diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 37d69f100..b9d833c4b 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -14,6 +14,8 @@ prompt_themes=3D() promptinit () { emulate -L zsh setopt extendedglob + autoload -Uz add-zsh-hook add-zle-hook-widget + local ppath=3D'' name theme local -a match mbegin mend =20 @@ -32,9 +34,6 @@ promptinit () { fi done =20 - # To manipulate precmd and preexec hooks... - autoload -Uz add-zsh-hook - # Variables common to all prompt styles prompt_newline=3D$'\n%{\r%}' } @@ -178,8 +177,13 @@ Use prompt -h for help on specific themes.' =20 # 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" done typeset -ga zle_highlight=3D( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight --=20 2.31.1 --Apple-Mail=_05C1B2E7-DEF0-477B-BC57-063687C2997B--