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 7830 invoked from network); 16 Apr 2021 16:04:56 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Apr 2021 16:04:56 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618589096; b=HrlJuwon1BuSKTSt35MixDK2ZG7hcXa8uK/pi7vkriqlBAbu5uyk0o0lKf9h0grMMebiBwY6sP FS3V6v5Obsuf+CBylgwK5StmzOCwUhEDPAavxyidyFYGJ/kXGL9FxWH8T08yZNyGEqUWsYJbQR KxMtT+RPfIKMO59zoFv8TqGbnZiIAx5R4aFVhmubcmEUleSbm4E1Y47YyNn+Ew+hJksDCNgn9R 6BqdYHj2hYk/C7OuuprIyo05RWYIXdu7KyaasLBEd1DNfqVEG7RjItAS0jovbLLmAyAUhOi713 G9JGCAjWT4R7qTj0YyKtFFbB8plq3mrg/qXZx0pHQeI2gQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f46.google.com) smtp.remote-ip=209.85.218.46; 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=1618589096; bh=vI49rNkbVQrMBwI7hvKs7L+NWJwoGdkWE/j4Lr6pzMo=; 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=zjNlvlcm5k3surBY7f3Fm3AqMEQCwD83jgfhUBYncp+SmxCis7JLcdfv7Ejx3ehocxfIV+Vaai sXPN80Dljl73s33vRFN0d+U/dQGTWVM9nIhYtO/MmLjbFfOmEJhBb6dXupvmcGJ8I4f99sweI+ eIYEBtTxWoHFzIPjxfiHFj8Byb0+qSbeo6HEhewT9XzfQLVucnZ90Jp1xjzAEphoihQbrn6Pj2 fm5aCvPuATcunG1pbrw5TK7ZLGQf9IqnxIb3heKOzhjnrFmtSa1bJtZqxyKVT9ZGYMsiUkrKuu QkgmQXaXMiysn6xK9ASfPeUUkFaWzvfdDewwdWvfole5IA==; 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=wOnQ0wBAbS+A4oJJcnUiK8VJGAPoe+JTvLmBOrmg1Og=; b=dFL6vkxo+gg/37Gq9PqBRviWoI hv9fxiQ39aCfETqnpJ8LglXqTrdUgQNwtXjdbWKTAxKefFTzuuEmnaqtxH9YmhzO+dwahiiCh2Ax+ 18kegmN0K9g04GqkZKIs6b0KFoYYJCbRrPMewmIu2+LglJrVtht9GVrSNG28yN7SxtMgb3UgtQhEg tAJXryPZJVx3idK24jYsIX6jKP4u+LCk6E1QMjdzMuDz3llDv1lfazviy941UGWIN58bDcdr+H1Dq thLwe5ZmACanZi+TDT64f1mHL88bAutBLl8BzG6nLvLx72w8ttVIM3EHrTzRr1PCqO4Ppqtj1L9TR pJP65OAg==; Received: from authenticated user by zero.zsh.org with local id 1lXQxk-0005Wv-0o; Fri, 16 Apr 2021 16:04:56 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f46.google.com) smtp.remote-ip=209.85.218.46; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ej1-f46.google.com ([209.85.218.46]:39861) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lXQx0-0005Hf-Ia; Fri, 16 Apr 2021 16:04:11 +0000 Received: by mail-ej1-f46.google.com with SMTP id v6so41589023ejo.6 for ; Fri, 16 Apr 2021 09:04:10 -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=wOnQ0wBAbS+A4oJJcnUiK8VJGAPoe+JTvLmBOrmg1Og=; b=MyhePnajygkxqxsDw3EwYcwprcQ+/M4FZhAZ3ZRQdlcs9k0KXRn8BaI4xkTRsV7fnL 5GPv+jf1ItiNdO+Z5x6o33beTwFAU+RlajxYaIrtzsqGrtwra74Mp5l32vP/FkAT2uUl WAyzXc7vUcblAydbUp0ZlBLOAG6Y+/yERD0MX3aDPonfuINgVJr5iPqRFM2AIk5pMaN2 pfB8v3FlqfYSUqni8fE5ku4aYlmXTKrFapQGb6UDEdglOvu6ZW73JZltB/QcfvMyDpof GF/j7eBVDmkMreFM7m44ywlzlMrHEXuIYUGmoCm36+iT69aMqL01q7S15HGjnNbutx2X 5HMA== 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=wOnQ0wBAbS+A4oJJcnUiK8VJGAPoe+JTvLmBOrmg1Og=; b=fzVqk6AT18N6MgnHiSpuyzgN/C94VRWo7XAVgJZNKo/q31z5vr10UGD0KlMGygP8Fx XkJJyIhK5n54GRrNdsyUaV9jPI1Q8sxO66dmjZEOohj50y1iXWcK4pF4PL6ZAZs/atdS +6kFTlH25fFi/mnC/vCfcwGXmBL2ynpLojaoXDA6W1lc7ICjtH6iG4kLGJCeQWz5X8VZ BSuXSaOpHCjXpBu1PdoVOZruM3NIDKIggsLTJfGgQ4NxfDtq4UZCNmx1NZbiNmr5XKog cQoTVKmiG70hPZyQSd/yLFwxJ+W3GO2eHEcU/Mk5hQUlgvrC8xhjcx91osgnPIcqOErE PEVQ== X-Gm-Message-State: AOAM532e+Xb0niLmY4yjew1Qov0EEEoW8Oi+XACRgCAb/2KU4wrTuoM0 Rq150iOIwLyk7WNRbZ9Cxfo= X-Google-Smtp-Source: ABdhPJwXCQ//WxlKUfsrhoGjtm74LhATKClmRrm7wd4BHrD/l1ghWToyAnlrL9sxZtgWjN/7reAhMA== X-Received: by 2002:a17:906:c08f:: with SMTP id f15mr9132980ejz.318.1618589049838; Fri, 16 Apr 2021 09:04:09 -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 i10sm5841881edt.3.2021.04.16.09.04.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Apr 2021 09:04:09 -0700 (PDT) From: Marlon Message-Id: <29E16F69-B09E-44BF-9009-1CF53053D4FC@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_232988C9-A9B4-49AD-81F4-5ED65D8ABEAE" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [RFC][PATCH] `newuser` prompt theme Date: Fri, 16 Apr 2021 19:04:06 +0300 In-Reply-To: Cc: Zsh hackers list , Mikael Magnusson , Bart Schaefer To: Daniel Shahaf 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> X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48599 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=_232988C9-A9B4-49AD-81F4-5ED65D8ABEAE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Alright, attached is a new attempt at this patch. Hopefully, this = version is more to your liking. Changes: * The primary prompt can now be configured completely through `zstyle = ':vcs_info:*:prompt_vcs:*=E2=80=99` statements. * Accordingly, I renamed the theme to `vcs`. (Naming is hard.) * I removed customization of the secondary prompt. * I removed the weird shenanigans with $vcs_info_msg_0_ between chpwd & = precmd. (I think I must=E2=80=99ve been tired when I originally wrote = that code. It makes no sense to me now.) * I added plenty of comments everywhere. My thanks to Daniel for his thorough review and to Bart & Mikael for = their zstyle/vcs_info tips. :) Question for Daniel: If you=E2=80=99re going to add sysexits(3) to = PRINT_EXIT_VALUE anyway (workers/48564), should I just get rid of = prompt_vcs_precmd()? Or do you think it still adds value? --Apple-Mail=_232988C9-A9B4-49AD-81F4-5ED65D8ABEAE Content-Disposition: attachment; filename=0001-Add-customizable-vcs-prompt-theme.txt Content-Type: text/plain; x-unix-mode=0644; name="0001-Add-customizable-vcs-prompt-theme.txt" Content-Transfer-Encoding: quoted-printable =46rom 172e2a886fcb499fd1f0712836721366dc66cb74 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Thu, 15 Apr 2021 23:28:56 +0300 Subject: [PATCH] Add customizable `vcs` prompt theme --- 0001-Add-customizable-vcs-prompt-theme.patch | 499 +++++++++++++++++++ Functions/Prompts/prompt_vcs_setup | 227 +++++++++ 2 files changed, 726 insertions(+) create mode 100644 0001-Add-customizable-vcs-prompt-theme.patch create mode 100644 Functions/Prompts/prompt_vcs_setup diff --git a/0001-Add-customizable-vcs-prompt-theme.patch = b/0001-Add-customizable-vcs-prompt-theme.patch new file mode 100644 index 000000000..fde38a197 --- /dev/null +++ b/0001-Add-customizable-vcs-prompt-theme.patch @@ -0,0 +1,499 @@ +=46rom 1d557059a1ae35be86f17832526198abde8d949d Mon Sep 17 00:00:00 = 2001 +From: Marlon Richert +Date: Thu, 15 Apr 2021 23:28:56 +0300 +Subject: [PATCH] Add customizable `vcs` prompt theme + +--- + 0001-Add-customizable-vcs-prompt-theme.txt | 245 +++++++++++++++++++++ + Functions/Prompts/prompt_vcs_setup | 227 +++++++++++++++++++ + 2 files changed, 472 insertions(+) + create mode 100644 0001-Add-customizable-vcs-prompt-theme.txt + create mode 100644 Functions/Prompts/prompt_vcs_setup + +diff --git a/0001-Add-customizable-vcs-prompt-theme.txt = b/0001-Add-customizable-vcs-prompt-theme.txt +new file mode 100644 +index 000000000..980f4a317 +--- /dev/null ++++ b/0001-Add-customizable-vcs-prompt-theme.txt +@@ -0,0 +1,245 @@ ++=46rom 1d34a81c3b09228deaf9de599e42611ec4fe21dd Mon Sep 17 00:00:00 = 2001 ++From: Marlon Richert ++Date: Thu, 15 Apr 2021 23:28:56 +0300 ++Subject: [PATCH] Add customizable `vcs` prompt theme ++ ++--- ++ Functions/Prompts/prompt_vcs_setup | 226 = +++++++++++++++++++++++++++++ ++ 1 file changed, 226 insertions(+) ++ create mode 100644 Functions/Prompts/prompt_vcs_setup ++ ++diff --git a/Functions/Prompts/prompt_vcs_setup = b/Functions/Prompts/prompt_vcs_setup ++new file mode 100644 ++index 000000000..218e6a5e2 ++--- /dev/null +++++ b/Functions/Prompts/prompt_vcs_setup ++@@ -0,0 +1,226 @@ +++## +++# Prompt that can be customized through vcs_info +++# +++ +++autoload -Uz add-zle-hook-widget add-zsh-hook vcs_info +++ +++# Standardized exit codes. See `man 3 sysexits`. +++if [[ ${(t)sysexits} !=3D *readonly* ]]; then +++ # Avoid error in case this has been set already. +++ readonly -ga sysexits=3D( +++ USAGE +++ DATAERR +++ NOINPUT +++ NOUSER +++ NOHOST +++ UNAVAILABLE +++ SOFTWARE +++ OSERR +++ OSFILE +++ CANTCREAT +++ IOERR +++ TEMPFAIL +++ PROTOCOL +++ NOPERM +++ CONFIG +++ ) +++fi +++ +++# Prompt segments +++readonly -gHA _prompt_vcs_defaults=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' +++) +++ +++prompt_vcs_help() { +++ print -r -- \ +++"This prompt theme can by customized by copy-pasting any of the code = below to +++your .zshrc file and editing it there:' +++ +++ # For each of these, +++ # * the first string is used for \$PS1 after changing dirs, +++ # * the second string is used for \$PS1 otherwise, and +++ # * the third string is used for \$RPS1 and updated asynchronously. +++ # In these, %v expands to the name (if any) & number of the last = exit code. +++ zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ +++ = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ +++ "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ +++ "${_prompt_vcs_defaults[start:right]//'%%'/%}" +++ zstyle ':vcs_info:*:prompt_vcs:*' formats \\ +++ = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ +++ ${(q+)_prompt_vcs_defaults[start:left]} \\ +++ = ${(q+):-%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start= :repo]} +++ zstyle ':vcs_info:*:prompt_vcs:*' actionformats \\ +++ = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ +++ ${(q+)_prompt_vcs_defaults[start:left]} \\ +++ = ${(q+):-%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start= :repo]} +++ +++ # These set the values of %c and %u, respectively: +++ zstyle ':vcs_info:*:prompt_vcs:*' stagedstr = ${(q+)_prompt_vcs_defaults[start:staged]} +++ zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr = ${(q+)_prompt_vcs_defaults[start:unstaged]} +++ +++For more info on the config above, see +++http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html and the = end of = +++http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#vcs_005f= info-Configuration" +++} +++ +++# Sets a style if it hasn't been set yet. +++_prompt_vcs_zstyle() { +++ local -a val +++ zstyle -g val "$1" "$2" +++ (( $#val )) || +++ zstyle "$@" +++} +++ +++_prompt_vcs_info() { +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' max-exports 3 # = Default is 2. +++ +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ +++ = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ +++ "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ +++ "${_prompt_vcs_defaults[start:right]//'%%'/%}" +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' formats \ +++ = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ +++ "$_prompt_vcs_defaults[start:left]" \ +++ = "%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start:repo]"= +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' actionformats \ +++ = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ +++ "$_prompt_vcs_defaults[start:left]" \ +++ = "%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start:repo]"= +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' stagedstr \ +++ "$_prompt_vcs_defaults[start:staged]" +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr \ +++ "$_prompt_vcs_defaults[start:unstaged]" +++ +++ vcs_info prompt_vcs # Call with namespace. +++ +++ print -rNC1 -- \ +++ "${(q+)vcs_info_msg_0_}" "${(q+)vcs_info_msg_1_}" = "${(q+)vcs_info_msg_2_}" +++} +++ +++prompt_vcs_chpwd() { +++ emulate -L zsh +++ +++ local -i fd=3D-1; local -a reply +++ exec {fd}< <( +++ # Fetch only staged changes at this point, for performance = reasons. +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' = check-for-staged-changes yes +++ _prompt_vcs_info +++ ) +++ IFS=3D$'\0' read -Aru "$fd" +++ typeset -ga __prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) +++ exec {fd}<&- +++ +++ PS1=3D"$__prompt_vcs_info_msg_[1]" +++ RPS1=3D"$__prompt_vcs_info_msg_[3]" +++} +++ +++prompt_vcs_precmd() { +++ local exitstatus=3D$? # Exit status of last command +++ emulate -L zsh +++ +++ # Assign human-friendly exit status name to %v. +++ 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 +++} +++ +++prompt_vcs_line-init() { +++ emulate -L zsh +++ +++ case $CONTEXT in +++ start ) # (R)PS1 +++ # Asynchronously check for unstaged changes. Do this here & not = in +++ # precmd, so you can press Enter on an empty line to update VCS = info. +++ local -i fd=3D-1 +++ exec {fd}< <( +++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' = check-for-changes yes +++ _prompt_vcs_info +++ print -r -- "$PWD" +++ ) +++ +++ # Add callback. Needs to be a widget, so we can refresh the = prompt. +++ zle -Fw "$fd" prompt_vcs_fd-handler +++ ;; +++ cont ) # (R)PS2 +++ # Indent left continuation prompt for each open shell = construct. +++ local fmt=3D"$_prompt_vcs_defaults[cont:indent]" +++ local -a indent=3D( '%('{1..$(( COLUMNS / ${(m)#fmt} = ))}"_,$fmt,)" ) +++ PS2=3D"${(j::)indent}$_prompt_vcs_defaults[cont:left]" +++ +++ RPS2=3D"$_prompt_vcs_defaults[cont:right]" +++ ;; +++ esac +++} +++ +++# Callback widget function for our async fetch of unstaged VCS = changes +++prompt_vcs_fd-handler() { +++ emulate -L zsh +++ +++ local -i fd=3D$1; local sig=3D$2; local -a reply +++ { +++ zle -F "$fd" # Detach ourselves, so we don't get called more = than once. +++ +++ [[ $sig !=3D (|hup) ]] && +++ return # Error occured +++ +++ IFS=3D$'\0' read -Aru "$fd" +++ +++ [[ $reply[-1] !=3D $PWD ]] && +++ return # Abort if the info is not for the current dir. +++ } always { +++ exec {fd}<&- +++ } +++ shift -p reply +++ typeset -ga __prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) +++ RPS1=3D"$__prompt_vcs_info_msg_[3]" +++ zle .reset-prompt +++} +++ +++prompt_vcs_line-finish() { +++ emulate -L zsh +++ PS1=3D"$__prompt_vcs_info_msg_[2]" +++} +++ +++prompt_vcs_setup() { +++ prompt_opts=3D( cr percent sp ) # Tell promptinit which options to = set. +++ +++ 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 +++ ) +++ +++ add-zsh-hook chpwd prompt_vcs_chpwd +++ add-zsh-hook precmd prompt_vcs_precmd +++ add-zle-hook-widget line-init prompt_vcs_line-init +++ add-zle-hook-widget line-finish prompt_vcs_line-finish +++ zle -N prompt_vcs_fd-handler # Callback widget for async VCS = update. +++ +++ prompt_vcs_chpwd +++} +++ +++prompt_vcs_setup "$@" ++--=20 ++2.31.1 ++ +diff --git a/Functions/Prompts/prompt_vcs_setup = b/Functions/Prompts/prompt_vcs_setup +new file mode 100644 +index 000000000..66f167f49 +--- /dev/null ++++ b/Functions/Prompts/prompt_vcs_setup +@@ -0,0 +1,227 @@ ++## ++# Prompt that can be customized through vcs_info ++# ++ ++autoload -Uz add-zle-hook-widget add-zsh-hook vcs_info ++ ++# Standardized exit codes. See `man 3 sysexits`. ++if [[ ${(t)sysexits} !=3D *readonly* ]]; then ++ # Avoid error in case this has been set already. ++ readonly -ga sysexits=3D( ++ USAGE ++ DATAERR ++ NOINPUT ++ NOUSER ++ NOHOST ++ UNAVAILABLE ++ SOFTWARE ++ OSERR ++ OSFILE ++ CANTCREAT ++ IOERR ++ TEMPFAIL ++ PROTOCOL ++ NOPERM ++ CONFIG ++ ) ++fi ++ ++# Prompt segments ++readonly -gHA _prompt_vcs_defaults=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' ++) ++ ++prompt_vcs_help() { ++ print -r -- \ ++"This prompt theme can by customized by copy-pasting any of the code = below to ++your .zshrc file and editing it there:' ++ ++ # For each of these, ++ # * the first string is used for \$PS1 after changing dirs, ++ # * the second string is used for \$PS1 otherwise, and ++ # * the third string is used for \$RPS1 and updated asynchronously. ++ # In these, %v expands to the name (if any) & number of the last = exit code. ++ zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ ++ = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ ++ "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ ++ "${_prompt_vcs_defaults[start:right]//'%%'/%}" ++ zstyle ':vcs_info:*:prompt_vcs:*' formats \\ ++ = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ ++ ${(q+)_prompt_vcs_defaults[start:left]} \\ ++ = ${(q+):-%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start= :repo]} ++ zstyle ':vcs_info:*:prompt_vcs:*' actionformats \\ ++ = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ ++ ${(q+)_prompt_vcs_defaults[start:left]} \\ ++ = ${(q+):-%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start= :repo]} ++ ++ # These set the values of %c and %u, respectively: ++ zstyle ':vcs_info:*:prompt_vcs:*' stagedstr = ${(q+)_prompt_vcs_defaults[start:staged]} ++ zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr = ${(q+)_prompt_vcs_defaults[start:unstaged]} ++ ++For more info on the config above, see ++http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html and the = end of = ++http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#vcs_005fi= nfo-Configuration" ++} ++ ++# Sets a style if it hasn't been set yet. ++_prompt_vcs_zstyle() { ++ local -a val ++ zstyle -g val "$1" "$2" ++ (( $#val )) || ++ zstyle "$@" ++} ++ ++_prompt_vcs_info() { ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' max-exports 3 # = Default is 2. ++ ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ ++ = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ ++ "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ ++ "${_prompt_vcs_defaults[start:right]//'%%'/%}" ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' formats \ ++ = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ ++ "$_prompt_vcs_defaults[start:left]" \ ++ = "%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start:repo]"= ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' actionformats \ ++ = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ ++ "$_prompt_vcs_defaults[start:left]" \ ++ = "%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start:repo]"= ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' stagedstr \ ++ "$_prompt_vcs_defaults[start:staged]" ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr \ ++ "$_prompt_vcs_defaults[start:unstaged]" ++ ++ vcs_info prompt_vcs # Call with namespace. ++ ++ print -rNC1 -- \ ++ "${(q+)vcs_info_msg_0_}" "${(q+)vcs_info_msg_1_}" = "${(q+)vcs_info_msg_2_}" ++} ++ ++prompt_vcs_chpwd() { ++ emulate -L zsh ++ ++ local -i fd=3D-1; local -a reply ++ exec {fd}< <( ++ # Fetch only staged changes at this point, for performance = reasons. ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' = check-for-staged-changes yes ++ _prompt_vcs_info ++ ) ++ IFS=3D$'\0' read -Aru "$fd" ++ typeset -ga _prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) ++ exec {fd}<&- ++ ++ PS1=3D"$_prompt_vcs_info_msg_[1]" ++ RPS1=3D"$_prompt_vcs_info_msg_[3]" ++} ++ ++prompt_vcs_precmd() { ++ local exitstatus=3D$? # Exit status of last command ++ emulate -L zsh ++ ++ # Assign human-friendly exit status string to %v. ++ 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)" ++ ;; ++ # No need to show EX_OK. ++ esac ++} ++ ++prompt_vcs_line-init() { ++ emulate -L zsh ++ ++ case $CONTEXT in ++ start ) # (R)PS1 ++ # Asynchronously check for unstaged changes. Do this here & not = in ++ # precmd, so you can press Enter on an empty line to update VCS = info. ++ local -i fd=3D-1 ++ exec {fd}< <( ++ _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' = check-for-changes yes ++ _prompt_vcs_info ++ print -r -- "$PWD" ++ ) ++ ++ # Add callback. Needs to be a widget, so we can refresh the = prompt. ++ zle -Fw "$fd" prompt_vcs_fd-handler ++ ;; ++ cont ) # (R)PS2 ++ # Indent left continuation prompt for each open shell construct. ++ local fmt=3D"$_prompt_vcs_defaults[cont:indent]" ++ local -a indent=3D( '%('{1..$(( COLUMNS / ${(m)#fmt} = ))}"_,$fmt,)" ) ++ PS2=3D"${(j::)indent}$_prompt_vcs_defaults[cont:left]" ++ ++ RPS2=3D"$_prompt_vcs_defaults[cont:right]" ++ ;; ++ esac ++} ++ ++# Callback widget function for our async fetch of unstaged VCS changes ++prompt_vcs_fd-handler() { ++ emulate -L zsh ++ ++ local -i fd=3D$1; local sig=3D$2; local -a reply ++ { ++ zle -F "$fd" # Detach ourselves, so we don't get called more than = once. ++ ++ [[ $sig !=3D (|hup) ]] && ++ return # Error occured ++ ++ IFS=3D$'\0' read -Aru "$fd" ++ ++ [[ $reply[-1] !=3D $PWD ]] && ++ return # Abort if the info is not for the current dir. ++ } always { ++ exec {fd}<&- ++ } ++ shift -p reply ++ typeset -ga _prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) ++ RPS1=3D"$_prompt_vcs_info_msg_[3]" ++ zle .reset-prompt ++} ++ ++prompt_vcs_line-finish() { ++ emulate -L zsh ++ PS1=3D"$_prompt_vcs_info_msg_[2]" ++} ++ ++prompt_vcs_setup() { ++ prompt_opts=3D( cr percent sp ) # Tell promptinit which options to = set. ++ ++ 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 ++ ) ++ ++ add-zsh-hook chpwd prompt_vcs_chpwd ++ add-zsh-hook precmd prompt_vcs_precmd ++ add-zle-hook-widget line-init prompt_vcs_line-init ++ add-zle-hook-widget line-finish prompt_vcs_line-finish ++ zle -N prompt_vcs_fd-handler # Callback widget for async VCS update. ++ ++ prompt_vcs_chpwd ++} ++ ++prompt_vcs_setup "$@" +--=20 +2.31.1 + diff --git a/Functions/Prompts/prompt_vcs_setup = b/Functions/Prompts/prompt_vcs_setup new file mode 100644 index 000000000..66f167f49 --- /dev/null +++ b/Functions/Prompts/prompt_vcs_setup @@ -0,0 +1,227 @@ +## +# Prompt that can be customized through vcs_info +# + +autoload -Uz add-zle-hook-widget add-zsh-hook vcs_info + +# Standardized exit codes. See `man 3 sysexits`. +if [[ ${(t)sysexits} !=3D *readonly* ]]; then + # Avoid error in case this has been set already. + readonly -ga sysexits=3D( + USAGE + DATAERR + NOINPUT + NOUSER + NOHOST + UNAVAILABLE + SOFTWARE + OSERR + OSFILE + CANTCREAT + IOERR + TEMPFAIL + PROTOCOL + NOPERM + CONFIG + ) +fi + +# Prompt segments +readonly -gHA _prompt_vcs_defaults=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' +) + +prompt_vcs_help() { + print -r -- \ +"This prompt theme can by customized by copy-pasting any of the code = below to +your .zshrc file and editing it there:' + + # For each of these, + # * the first string is used for \$PS1 after changing dirs, + # * the second string is used for \$PS1 otherwise, and + # * the third string is used for \$RPS1 and updated asynchronously. + # In these, %v expands to the name (if any) & number of the last exit = code. + zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ + = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ + "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ + "${_prompt_vcs_defaults[start:right]//'%%'/%}" + zstyle ':vcs_info:*:prompt_vcs:*' formats \\ + = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ + ${(q+)_prompt_vcs_defaults[start:left]} \\ + = ${(q+):-%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start= :repo]} + zstyle ':vcs_info:*:prompt_vcs:*' actionformats \\ + = ${(q+):-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left= ]} \\ + ${(q+)_prompt_vcs_defaults[start:left]} \\ + = ${(q+):-%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start= :repo]} + + # These set the values of %c and %u, respectively: + zstyle ':vcs_info:*:prompt_vcs:*' stagedstr = ${(q+)_prompt_vcs_defaults[start:staged]} + zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr = ${(q+)_prompt_vcs_defaults[start:unstaged]} + +For more info on the config above, 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" +} + +# Sets a style if it hasn't been set yet. +_prompt_vcs_zstyle() { + local -a val + zstyle -g val "$1" "$2" + (( $#val )) || + zstyle "$@" +} + +_prompt_vcs_info() { + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' max-exports 3 # Default = is 2. + + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' nvcsformats \ + = "${${:-$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]= }//'%%'/%}" \ + "${_prompt_vcs_defaults[start:left]//'%%'/%}" \ + "${_prompt_vcs_defaults[start:right]//'%%'/%}" + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' formats \ + = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ + "$_prompt_vcs_defaults[start:left]" \ + = "%u%c$_prompt_vcs_defaults[start:branch]$_prompt_vcs_defaults[start:repo]"= + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' actionformats \ + = "$_prompt_vcs_defaults[start:chpwd]$_prompt_vcs_defaults[start:left]" \ + "$_prompt_vcs_defaults[start:left]" \ + = "%u%c$_prompt_vcs_defaults[start:action]$_prompt_vcs_defaults[start:repo]"= + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' stagedstr \ + "$_prompt_vcs_defaults[start:staged]" + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' unstagedstr \ + "$_prompt_vcs_defaults[start:unstaged]" + + vcs_info prompt_vcs # Call with namespace. + + print -rNC1 -- \ + "${(q+)vcs_info_msg_0_}" "${(q+)vcs_info_msg_1_}" = "${(q+)vcs_info_msg_2_}" +} + +prompt_vcs_chpwd() { + emulate -L zsh + + local -i fd=3D-1; local -a reply + exec {fd}< <( + # Fetch only staged changes at this point, for performance reasons. + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' = check-for-staged-changes yes + _prompt_vcs_info + ) + IFS=3D$'\0' read -Aru "$fd" + typeset -ga _prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) + exec {fd}<&- + + PS1=3D"$_prompt_vcs_info_msg_[1]" + RPS1=3D"$_prompt_vcs_info_msg_[3]" +} + +prompt_vcs_precmd() { + local exitstatus=3D$? # Exit status of last command + emulate -L zsh + + # Assign human-friendly exit status string to %v. + 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)" + ;; + # No need to show EX_OK. + esac +} + +prompt_vcs_line-init() { + emulate -L zsh + + case $CONTEXT in + start ) # (R)PS1 + # Asynchronously check for unstaged changes. Do this here & not = in + # precmd, so you can press Enter on an empty line to update VCS = info. + local -i fd=3D-1 + exec {fd}< <( + _prompt_vcs_zstyle ':vcs_info:*:prompt_vcs:*' check-for-changes = yes + _prompt_vcs_info + print -r -- "$PWD" + ) + + # Add callback. Needs to be a widget, so we can refresh the = prompt. + zle -Fw "$fd" prompt_vcs_fd-handler + ;; + cont ) # (R)PS2 + # Indent left continuation prompt for each open shell construct. + local fmt=3D"$_prompt_vcs_defaults[cont:indent]" + local -a indent=3D( '%('{1..$(( COLUMNS / ${(m)#fmt} = ))}"_,$fmt,)" ) + PS2=3D"${(j::)indent}$_prompt_vcs_defaults[cont:left]" + + RPS2=3D"$_prompt_vcs_defaults[cont:right]" + ;; + esac +} + +# Callback widget function for our async fetch of unstaged VCS changes +prompt_vcs_fd-handler() { + emulate -L zsh + + local -i fd=3D$1; local sig=3D$2; local -a reply + { + zle -F "$fd" # Detach ourselves, so we don't get called more than = once. + + [[ $sig !=3D (|hup) ]] && + return # Error occured + + IFS=3D$'\0' read -Aru "$fd" + + [[ $reply[-1] !=3D $PWD ]] && + return # Abort if the info is not for the current dir. + } always { + exec {fd}<&- + } + shift -p reply + typeset -ga _prompt_vcs_info_msg_=3D( "${(@Q)reply}" ) + RPS1=3D"$_prompt_vcs_info_msg_[3]" + zle .reset-prompt +} + +prompt_vcs_line-finish() { + emulate -L zsh + PS1=3D"$_prompt_vcs_info_msg_[2]" +} + +prompt_vcs_setup() { + prompt_opts=3D( cr percent sp ) # Tell promptinit which options to = set. + + 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 + ) + + add-zsh-hook chpwd prompt_vcs_chpwd + add-zsh-hook precmd prompt_vcs_precmd + add-zle-hook-widget line-init prompt_vcs_line-init + add-zle-hook-widget line-finish prompt_vcs_line-finish + zle -N prompt_vcs_fd-handler # Callback widget for async VCS update. + + prompt_vcs_chpwd +} + +prompt_vcs_setup "$@" --=20 2.31.1 --Apple-Mail=_232988C9-A9B4-49AD-81F4-5ED65D8ABEAE--