From bacad965238158b9ae6ff438ba923725ec128020 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 16 Feb 2020 00:03:13 +0000 Subject: github #48/0001: vcs_info git: avoid warnings in bare repositories Git 2.25 introduced a change to how git rev-parse --show-toplevel behaves. Traditionally, it succeeded with no output if the user was in a bare repository. Now it dies, printing an error to standard error. Consequently, when the user is in a bare repository with a newer Git, vcs_info prints noisily to standard error. While this is functionally harmless, it is annoying for the shell to print messages from Git every time the prompt is printed, so let's silence the error message. --- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Functions') diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index ceb4f978a..0128c0981 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -138,7 +138,7 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} -gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel ) +gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) rrn=${gitbase:t} if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD) -- cgit v1.2.3 From 51260963703bbc91944434648ae71a05addbcb05 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sun, 16 Feb 2020 20:54:12 +0000 Subject: github #48/0002: vcs_info git: properly detect bare repositories We currently detect Git repositories by finding the top level of the working tree, and if we fail to detect it, assume that we're not in a repository. However, there's a case we don't consider: a bare repository. Let's detect if the user is in a bare repository by checking if gitdir is set, and if so, using that if there is no working tree. We now detect bare Git repositories with vcs_info, as expected. --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 75751a547..290f1c6af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-02-17 brian m. carlson + * github #48/0002: + Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: + properly detect bare repositories + * github #48/0001: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: avoid warnings in bare repositories diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 0128c0981..5ddce72a6 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -139,6 +139,10 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) +if [[ -z ${gitbase} ]]; then + # Bare repository + gitbase=${gitdir:P} +fi rrn=${gitbase:t} if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD) -- cgit v1.2.3 From af57462beb38159637eba7004363d867f41eff50 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:48:51 +0000 Subject: 45545: vcs_info git: In interactive rebases, ignore comment lines. --- ChangeLog | 5 +++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 6fdaccb7f..fa59d44e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-03-15 Daniel Shahaf + + * 45545: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: In interactive rebases, ignore comment lines. + 2020-03-13 dana * unposted: Completion/Unix/Command/_git: Fix copy/paste error diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 5ddce72a6..a8f49e24a 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -202,6 +202,10 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then # exec: Add "exec ${command}" to $git_patches_applied. # (anything else): As 'exec'. case $p in + ([#]*) + # Comment line. Skip. + continue + ;; ((p|pick|e|edit|r|reword|f|fixup|s|squash)' '*) # The line is of the form "pick $hash $subject". # Just strip the verb and we're good to go. -- cgit v1.2.3 From c756545014c93448494ee4f1d841d8487601a324 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:48:52 +0000 Subject: 45546: vcs_info git: In interactive rebases, properly support the full form of the "exec" verb. The code before this commit happened to have done the right thing: "exec" lines were handled by the catchall forward compatibility case, which happened to have had virtually the same effect as the correct case. However, that was merely an accidental result. This patch makes the code do the right thing deliberately, rather than by accident. --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index fa59d44e6..183db5dd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-03-15 Daniel Shahaf + * 45546: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: In interactive rebases, properly support the full + form of the "exec" verb. + * 45545: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: In interactive rebases, ignore comment lines. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index a8f49e24a..d8e5d1ff1 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -229,11 +229,11 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then p="${p%% *} ?" fi ;; - (x *) + ((x|exec) *) # The line is of the form 'exec foo bar baz' where 'foo bar # baz' is a shell command. There's no way to map _that_ to # "$hash $subject", but I hope this counts as making an effort. - p=${p/x /exec } + p=${p/#x /exec } ;; (*) # Forward compatibility with not-yet-existing 'git rebase -i' verbs. -- cgit v1.2.3 From 8e128afb2c655d759d013c98002ef92795a5cafa Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:48:53 +0000 Subject: 45547: vcs_info git: In interactive rebases, process gen-unapplied-string arguments like gen-applied-string arguments are processed. I consider this a bugfix, since it's unexpected for -applied and -unapplied to differ about this. --- ChangeLog | 5 +++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 183db5dd8..820f78734 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-03-15 Daniel Shahaf + * 45547: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: In interactive rebases, process + gen-unapplied-string arguments like gen-applied-string arguments + are processed. + * 45546: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: In interactive rebases, properly support the full form of the "exec" verb. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index d8e5d1ff1..f7c4210e8 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -196,15 +196,16 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then # 'git rebase -i' patchdir="${gitdir}/rebase-merge" local p - [[ -f "${patchdir}/done" ]] && - for p in ${(f)"$(< "${patchdir}/done")"}; do + VCS_INFO_git_map_rebase_line_to_hash_and_subject() { + local p=$1 + unset REPLY # pick/edit/fixup/squash/reword: Add "$hash $subject" to $git_patches_applied. # exec: Add "exec ${command}" to $git_patches_applied. # (anything else): As 'exec'. case $p in ([#]*) # Comment line. Skip. - continue + return 0 ;; ((p|pick|e|edit|r|reword|f|fixup|s|squash)' '*) # The line is of the form "pick $hash $subject". @@ -241,11 +242,19 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then p+=" ?" fi esac - git_patches_applied+=("$p") - done + REPLY=$p + } + if [[ -f "${patchdir}/done" ]] ; then + for p in ${(f)"$(< "${patchdir}/done")"}; do + VCS_INFO_git_map_rebase_line_to_hash_and_subject "$p" + (( $+REPLY )) && git_patches_applied+=( "$REPLY" ) + done + fi if [[ -f "${patchdir}/git-rebase-todo" ]] ; then - # TODO: Process ${patchdir}/git-rebase-todo lines like ${patchdir}/done lines are - git_patches_unapplied=( ${${(f)${"$(<"${patchdir}/git-rebase-todo")"}}:#[#]*} ) + for p in ${(f)"$(< "${patchdir}/git-rebase-todo")"}; do + VCS_INFO_git_map_rebase_line_to_hash_and_subject "$p" + (( $+REPLY )) && git_patches_unapplied+=( "$REPLY" ) + done fi VCS_INFO_git_handle_patches elif [[ -d "${gitdir}/rebase-apply" ]]; then -- cgit v1.2.3 From 5a1f5cf8ab32e598d06c024620468657c137d5c3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:15:45 +0000 Subject: 45543: vcs_info quilt: Allow quiltcommand to be a function. Before this commit, it could only be an external command. --- ChangeLog | 3 +++ Functions/VCS_Info/VCS_INFO_quilt | 5 +++-- README | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 820f78734..4687c2212 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-15 Daniel Shahaf + * 45543: Functions/VCS_Info/VCS_INFO_quilt, README: vcs_info + quilt: Allow quiltcommand to be a function. + * 45547: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: In interactive rebases, process gen-unapplied-string arguments like gen-applied-string arguments diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index fef85964a..264dbed0e 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -133,7 +133,7 @@ function VCS_INFO_quilt-patch2subject() { # This zstyle call needs to be moved further up if `quilt' needs # to be run in more places than this one. zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt' - quilt_env=(env) + quilt_env=() if [ -z "$patches" ]; then zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" if [[ "${patches}" != /* ]]; then @@ -147,7 +147,8 @@ function VCS_INFO_quilt-patch2subject() { fi quilt_env+=(QUILT_PATCHES="$patches") fi - unapplied=( ${(f)"$(${quilt_env[@]} $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} ) + unapplied=( ${(f)"$(if (( $+quilt_env[1] )); then export ${quilt_env[@]}; fi + $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} ) unapplied=( ${unapplied:#} ) else unapplied=() diff --git a/README b/README index b8dfd0e2a..2bd5c2179 100644 --- a/README +++ b/README @@ -38,6 +38,11 @@ Build-time change: The default value of the --enable-gdbm configure argument has changed from "yes" to "no". Thus, the zsh/db/gdbm module will not be built unless --enable-gdbm is passed explicitly. +vcs_info quilt: The value of the 'quiltcommand' style used to be taken for the +name of an external command. Now it may also be a shell function. Normal +command word precedece rules apply, so if you have a function and a command +with the same name, the function will be used. + Incompatibilities since 5.7.1 ----------------------------- -- cgit v1.2.3 From e1946bacf82653b4795793abe5ae095e3e65fea7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:06:21 +0000 Subject: 45540: vcs_info git: In non-interactive rebases, compute patch names for unapplied patches. --- ChangeLog | 5 ++++ Doc/Zsh/contrib.yo | 4 +-- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 31 ++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 4687c2212..edf814dd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-03-15 Daniel Shahaf + * 45540: Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: + In non-interactive rebases, compute patch names for unapplied + patches. + * 45543: Functions/VCS_Info/VCS_INFO_quilt, README: vcs_info quilt: Allow quiltcommand to be a function. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c6bf745b7..0909cd4f5 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1177,7 +1177,7 @@ If there are two different ways of gathering information, you can select the simpler one by setting this style to true; the default is to use the not-that-simple code, which is potentially a lot slower but might be more accurate in all possible cases. This style is -used by the tt(bzr) and tt(hg) backends. In the case of tt(hg) it will invoke +used by the tt(bzr), tt(hg), and tt(git) backends. In the case of tt(hg) it will invoke the external hexdump program to parse the binary dirstate cache file; this method will not return the local revision number. ) @@ -1236,7 +1236,7 @@ item(tt(get-unapplied))( This boolean style controls whether a backend should attempt to gather a list of unapplied patches (for example with Mercurial Queue patches). -Used by the tt(quilt) and tt(hg) backends. +Used by the tt(quilt), tt(hg), and tt(git) backends. ) enditem() diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index f7c4210e8..97a04b6ce 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -261,17 +261,20 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then # 'git rebase' without -i patchdir="${gitdir}/rebase-apply" local next="${patchdir}/next" + local this_patch_file if [[ -f $next ]]; then local cur=$(< $next) local p subject - # Fake patch names for all but current patch + # Fake patch names for patches "before" the current patch + # + # Note: With git 2.24, (( cur == 1 )), so the loop body never runs. for ((p = 1; p < cur; p++)); do printf -v "git_patches_applied[$p]" "%04d ?" "$p" done + # Set $subject to the info for the current patch if [[ -f "${patchdir}/msg-clean" ]]; then subject="${$(< "${patchdir}/msg-clean")[(f)1]}" - elif local this_patch_file - printf -v this_patch_file "%s/%04d" "${patchdir}" "${cur}" + elif printf -v this_patch_file "%s/%04d" "${patchdir}" "${cur}" [[ -f $this_patch_file ]] then () { @@ -286,11 +289,27 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then else git_patches_applied+=("? $subject") fi - local last="$(< "${patchdir}/last")" - if (( cur+1 <= last )); then - git_patches_unapplied=( {$((cur+1))..$last} ) + # Handle patches scheduled for after the current patch, if instructed to. + if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-unapplied; then + local last="$(< "${patchdir}/last")" + if [[ -r ${patchdir}/original-commit && -r ${patchdir}/orig-head ]] && + ! zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple + then + git_patches_unapplied+=( ${(f)"$(${vcs_comm[cmd]} log --reverse --pretty="%h %s" "$(<${patchdir}/original-commit)..$(<${patchdir}/orig-head)")"} ) + else + for ((p = cur+1; p <= last; p++)); do + printf -v this_patch_file "%s/%04d" "${patchdir}" "${p}" + if [[ -f $this_patch_file ]]; then + VCS_INFO_patch2subject "${this_patch_file}" + git_patches_unapplied+=( "$p $REPLY" ) + else + git_patches_unapplied+=( "$p ?" ) + fi + done + fi fi fi + unset this_patch_file VCS_INFO_git_handle_patches elif [[ -f "${gitdir}/MERGE_HEAD" ]]; then -- cgit v1.2.3 From 4ce4483daf856aa7e9adfecea8e5ee7f87f0b22c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:06:22 +0000 Subject: 45539: vcs_info git: In non-interactive rebases, obtain applied patches' names. --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index edf814dd9..92d37809e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-03-15 Daniel Shahaf + * 45539: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: In non-interactive rebases, obtain applied + patches' names. + * 45540: Doc/Zsh/contrib.yo, Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: In non-interactive rebases, compute patch names for unapplied diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 97a04b6ce..2b1e9afca 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -266,11 +266,23 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then local cur=$(< $next) local p subject # Fake patch names for patches "before" the current patch - # - # Note: With git 2.24, (( cur == 1 )), so the loop body never runs. - for ((p = 1; p < cur; p++)); do - printf -v "git_patches_applied[$p]" "%04d ?" "$p" - done + if [[ -r ${patchdir}/rewritten ]]; then + if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple; then + git_patches_applied=( ${${(f)"$(<${patchdir}/rewritten)"}// */' ?'} ) + else + git_patches_applied=( + ${(f)"$(${vcs_comm[cmd]} log --no-walk=unsorted --pretty='%h %s' ${${(f)"$(<${patchdir}/rewritten)"}%% *} --)"} + ) + fi + else + # Compatibility with old git. In 2.11 and 2.24, at least, + # (( cur == 1 )), so the loop body would never run. However, both + # of these versions have original-commit and orig-head and would + # take the 'if' branch, rather than this 'else' branch. + for ((p = 1; p < cur; p++)); do + printf -v "git_patches_applied[$p]" "%04d ?" "$p" + done + fi # Set $subject to the info for the current patch if [[ -f "${patchdir}/msg-clean" ]]; then subject="${$(< "${patchdir}/msg-clean")[(f)1]}" -- cgit v1.2.3 From e5765bfdc89f131d03051ba4963819fdfe252503 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 Mar 2020 18:06:23 +0000 Subject: 45541: internal: vcs_info git: Add a test case repository for rebase-apply situations --- ChangeLog | 4 +++ Functions/VCS_Info/test-repo-git-rebase-apply | 49 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 Functions/VCS_Info/test-repo-git-rebase-apply (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 92d37809e..cc270ddc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-03-15 Daniel Shahaf + * 45541: Functions/VCS_Info/test-repo-git-rebase-apply: internal: + vcs_info git: Add a test case repository for rebase-apply + situations + * 45539: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: In non-interactive rebases, obtain applied patches' names. diff --git a/Functions/VCS_Info/test-repo-git-rebase-apply b/Functions/VCS_Info/test-repo-git-rebase-apply new file mode 100755 index 000000000..cb4ea4f58 --- /dev/null +++ b/Functions/VCS_Info/test-repo-git-rebase-apply @@ -0,0 +1,49 @@ +#!/usr/local/bin/zsh -f +# +# This script creates a test repository for testing the git backend's behaviour during rebase-apply operations. +# +# It works in ./vcs-test/. +# +# Suggested zshrc settings: +# +# autoload vcs_info +# precmd() { vcs_info; typeset -pm vcs\* } +# zstyle ':vcs_info:*' actionformats %m +# zstyle ':vcs_info:*' patch-format '[%n+%c=%a] [%p] [%u]' +# zstyle :vcs_info:\*gen-applied-string\* hooks f1 +# +vi-f1() { typeset -p argv hook_com } +# zstyle :vcs_info:\*gen-unapplied-string\* hooks f2 +# +vi-f2() { typeset -p argv hook_com } +# zstyle :vcs_info:\* get-unapplied true +# +mkdir "vcs-test" +cd "vcs-test" +git init + +append_lines() { for 1; do echo line from r$1 >> iota && git commit -am "r$1: Append a line"; done } + +echo "This is the file 'iota'." > iota +git add iota +git commit -m "r1: Add iota" +git tag rebase_onto_this HEAD + +# Make another change to iota +append_lines 2 +git tag rebase_from_this HEAD + +# Make non-conflicting changes +for 1 in 3 4 5 6; do + touch kappa$1 + git add kappa$1 + git commit -m "r${1}: non-conflicting change" +done + +# Make more changes to iota +append_lines 7 8 9 + +# Specify a rebase that would create the history [1,3,4,5,6,7,8,9]. +# This will conflict because r7 depends on r2 which is not included. +git checkout -b myref +git rebase --onto=rebase_onto_this rebase_from_this myref + + -- cgit v1.2.3 From b0d020408a935d2d1c317206e3eda43217d0d453 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Mar 2020 01:32:49 +0000 Subject: 45624: vcs_info: Set $rrn in all backends. --- ChangeLog | 5 +++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil | 1 + Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 | 1 + Functions/VCS_Info/VCS_INFO_bydir_detect | 2 ++ 4 files changed, 9 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index f53433443..f1b39709d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-03-26 Daniel Shahaf + * 45624: Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil, + Functions/VCS_Info/Backends/VCS_INFO_get_data_p4, + Functions/VCS_Info/VCS_INFO_bydir_detect: vcs_info: Set $rrn + in all backends. + * 45623: Completion/Unix/Command/_quilt: Add subcommand descriptions diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil index fd0f8389e..e84b3abc0 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil @@ -20,5 +20,6 @@ if [ -n "$merging" ]; then action="merging" fi +rrn=${fsinfo[local_root]:t} VCS_INFO_formats "$action" "${fsbranch}" "${fsinfo[local_root]}" '' "$changed" "${fshash}" "${fsinfo[repository]}" return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 index 329884982..815924c26 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 @@ -17,6 +17,7 @@ local p4branch change # here down is synced as the revision. # I suppose the following might be slow on a tortuous client view. change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}" +rrn=${p4base:t} zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r" hook_com=( branch "${p4info[Client_name]}" revision "${change}" ) if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then diff --git a/Functions/VCS_Info/VCS_INFO_bydir_detect b/Functions/VCS_Info/VCS_INFO_bydir_detect index 29b261413..89b4d6503 100644 --- a/Functions/VCS_Info/VCS_INFO_bydir_detect +++ b/Functions/VCS_Info/VCS_INFO_bydir_detect @@ -36,4 +36,6 @@ done [[ ${basedir} == "/" ]] && return 1 vcs_comm[basedir]=${basedir} +# TODO: Would the following be correct? --- +# rrn=${vcs_comm[basedir]:t} return 0 -- cgit v1.2.3 From cb87816b0f47367a763790adabcec1e331156ea2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Mar 2020 01:32:50 +0000 Subject: 45626: vcs_info: Deduplicate calling the set-branch-format hook. --- ChangeLog | 8 ++++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr | 11 ++--------- Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 | 10 ++-------- Functions/VCS_Info/Backends/VCS_INFO_get_data_svk | 10 ++-------- Functions/VCS_Info/Backends/VCS_INFO_get_data_svn | 10 ++-------- Functions/VCS_Info/VCS_INFO_set-branch-format | 22 ++++++++++++++++++++++ Functions/VCS_Info/vcs_info | 1 + 7 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 Functions/VCS_Info/VCS_INFO_set-branch-format (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index f1b39709d..a82b46570 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-03-26 Daniel Shahaf + * 45626: Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr, + Functions/VCS_Info/Backends/VCS_INFO_get_data_p4, + Functions/VCS_Info/Backends/VCS_INFO_get_data_svk, + Functions/VCS_Info/Backends/VCS_INFO_get_data_svn, + Functions/VCS_Info/VCS_INFO_set-branch-format, + Functions/VCS_Info/vcs_info: vcs_info: Deduplicate calling the + set-branch-format hook. + * 45624: Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil, Functions/VCS_Info/Backends/VCS_INFO_get_data_p4, Functions/VCS_Info/VCS_INFO_bydir_detect: vcs_info: Set $rrn diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr index b30e0e12b..f1f5527e8 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr @@ -100,14 +100,7 @@ else fi rrn=${bzrbase:t} -zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat bzrbr || bzrbr="%b:%r" -hook_com=( branch "${bzrinfo[2]}" revision "${bzrinfo[1]}" ) -if VCS_INFO_hook 'set-branch-format' "${bzrbr}"; then - zformat -f bzrbr "${bzrbr}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" -else - bzrbr=${hook_com[branch-replace]} -fi -hook_com=() - +VCS_INFO_set-branch-format "${bzrinfo[2]}" "${bzrinfo[1]}" && + bzrbr="${REPLY}" VCS_INFO_formats '' "${bzrbr}" "${bzrbase}" '' "${bzr_changes}" "${bzrinfo[1]}" "${bzr_changes}" return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 index 815924c26..e8a08a663 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 @@ -18,13 +18,7 @@ local p4branch change # I suppose the following might be slow on a tortuous client view. change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}" rrn=${p4base:t} -zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r" -hook_com=( branch "${p4info[Client_name]}" revision "${change}" ) -if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then - zformat -f p4branch "${p4branch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" -else - p4branch=${hook_com[branch-replace]} -fi -hook_com=() +VCS_INFO_set-branch-format "${p4info[Client_name]}" "${change}" && + p4branch="${REPLY}" VCS_INFO_formats '' "${p4branch}" "${p4base}" '' '' "$change" '' return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk index 1d2d22ffb..149e30222 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk @@ -8,13 +8,7 @@ local -A hook_com svkbase=${vcs_comm[basedir]} rrn=${svkbase:t} -zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svkbranch || svkbranch="%b:%r" -hook_com=( branch "${vcs_comm[branch]}" revision "${vcs_comm[revision]}" ) -if VCS_INFO_hook 'set-branch-format' "${svkbranch}"; then - zformat -f svkbranch "${svkbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" -else - svkbranch=${hook_com[branch-replace]} -fi -hook_com=() +VCS_INFO_set-branch-format "${vcs_comm[branch]}" "${vcs_comm[revision]}" && + svkbranch="${REPLY}" VCS_INFO_formats '' "${svkbranch}" "${svkbase}" '' '' "${vcs_comm[revision]}" '' return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn index 21590addd..6fbd673a7 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn @@ -60,13 +60,7 @@ else fi rrn=${svnbase:t} -zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r" -hook_com=( branch "${svninfo[URL]##*/}" revision "${cwdinfo[Revision]}" ) -if VCS_INFO_hook 'set-branch-format' "${svnbranch}"; then - zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" -else - svnbranch=${hook_com[branch-replace]} -fi -hook_com=() +VCS_INFO_set-branch-format "${svninfo[URL]##*/}" "${cwdinfo[Revision]}" && + svnbranch="${REPLY}" VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${cwdinfo[Revision]}" '' return 0 diff --git a/Functions/VCS_Info/VCS_INFO_set-branch-format b/Functions/VCS_Info/VCS_INFO_set-branch-format new file mode 100644 index 000000000..8cff51b9a --- /dev/null +++ b/Functions/VCS_Info/VCS_INFO_set-branch-format @@ -0,0 +1,22 @@ +# A function for calling the branch-format hook +# +# Return the value to use in REPLY +# +# Parameters: +readonly branch=$1 +readonly revision=$2 +# + +[[ -n $rrn ]] || return 1 +local -A hook_com +local branchformat + +zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat branchformat || branchformat="%b:%r" +hook_com=( branch "${branch}" revision "${revision}" ) +if VCS_INFO_hook 'set-branch-format' "${branchformat}"; then + zformat -f REPLY "${branchformat}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" +else + REPLY=${hook_com[branch-replace]} +fi +hook_com=() +return 0 diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info index 9f48bee75..786b61918 100644 --- a/Functions/VCS_Info/vcs_info +++ b/Functions/VCS_Info/vcs_info @@ -22,6 +22,7 @@ static_functions=( VCS_INFO_hexdump VCS_INFO_hook VCS_INFO_set-patch-format + VCS_INFO_set-branch-format VCS_INFO_maxexports VCS_INFO_nvcsformats VCS_INFO_patch2subject -- cgit v1.2.3 From f207fb90d8a86c5968e1a3d702ea4cf778bd79d8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Mar 2020 01:32:51 +0000 Subject: 45625: vcs_info svn: Detect the "working copy format is too new" error. --- ChangeLog | 3 +++ Functions/VCS_Info/Backends/VCS_INFO_get_data_svn | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index a82b46570..b21bdefed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-26 Daniel Shahaf + * 45625: Functions/VCS_Info/Backends/VCS_INFO_get_data_svn: + vcs_info svn: Detect the "working copy format is too new" error. + * 45626: Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr, Functions/VCS_Info/Backends/VCS_INFO_get_data_p4, Functions/VCS_Info/Backends/VCS_INFO_get_data_svk, diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn index 6fbd673a7..b33efc2fb 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn @@ -10,6 +10,7 @@ local -i rc local -A svninfo parentinfo cwdinfo local -A hook_com integer -r SVN_ERR_WC_UPGRADE_REQUIRED=155036 # from /usr/local/include/subversion-1/svn_error_codes.h +integer -r SVN_ERR_WC_UNSUPPORTED_FORMAT=155021 svnbase="."; svninfo=() @@ -22,7 +23,14 @@ rc=$? if (( rc != 0 )) ; then if (( rc == 1 )) && [[ -n ${(M)dat:#"svn: E${SVN_ERR_WC_UPGRADE_REQUIRED}: "*} ]]; then hook_com=() - VCS_INFO_formats '' '?' '?' '' '' '?' 'upgrade required' + # User should run 'svn upgrade' + VCS_INFO_formats '' '?' '?' '' '' '?' 'working copy upgrade required' + return $? + elif (( rc == 1 )) && [[ -n ${(M)dat:#"svn: E${SVN_ERR_WC_UNSUPPORTED_FORMAT}: "*} ]]; then + hook_com=() + # User probably needs to install a newer svn, but we're not sure, so point + # the user to svn's error message. + VCS_INFO_formats '' '?' '?' '' '' '?' 'svn error' return $? else return 1 -- cgit v1.2.3 From d13d6afb2e788fac8eefeff47e889a54498eea9a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Mar 2020 02:43:41 +0000 Subject: 45627: vcs_info git: Under git-am(1) conflicts, pass to the gen-applied-string hook information on already-applied patches. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hook already receives information about the current (topmost applied) patch and, if the get-unapplied style is set, about future (unapplied) patches. Tested in the Functions/VCS_Info/test-repo-git-rebase-apply scenario, after manually converting the rebase to a «git am». (Specifically, I ran: mkdir d git rebase --abort git format-patch rebase_from_this..HEAD -o d git checkout rebase_onto_this git am d/* .) --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index b21bdefed..0d81ea3b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-03-26 Daniel Shahaf + * 45627: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: Under git-am(1) conflicts, pass to the + gen-applied-string hook information on already-applied patches. + * 45625: Functions/VCS_Info/Backends/VCS_INFO_get_data_svn: vcs_info svn: Detect the "working copy format is too new" error. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 2b1e9afca..2b2040c94 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -258,14 +258,14 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then fi VCS_INFO_git_handle_patches elif [[ -d "${gitdir}/rebase-apply" ]]; then - # 'git rebase' without -i + # 'git rebase' without -i, or 'git am' patchdir="${gitdir}/rebase-apply" local next="${patchdir}/next" local this_patch_file if [[ -f $next ]]; then local cur=$(< $next) local p subject - # Fake patch names for patches "before" the current patch + # Compute patch names for patches "before" the current patch if [[ -r ${patchdir}/rewritten ]]; then if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple; then git_patches_applied=( ${${(f)"$(<${patchdir}/rewritten)"}// */' ?'} ) @@ -280,7 +280,13 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then # of these versions have original-commit and orig-head and would # take the 'if' branch, rather than this 'else' branch. for ((p = 1; p < cur; p++)); do - printf -v "git_patches_applied[$p]" "%04d ?" "$p" + printf -v this_patch_file "%s/%04d" "${patchdir}" "${p}" + if [[ -f $this_patch_file ]]; then + VCS_INFO_patch2subject "${this_patch_file}" + git_patches_applied+=( "$p $REPLY" ) + else + git_patches_applied+=( "$p ?" ) + fi done fi # Set $subject to the info for the current patch @@ -298,6 +304,8 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then subject=${subject:-'?'} if [[ -f "${patchdir}/original-commit" ]]; then git_patches_applied+=("$(< ${patchdir}/original-commit) $subject") + elif [[ -f "${patchdir}/next" ]]; then + git_patches_applied+=("$(< ${patchdir}/next) $subject") else git_patches_applied+=("? $subject") fi -- cgit v1.2.3 From 2f2aa360bc9a966f819474d349b79fd13191cb16 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 28 Mar 2020 03:40:52 +0000 Subject: 45644: vcs_info git: Fix current patch's name in several cases. --- ChangeLog | 3 +++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 15 +++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index dc041d2e1..57a397ce1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-28 Daniel Shahaf + * 45644: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: Fix current patch's name in several cases. + * unposted: Test/V07pcre.ztst: Fix syntax error introduced in 45591. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 2b2040c94..79429c8e0 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -292,9 +292,24 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then # Set $subject to the info for the current patch if [[ -f "${patchdir}/msg-clean" ]]; then subject="${$(< "${patchdir}/msg-clean")[(f)1]}" + elif [[ -f "${patchdir}/final-commit" ]]; then + # This value is not rfc2047-encoded. It's also available via + # "${patchdir}/info". + subject="${$(< "${patchdir}/final-commit")[(f)1]}" elif printf -v this_patch_file "%s/%04d" "${patchdir}" "${cur}" [[ -f $this_patch_file ]] then + # This branch is last for several reasons: + # + # - The "Subject" header will be MIME-encoded (rfc2047). + # + # - If the mail has full rfc822 headers (including "Received" and + # so on), we won't find the "Subject:" header, since + # VCS_INFO_patch2subject only checks the first few lines. + # + # - In --scissors mode, we may find the outer "Subject:" header, + # whereas the inner one (after the scissors line) will be used, + # if present. () { local REPLY VCS_INFO_patch2subject "${this_patch_file}" -- cgit v1.2.3 From ae0129b49f9f1b624fb4b067f6f1ef6757a24fd2 Mon Sep 17 00:00:00 2001 From: Manuel Jacob Date: Mon, 22 Jun 2020 00:22:30 +0200 Subject: 46091: Add code to Mercurial VCS backend to show topic if there is any. "Topics" is an experimental concept in Mercurial that augments the current branching concept (called "named branches"). For more information, see the not always up-to-date Mercurial Wiki page https://www.mercurial-scm.org/wiki/TopicPlan. --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 3 ++- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 79fa9c085..bf139ed0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-06-22 Manuel Jacob + + * 46091: Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: Add code to + Mercurial VCS backend to show topic if there is any. + 2020-06-19 Daniel Shahaf * 46044 (tweaked per Matthew): Completion/Unix/Command/_units: diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 0909cd4f5..b9f48e8af 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1328,7 +1328,8 @@ enditem() In tt(branchformat) these replacements are done: startsitem() -sitem(tt(%b))(The branch name.) +sitem(tt(%b))(The branch name. For tt(hg), the branch name can include a +topic name.) sitem(tt(%r))(The current revision number or the tt(hgrevformat) style for tt(hg).) endsitem() diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index cd5ef321d..9f61aeaf4 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -5,7 +5,7 @@ setopt localoptions extendedglob NO_shwordsplit -local hgbase bmfile branchfile rebasefile dirstatefile mqseriesfile \ +local hgbase bmfile branchfile topicfile rebasefile dirstatefile mqseriesfile \ curbmfile curbm \ mqstatusfile mqguardsfile patchdir mergedir \ r_csetid r_lrev r_branch i_bmhash i_bmname \ @@ -27,6 +27,7 @@ mergedir="${hgbase}/.hg/merge/" bmfile="${hgbase}/.hg/bookmarks" curbmfile="${hgbase}/.hg/bookmarks.current" branchfile="${hgbase}/.hg/branch" +topicfile="${hgbase}/.hg/topic" rebasefile="${hgbase}/.hg/rebasestate" dirstatefile="${hgbase}/.hg/dirstate" mqstatusfile="${patchdir}/status" # currently applied patches @@ -69,6 +70,14 @@ fi # If we still don't know the branch it's safe to assume default [[ -n ${r_branch} ]] || r_branch="default" +# Show topic if there is any (the UI for this experimental concept is not yet +# final, but for a long time the convention has been to join the branch name +# and the topic name by a colon) +if [[ -f ${topicfile} && -r ${topicfile} && -s ${topicfile} ]] ; then + IFS= read -r REPLY < ${topicfile} + r_branch=${r_branch}:${REPLY} +fi + # The working dir has uncommitted-changes if the revision ends with a + if [[ $r_lrev[-1] == + ]] ; then hgchanges=1 -- cgit v1.2.3 From 0cffb0a6b3602a00cebe2bbb7537d76727892959 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 18 Jun 2020 11:42:19 +0000 Subject: 46072 + 46136: Add the 'zle $widget -f nolast' syntax, to improve add-zle-hook-widget support for multiple hook functions. See workers/46004 for the use-case. --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 2 +- Doc/Zsh/zle.yo | 7 +++++-- Functions/Misc/add-zle-hook-widget | 4 ++-- Src/Zle/zle_thingy.c | 19 +++++++++++++++++-- Test/X04zlehighlight.ztst | 11 +++++++++++ 6 files changed, 42 insertions(+), 7 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index cc1963af2..0d3a50cd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-06-27 Daniel Shahaf + * 46072 + 46136: Doc/Zsh/contrib.yo, Doc/Zsh/zle.yo, + Functions/Misc/add-zle-hook-widget, Src/Zle/zle_thingy.c, + Test/X04zlehighlight.ztst: Add the 'zle $widget -f nolast' + syntax, to improve add-zle-hook-widget support for multiple + hook functions. + * users/24959/0002: Doc/Zsh/grammar.yo: Update aliases documentation for the addition of the ALIAS_FUNC_DEF option. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c611ff43b..7cde0033f 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -347,7 +347,7 @@ as the var(hook) argument. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Widgets are invoked in the order they were added, with -example(tt(zle )var(widgetname)tt( -Nw -- "$@")) +example(tt(zle )var(widgetname)tt( -Nw -f "nolast" -- "$@")) vindex(WIDGET, in hooks) Note that this means that the `tt(WIDGET)' special parameter tracks the diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 909abeb49..84be010e1 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -415,7 +415,7 @@ xitem(tt(zle) tt(-K) var(keymap)) xitem(tt(zle) tt(-F) [ tt(-L) | tt(-w) ] [ var(fd) [ var(handler) ] ]) xitem(tt(zle) tt(-I)) xitem(tt(zle) tt(-T) [ tt(tc) var(function) | tt(-r) tt(tc) | tt(-L) ] ) -item(tt(zle) var(widget) [ tt(-n) var(num) ] [ tt(-Nw) ] [ tt(-K) var(keymap) ] var(args) ...)( +item(tt(zle) var(widget) [ tt(-n) var(num) ] [ tt(-f) var(flag) ] [ tt(-Nw) ] [ tt(-K) var(keymap) ] var(args) ...)( The tt(zle) builtin performs a number of different actions concerning ZLE. @@ -683,7 +683,7 @@ optional argument for debugging or testing. Note that this transformation is not applied to other non-printing characters such as carriage returns and newlines. ) -item(var(widget) [ tt(-n) var(num) ] [ tt(-Nw) ] [ tt(-K) var(keymap) ] var(args) ...)( +item(var(widget) [ tt(-n) var(num) ] [ tt(-f) var(flag) ] [ tt(-Nw) ] [ tt(-K) var(keymap) ] var(args) ...)( Invoke the specified var(widget). This can only be done when ZLE is active; normally this will be within a user-defined widget. @@ -702,6 +702,9 @@ appears as if the top-level widget called by the user were still active. With the option tt(-w), tt(WIDGET) and related parameters are set to reflect the widget being executed by the tt(zle) call. +Normally, when var(widget) returns the special parameter tt(LASTWIDGET) will +point to it. This can be inhibited by passing the option tt(-f nolast). + Any further arguments will be passed to the widget; note that as standard argument handling is performed, any general argument list should be preceded by tt(-)tt(-). If it is a shell diff --git a/Functions/Misc/add-zle-hook-widget b/Functions/Misc/add-zle-hook-widget index 9cc35496f..4d8049083 100644 --- a/Functions/Misc/add-zle-hook-widget +++ b/Functions/Misc/add-zle-hook-widget @@ -47,9 +47,9 @@ function azhw:${^hooktypes} { for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do if [[ "$hook" = user:* ]]; then # Preserve $WIDGET within the renamed widget - zle "$hook" -N -- "$@" + zle "$hook" -f "nolast" -N -- "$@" else - zle "$hook" -Nw -- "$@" + zle "$hook" -f "nolast" -Nw -- "$@" fi || return done return 0 diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index ce61db27b..cd3f2c356 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -678,6 +678,7 @@ bin_zle_flags(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) else if (!strcmp(*flag, "keepsuffix")) w->flags |= ZLE_KEEPSUFFIX; */ + /* If you add magic strings here, be consistent with bin_zle_call() */ else if (!strcmp(*flag, "vichange")) { if (invicmdmode()) { startvichange(-1); @@ -703,7 +704,7 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) { Thingy t; struct modifier modsave = zmod; - int ret, saveflag = 0, setbindk = 0, setlbindk, remetafy; + int ret, saveflag = 0, setbindk = 0, setlbindk = 0, remetafy; char *wname = *args++, *keymap_restore = NULL, *keymap_tmp; if (!wname) @@ -727,12 +728,26 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) while (*args && **args == '-') { char skip_this_arg[2] = "x"; char *num; + char *flag; if (!args[0][1] || args[0][1] == '-') { args++; break; } while (*++(*args)) { switch (**args) { + case 'f': + flag = args[0][1] ? args[0]+1 : args[1]; + if (flag == NULL || strcmp(flag, "nolast")) { + zwarnnam(name, "%s", "'nolast' expected after -f"); + if (remetafy) + metafy_line(); + return 1; + } + if (!args[0][1]) + *++args = skip_this_arg; + /* If you add magic strings here, be consistent with bin_zle_flags() */ + setlbindk = 1; + break; case 'n': num = args[0][1] ? args[0]+1 : args[1]; if (!num) { @@ -787,7 +802,7 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) * a vi range to detect a repeated key */ setbindk = setbindk || (t->widget && (t->widget->flags & (WIDGET_INT | ZLE_VIOPER)) == WIDGET_INT); - setlbindk = t->widget && (t->widget->flags & ZLE_NOLAST) == ZLE_NOLAST; + setlbindk |= t->widget && (t->widget->flags & ZLE_NOLAST) == ZLE_NOLAST; ret = execzlefunc(t, args, setbindk, setlbindk); unrefthingy(t); if (saveflag) diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst index 7ab050bee..ea1d64fe1 100644 --- a/Test/X04zlehighlight.ztst +++ b/Test/X04zlehighlight.ztst @@ -198,6 +198,17 @@ 0:overlapping region_highlight with near-color (hex-triplets at input) >0m27m24mCDE|340|tCDE|3160|rCDE|39|CDE|340|ueCDE|39| + zpty_start + zpty_input 'f () { zle clear-screen; zle g -f nolast; BUFFER=": ${(q)LASTWIDGET}" }; zle -N f' + zpty_input 'g () { }; zle -N g' + zpty_input 'bindkey "\C-a" f' + zpty_enable_zle + zpty_input $'\C-a' + zpty_line 1 p + zpty_stop +0:zle $widgetname -f nolast +>0m27m24m0m27m24m: clear-screen + %clean zmodload -ui zsh/zpty -- cgit v1.2.3 From 5448e1611d2cc4cb436fedfc3e7ff0f1ebfc766b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 8 Aug 2020 07:29:34 +0000 Subject: 47303: vcs_info hg: Fix changing the expansion of %g (hook_com[guards]) in the set-patch-format hook (regression from workers/40480). To reproduce, go to a hg repository with active mq guards and configure vcs_info as follows: zstyle '*' get-unapplied true zstyle ':vcs_info:*set-patch-format*' hooks f zstyle '*' patch-format '[%g : %G]' zstyle '*' nopatch-format '[%g : %G]' zstyle '*' formats '%m' +vi-f () { hook_com[guards]+=XXX } The regression was first released in 5.3.1-test-2, over three years ago. --- ChangeLog | 7 +++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 8 ++++++-- Functions/VCS_Info/VCS_INFO_set-patch-format | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 35de0e236..e8703a156 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-08-09 Daniel Shahaf + + * 47303: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, + Functions/VCS_Info/VCS_INFO_set-patch-format: vcs_info hg: + Fix changing the expansion of %g (hook_com[guards]) in the + set-patch-format hook (regression from workers/40480). + 2020-08-08 Daniel Shahaf * unposted: Doc/Zsh/metafaq.yo, Etc/FAQ.yo: Update documentation diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 9f61aeaf4..f7e9d6f45 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -217,12 +217,16 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ fi local -A extra_hook_com=( guards "${guards_string}" guards-n ${#mqguards} ) - local -a extra_zformats=( "g:${extra_hook_com[guards]}" "G:${#mqguards}" ) + + (( ${+functions[VCS_INFO_hg_extra_zformats]} )) || + VCS_INFO_hg_extra_zformats() { + reply=( "g:${hook_com[guards]}" "G:${#mqguards}" ) + } VCS_INFO_set-patch-format 'mqpatches' 'applied_string' \ 'mqunapplied' 'unapplied_string' \ ":vcs_info:${vcs}:${usercontext}:${rrn}" hgmqstring \ - extra_hook_com extra_zformats + extra_hook_com VCS_INFO_hg_extra_zformats hgmqstring=$REPLY fi diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format index 917ebf6bf..e387110a2 100644 --- a/Functions/VCS_Info/VCS_INFO_set-patch-format +++ b/Functions/VCS_Info/VCS_INFO_set-patch-format @@ -12,7 +12,7 @@ # $6 - name of a parameter to store a patch-format format string in # $7 - name of an assoc parameter with extra $hook_com key-value pairs for the # set-patch-format hook invocation, or '' for none -# $8 - name of an array parameter with extra arguments for the patch-format zformat call, or '' for empty +# $8 - name of a function that sets $reply to extra arguments for the patch-format zformat call, or '' for none # # The expanded patch-format string is returned in $REPLY. # @@ -68,10 +68,12 @@ hook_com[unapplied]=${hook_com[unapplied]//'%'/%%} fi + reply=() + [[ -n $8 ]] && "$8" zformat -f REPLY "${(P)6}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ "n:${hook_com[applied-n]}" "c:${hook_com[unapplied-n]}" \ "a:${hook_com[all-n]}" \ - ${8:+"${(@P)8}"} + "${reply[@]}" else unset applied_needs_escaping unapplied_needs_escaping # the hook deals with escaping REPLY=${hook_com[patch-replace]} -- cgit v1.2.3 From d877073959ba4b86da968f63be320875a0f0c2a7 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 8 Jun 2012 07:55:27 +0200 Subject: 47305: edit-command-line: when possible, set $BUFFER directly This avoids the send-break which is both visually unappealing and might break some use cases where the user wishes to wrap edit-command-line in another widget. --- Functions/Zle/edit-command-line | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 991775ea5..1103ca556 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -7,6 +7,11 @@ # except that it will handle multi-line buffers properly. emulate -L zsh +local prebuffer +# see below comment for why this is needed +if (( ! ZLE_RECURSIVE )); then + prebuffer=$PREBUFFER +fi () { exec Date: Wed, 5 Aug 2020 16:47:45 +0200 Subject: 47306: edit-command-line: add editor style --- Completion/Zsh/Command/_zstyle | 1 + Doc/Zsh/contrib.yo | 6 ++++++ Functions/Zle/edit-command-line | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index e9a5d800c..bb871762e 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -143,6 +143,7 @@ styles=( cursor e: edit-buffer e:bool edit-previous e:bool + editor e: insert-kept e: leave-cursor e:bool match e: diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 66e6bdc1e..bab1e3023 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2472,6 +2472,12 @@ item(tt(edit-command-line))( Edit the command line using your visual editor, as in tt(ksh). example(bindkey -M vicmd v edit-command-line) + +The editor to be used can also be specified using the tt(editor) style in +the context of the widget. It is specified as an array of command and +arguments: + +example(zstyle :zle:edit-command-line editor gvim -f) ) tindex(expand-absolute-path) item(tt(expand-absolute-path))( diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 1103ca556..8aaeb738e 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -22,8 +22,12 @@ fi (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2] # Open the editor, placing the cursor at the right place if we know how. - local editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) - case $editor in + local -a editor + zstyle -a :zle:$WIDGET editor editor + if (( ! $#editor )); then + editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) + fi + case $editor in (*vim*) integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) "${(@)editor}" -c "normal! ${byteoffset}go" -- $1;; -- cgit v1.2.3 From 0bc559d0918159e357dc3669e97e9bb67b9610bd Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 5 Aug 2020 17:14:13 +0200 Subject: 47307: edit-command-line: restrict editing to region if it is active --- Functions/Zle/edit-command-line | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'Functions') diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 8aaeb738e..3781244b2 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -7,9 +7,20 @@ # except that it will handle multi-line buffers properly. emulate -L zsh -local prebuffer -# see below comment for why this is needed -if (( ! ZLE_RECURSIVE )); then +local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER +# set up parameters depending on which context we are called from, +# see below comment for more details +if (( REGION_ACTIVE )); then + if (( CURSOR < MARK )); then + left=$CURSOR right=$MARK + lbuffer= + else + left=$MARK right=$CURSOR + lbuffer[right-left,-1]= + fi + (( left++ )) + buffer=$BUFFER[left,right] +elif (( ! ZLE_RECURSIVE )); then prebuffer=$PREBUFFER fi @@ -29,10 +40,10 @@ fi fi case $editor in (*vim*) - integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) + integer byteoffset=$(( $#prebuffer + $#lbuffer + 1 )) "${(@)editor}" -c "normal! ${byteoffset}go" -- $1;; (*emacs*) - local lines=( "${(@f):-"$PREBUFFER$LBUFFER"}" ) + local lines=( "${(@f):-"$prebuffer$lbuffer"}" ) "${(@)editor}" +${#lines}:$((${#lines[-1]} + 1)) $1;; (*) "${(@)editor}" $1;; esac @@ -48,13 +59,24 @@ fi # the following point) # - when we are at PS2 (CONTEXT == cont && ! ZLE_RECURSIVE) we do want the # break or otherwise the text from PREBUFFER will be inserted twice + # - when the region is active, we only want to change the parts of BUFFER + # covered by the region, and any PREBUFFER stays as PREBUFFER # - in all other cases (that I can think of) we also just want to set # $BUFFER directly. - if [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then + if (( REGION_ACTIVE )); then + # adjust the length of the region to the length of the edited text + local prelen=$#BUFFER + BUFFER[left,right]="$(<$1)" + if (( MARK > CURSOR )); then + (( MARK += $#BUFFER - prelen )) + else + (( CURSOR += $#BUFFER - prelen )) + fi + elif [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then BUFFER="$(<$1)" else print -Rz - "$(<$1)" zle send-break fi -} =(<<<"$prebuffer$BUFFER") +} =(<<<"$prebuffer$buffer") -- cgit v1.2.3 From f493b438fd2fd695a3082f780f192e570c299247 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Fri, 11 Dec 2020 17:20:45 +0900 Subject: 43946: call run-help for the command given to sudo --- ChangeLog | 5 +++++ Functions/Misc/run-help-sudo | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index c478a9219..ea4b1cfab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-12-11 Jun-ichi Takimoto + + * Samir Benmendil: 43946: Functions/Misc/run-help-sudo: call + run-help (instead of man) for the command given to sudo + 2020-12-05 Bart Schaefer * unposted: Doc/Zsh/compsys.yo: index compprefuncs and comppostfuncs diff --git a/Functions/Misc/run-help-sudo b/Functions/Misc/run-help-sudo index f38696e19..a8fa7aa0f 100644 --- a/Functions/Misc/run-help-sudo +++ b/Functions/Misc/run-help-sudo @@ -2,6 +2,6 @@ if [ $# -eq 0 ]; then man sudo else - man $1 + run-help $1 fi -- cgit v1.2.3 From 34eae734900f42f8127c1eda5ed729f02121ae47 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 11 Dec 2020 17:24:33 +0900 Subject: 47731 (+unposted): add run-help assistant for btrfs also fix format errors in contrib.yo --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 15 +++++++++------ Functions/Misc/run-help-btrfs | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 Functions/Misc/run-help-btrfs (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index ea4b1cfab..2d524e81e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-12-11 Jun-ichi Takimoto + * 47731 (+unposted): Functions/Misc/run-help-btrfs, + Doc/Zsh/contrib.yo: add run-help assistant for btrfs command. + (based on the patch by Samir Benmendil in 43947⁩) + * Samir Benmendil: 43946: Functions/Misc/run-help-sudo: call run-help (instead of man) for the command given to sudo diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 00f693664..2b567056e 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -4363,6 +4363,7 @@ directory. These must be autoloaded, or placed as executable scripts in your search path, in order to be found and used by tt(run-help). startitem() +findex(run-help-btrfs) findex(run-help-git) findex(run-help-ip) findex(run-help-openssl) @@ -4370,14 +4371,16 @@ findex(run-help-p4) findex(run-help-sudo) findex(run-help-svk) findex(run-help-svn) -xitem(run-help-git) -xitem(run-help-ip) -xitem(run-help-openssl) -xitem(run-help-p4) -xitem(run-help-sudo) -xitem(run-help-svk) +xitem(tt(run-help-btrfs)) +xitem(tt(run-help-git)) +xitem(tt(run-help-ip)) +xitem(tt(run-help-openssl)) +xitem(tt(run-help-p4)) +xitem(tt(run-help-sudo)) +xitem(tt(run-help-svk)) item(tt(run-help-svn))( Assistant functions for the +tt(btrfs), tt(git), tt(ip), tt(openssl), diff --git a/Functions/Misc/run-help-btrfs b/Functions/Misc/run-help-btrfs new file mode 100644 index 000000000..0dc1dabcb --- /dev/null +++ b/Functions/Misc/run-help-btrfs @@ -0,0 +1,22 @@ +while [[ $# != 0 && $1 == -* ]]; do + shift +done + +case $1 in + (b*) man btrfs-balance ;; + (c*) man btrfs-check ;; + (d*) man btrfs-device ;; + (f*) man btrfs-filesystem ;; + (i*) man btrfs-inspect-internal ;; + (p*) man btrfs-property ;; + (qg*) man btrfs-qgroup ;; + (qu*) man btrfs-quota ;; + (rec*) man btrfs-receive ;; + (rep*) man btrfs-replace ;; + (resc*) man btrfs-rescue ;; + (rest*) man btrfs-restore ;; + (sc*) man btrfs-scrub ;; + (se*) man btrfs-send ;; + (su*) man btrfs-subvolume ;; + (*) man btrfs ;; +esac -- cgit v1.2.3 From b374f7b31871358dc87ffcf3adfad099f7d5c6c8 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 23 Jan 2021 13:25:24 -0800 Subject: users/26406: preserve caller setopts in zargs --- ChangeLog | 4 ++++ Functions/Misc/zargs | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 4cf94b1f2..d8c6d0e94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-01-23 Bart Schaefer + + * users/26406: Functions/Misc/zargs: preserve caller setopts + 2021-01-20 Jun-ichi Takimoto * 47849: Test/E01options.ztst, Test/V08zpty.ztst, diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs index 28ebca78f..ecd69f7e4 100644 --- a/Functions/Misc/zargs +++ b/Functions/Misc/zargs @@ -70,6 +70,19 @@ # this behavior, as do -l/-L, but when -i/-I appear anywhere then -l/-L # are ignored (forced to 1). +# First, capture the current setopts as "sticky emulation" +if zmodload zsh/parameter +then + emulate $(emulate -l) -c "\ + _zarun() { + options=( ${(j: :kv)options[@]} monitor off zle off )"' + eval "$@" + }' +else + # Warning? + emulate $(emulate -l) -c '_zarun() { eval "$@" }' +fi + emulate -L zsh || return 1 local -a opts eof n s l P i @@ -186,8 +199,8 @@ local execute=' elif (( $opts[(I)-(-verbose|t)] )) then print -u2 -r -- "$call" fi - eval "{ - \"\${(@)call}\" + _zarun "{ + \"\${call[@]}\" } $bg"' local ret=0 analyze=' case $? in -- cgit v1.2.3 From 8f42ecd8eecd848ac5a1efdff9d7db15cc89422f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 27 Jan 2021 11:16:55 +0000 Subject: 47873: Improve completion within dynamic directory names --- ChangeLog | 5 +++++ Completion/Base/Core/_main_complete | 14 ++++++++++++-- Completion/Zsh/Context/_subscript | 4 +++- Functions/Chpwd/zsh_directory_name_cdr | 4 +++- 4 files changed, 23 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 4d4548e3f..2d69f05eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-01-27 Peter Stephenson + * 47873: Completion/Base/Core/_main_complete, + Completion/Zsh/Context/_subscript, + Functions/Chpwd/zsh_directory_name_cdr: Improve completion + within dynamic directory names ~[]. + * GammaFunction@vivaldi.net via Roman: 47744: Src/Zle/zle_main.c: Fix vi-repeat-change when hooks are in use. diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 6b2cf2bcf..663f7557a 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then if [[ -o equals ]] && compset -P 1 '='; then compstate[context]=equal elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then - compset -p 1 - compstate[context]=tilde + if [[ "$PREFIX" = '~['[^\]]# ]]; then + # Inside ~[...] should be treated as a subscript. + compset -p 2 + # To be consistent, we ignore all but the contents of the square + # brackets. + compset -S '\]*' + compstate[context]=subscript + [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return + else + compset -p 1 + compstate[context]=tilde + fi fi fi diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript index 0c9a89ad5..0d9632864 100644 --- a/Completion/Zsh/Context/_subscript +++ b/Completion/Zsh/Context/_subscript @@ -1,6 +1,8 @@ #compdef -subscript- -local expl ind osuf=']' flags sep +local expl ind osuf flags sep + +[[ $ISUFFIX = *\]* ]] || osuf=\] if [[ "$1" = -q ]]; then compquote osuf diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr index cb72e4600..b653e7c38 100644 --- a/Functions/Chpwd/zsh_directory_name_cdr +++ b/Functions/Chpwd/zsh_directory_name_cdr @@ -16,8 +16,10 @@ elif [[ $1 = c ]]; then typeset -a keys values values=(${${(f)"$(cdr -l)"}/ ##/:}) keys=(${values%%:*}) + local addsuffix + [[ $ISUFFIX = *\]* ]] || addsuffix='-S]' _describe -t dir-index 'recent directory index' \ - values -V unsorted -S']' + values -V unsorted $addsuffix return fi fi -- cgit v1.2.3 From 5c60ec46ec087e7e58c8fc00c6821060e8caecb8 Mon Sep 17 00:00:00 2001 From: Arseny Maslennikov Date: Fri, 19 Feb 2021 18:38:09 -0600 Subject: 47867: Fix RPROMPT typo in prompinit --- ChangeLog | 5 +++++ Functions/Prompts/promptinit | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 8eaaee9d1..cee131eda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-02-19 dana + + * 47867: Arseny Maslennikov: Functions/Prompts/promptinit: Fix + RPROMPT typo + 2021-02-18 Peter Stephenson * users/26509: Src/builtin.c: fc -L should ignore remote entries diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index e27b8779a..5e42ebdd3 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -49,7 +49,7 @@ prompt_preview_safely() { # This handles all the stuff from the default :prompt-theme cleanup local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 - local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR local -a precmd_functions preexec_functions prompt_preview_cleanup local -aLl +h zle_highlight @@ -101,7 +101,7 @@ Use prompt -h for help on specific themes.' if [[ -z "$prompt_theme[1]" ]]; then # Not using a prompt theme; save settings local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 - local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR local -a precmd_functions preexec_functions else trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 -- cgit v1.2.3 From 8b67c36d929c2661a1f4e28ff137c7ddd53ec33d Mon Sep 17 00:00:00 2001 From: Arseny Maslennikov Date: Mon, 22 Feb 2021 20:29:55 -0800 Subject: 48094: apply cleanup commands of the current theme on any theme change * Rename zstyle `cleanup' on the context `:prompt-theme' to `restore' everywhere but in prompt_cleanup(). It is only used as a restore mechanism now. * Ensure prompt_cleanup() continues to store its command list in the `cleanup' style. * Clean up before theme switch at the end of set_prompt(). * Prepend every use of prompt_*_setup (which might modify the shell state in ways that require cleanup) with a cleanup run. * Adjust `prompt restore' to do both parts of the newly split restore mechanism, cleanup first. --- ChangeLog | 6 ++++ Functions/Prompts/prompt_restore_setup | 1 + Functions/Prompts/promptinit | 54 ++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 19 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index cee131eda..7e96cfadf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-02-22 Bart Schaefer + + * 48094: Arseny Maslennikov: Functions/Prompts/prompt_restore_setup, + Functions/Prompts/promptinit: apply cleanup commands of the current + theme on any theme change, including "prompt -[hp] $theme" + 2021-02-19 dana * 47867: Arseny Maslennikov: Functions/Prompts/promptinit: Fix diff --git a/Functions/Prompts/prompt_restore_setup b/Functions/Prompts/prompt_restore_setup index 54c4adbf9..b77dbe815 100644 --- a/Functions/Prompts/prompt_restore_setup +++ b/Functions/Prompts/prompt_restore_setup @@ -1,2 +1,3 @@ # Damn that was easy zstyle -t :prompt-theme cleanup +zstyle -t :prompt-theme restore diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 5e42ebdd3..37d69f100 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -47,17 +47,19 @@ prompt_preview_safely() { return fi - # This handles all the stuff from the default :prompt-theme cleanup + # This handles all the stuff from the default :prompt-theme restore local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR - local -a precmd_functions preexec_functions prompt_preview_cleanup + local -a precmd_functions preexec_functions prompt_preview_restore local -aLl +h zle_highlight { # Save and clear current restore-point if any - zstyle -g prompt_preview_cleanup :prompt-theme cleanup + zstyle -g prompt_preview_restore :prompt-theme restore { - zstyle -d :prompt-theme cleanup + zstyle -d :prompt-theme restore + # Execute current cleanup sequence, if any. + zstyle -t :prompt-theme cleanup # The next line is a bit ugly. It (perhaps unnecessarily) # runs the prompt theme setup function to ensure that if @@ -74,8 +76,8 @@ prompt_preview_safely() { zstyle -t :prompt-theme cleanup } } always { - (( $#prompt_preview_cleanup )) && - zstyle -e :prompt-theme cleanup "${prompt_preview_cleanup[@]}" + (( $#prompt_preview_restore )) && + zstyle -e :prompt-theme restore "${prompt_preview_restore[@]}" } } @@ -103,9 +105,11 @@ Use prompt -h for help on specific themes.' local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR local -a precmd_functions preexec_functions + local theme_reset='' else - trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 + local theme_reset='prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' fi + trap 'zstyle -t :prompt-theme cleanup;'"${theme_reset:+ $theme_reset}" 0 ;; esac case "$opt" in @@ -120,6 +124,7 @@ Use prompt -h for help on specific themes.' ;; h) if [[ -n "$2" && -n $prompt_themes[(r)$2] ]]; then if functions prompt_$2_setup >/dev/null; then + zstyle -t :prompt-theme cleanup # The next line is a bit ugly. It (perhaps unnecessarily) # runs the prompt theme setup function to ensure that if # the theme has a _help function that it's been autoloaded. @@ -179,28 +184,38 @@ Use prompt -h for help on specific themes.' typeset -ga zle_highlight=( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight + zstyle -t :prompt-theme cleanup prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" ) ;; esac } prompt_cleanup () { - local -a cleanup_hooks - if zstyle -g cleanup_hooks :prompt-theme cleanup - then - cleanup_hooks+=(';' "$@") - zstyle -e :prompt-theme cleanup "${cleanup_hooks[@]}" - elif (( $+prompt_preview_cleanup == 0 )) + local -a cleanup_hooks theme_active + if ! zstyle -g cleanup_hooks :prompt-theme cleanup then - print -u2 "prompt_cleanup: no prompt theme active" - return 1 + (( $+prompt_preview_restore == 0 )) && + if ! zstyle -g theme_active :prompt-theme restore + then + print -u2 "prompt_cleanup: no prompt theme active" + return 1 + fi + + # Set the cleanup sequence up. + zstyle -e :prompt-theme cleanup \ + 'zstyle -d :prompt-theme cleanup;' \ + 'reply=(yes)' + zstyle -g cleanup_hooks :prompt-theme cleanup fi + + cleanup_hooks+=(';' "$@") + zstyle -e :prompt-theme cleanup "${cleanup_hooks[@]}" } prompt () { local -a prompt_opts theme_active - zstyle -g theme_active :prompt-theme cleanup || { + zstyle -g theme_active :prompt-theme restore || { # This is done here rather than in set_prompt so that it # is safe and sane for set_prompt to setopt localoptions, # which will be cleared before we arrive back here again. @@ -210,8 +225,8 @@ prompt () { [[ -o promptpercent ]] && prompt_opts+=(percent) [[ -o promptsp ]] && prompt_opts+=(sp) [[ -o promptsubst ]] && prompt_opts+=(subst) - zstyle -e :prompt-theme cleanup \ - 'zstyle -d :prompt-theme cleanup;' \ + zstyle -e :prompt-theme restore \ + 'zstyle -d :prompt-theme restore;' \ 'prompt_default_setup;' \ ${PS1+PS1="${(q)PS1}"} \ ${PS2+PS2="${(q)PS2}"} \ @@ -239,7 +254,7 @@ prompt_preview_theme () { emulate -L zsh # Check for proper state handling - (( $+prompt_preview_cleanup )) || { + (( $+prompt_preview_restore )) || { prompt_preview_safely "$@" return } @@ -249,6 +264,7 @@ prompt_preview_theme () { print -n "$1 theme" (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'" print ":" + zstyle -t :prompt-theme cleanup prompt_${1}_setup "$@[2,-1]" (( ${#prompt_opts} )) && setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" -- cgit v1.2.3 From f87b73e677739970c61eab55d4a3276beba1bd43 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 7 Mar 2021 17:07:06 +0000 Subject: 48147/0002: zmathfunc: Fix bug where the exit code would be non-zero if the expression evaluted to zero. --- ChangeLog | 4 ++++ Functions/Math/zmathfunc | 10 ++++++++-- Test/Z02zmathfunc.ztst | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index d77fb2df5..022e38994 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-03-07 Daniel Shahaf + * 48147/0002: Functions/Math/zmathfunc, Test/Z02zmathfunc.ztst: + zmathfunc: Fix bug where the exit code would be non-zero if + the expression evaluted to zero. + * 48147/0001: Test/Z02zmathfunc.ztst: tests: Add a unit test for zmathfunc and a regression test for workers/48146 affecting it. diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc index 4ff40700d..8e4b78549 100644 --- a/Functions/Math/zmathfunc +++ b/Functions/Math/zmathfunc @@ -1,34 +1,40 @@ #autoload zsh_math_func_min() { + emulate -L zsh local result=$1 shift local arg for arg ; do (( $arg < result )) && result=$arg done - (( result )) # return + (( result )) + true # Careful here: `return 0` evaluates an arithmetic expression } functions -M min 1 -1 zsh_math_func_min # at least one argument zsh_math_func_max() { + emulate -L zsh local result=$1 shift local arg for arg ; do (( $arg > result )) && result=$arg done - (( result )) # return + (( result )) + true # Careful here: `return 0` evaluates an arithmetic expression } functions -M max 1 -1 zsh_math_func_max # at least one argument zsh_math_func_sum() { + emulate -L zsh local sum local arg for arg ; do (( sum += $arg )) done (( sum )) + true # Careful here: `return 0` evaluates an arithmetic expression } functions -M sum 0 -1 zsh_math_func_sum diff --git a/Test/Z02zmathfunc.ztst b/Test/Z02zmathfunc.ztst index 94bc59576..43a0a0d76 100644 --- a/Test/Z02zmathfunc.ztst +++ b/Test/Z02zmathfunc.ztst @@ -15,7 +15,7 @@ (set -e; echo $(( min(0, 42) ))) (set -e; echo $(( max(0, -42) ))) (set -e; echo $(( sum(42, -42) ))) --f:regression test for ERR_EXIT +0:regression test for ERR_EXIT >0 >0 >0 -- cgit v1.2.3 From fc82e8193bad79db5de9e40ec99814fe401ad876 Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Mon, 29 Mar 2021 15:53:44 +0000 Subject: 47561 (the git and cvs parts) (compare 44919 + 44920): vcs_info internals: cvs, git: Set ${vcs_comm[basedir]} like all other backends do. That doesn't affect anything, not even other vcs_info internals; it's just for consistency across backends. --- ChangeLog | 10 ++++++++++ Functions/VCS_Info/Backends/VCS_INFO_detect_cvs | 17 +++++++++++++++-- Functions/VCS_Info/Backends/VCS_INFO_detect_git | 1 + Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs | 11 +---------- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 23c4a0707..83bd3c3a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2021-03-29 Aleksandr Mezin + + * 47561 (the git and cvs parts) (compare 44919 + 44920): + Functions/VCS_Info/Backends/VCS_INFO_detect_cvs, + Functions/VCS_Info/Backends/VCS_INFO_detect_git, + Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs, + Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info + internals: cvs, git: Set ${vcs_comm[basedir]} like all other + backends do. + 2021-03-29 dana * 47737: Completion/Zsh/Command/_zstyle: Fix option completion diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs index 7a5ee1eef..a57959ec9 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs +++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs @@ -7,5 +7,18 @@ setopt localoptions NO_shwordsplit [[ $1 == '--flavours' ]] && return 1 VCS_INFO_check_com ${vcs_comm[cmd]} || return 1 -[[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0 -return 1 +if ! [[ -d "./CVS" ]] || ! [[ -r "./CVS/Repository" ]] ; then + return 1 +fi + +# Look for the most distant parent that still has a CVS subdirectory. +local cvsbase="." +cvsbase=${cvsbase:P} +while [[ -d "${cvsbase:h}/CVS" ]]; do + cvsbase="${cvsbase:h}" + if [[ $cvsbase == '/' ]]; then + break + fi +done + +vcs_comm[basedir]="${cvsbase}" diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_git b/Functions/VCS_Info/Backends/VCS_INFO_detect_git index e4191f474..b7955de38 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_detect_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_git @@ -7,6 +7,7 @@ setopt localoptions NO_shwordsplit [[ $1 == '--flavours' ]] && { print -l git-p4 git-svn; return 0 } if VCS_INFO_check_com ${vcs_comm[cmd]} && vcs_comm[gitdir]="$(${vcs_comm[cmd]} rev-parse --git-dir 2> /dev/null)" ; then + vcs_comm[basedir]="$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )" if [[ -d ${vcs_comm[gitdir]}/svn ]] ; then vcs_comm[overwrite_name]='git-svn' elif [[ -d ${vcs_comm[gitdir]}/refs/remotes/p4 ]] ; then vcs_comm[overwrite_name]='git-p4' ; fi return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs index 9b828bd11..bc0d5cfe5 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs @@ -5,17 +5,8 @@ setopt localoptions NO_shwordsplit local cvsbranch cvsbase -# Look for the most distant parent that still has a CVS subdirectory. +cvsbase="${vcs_comm[basedir]}" # VCS_INFO_detect_cvs ensured that ./CVS/Repository exists. -cvsbase="." -cvsbase=${cvsbase:P} -while [[ -d "${cvsbase:h}/CVS" ]]; do - cvsbase="${cvsbase:h}" - if [[ $cvsbase == '/' ]]; then - break - fi -done - cvsbranch=$(< ./CVS/Repository) rrn=${cvsbase:t} cvsbranch=${cvsbranch##${rrn}/} diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 79429c8e0..eb04d4b41 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -138,7 +138,7 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} -gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) +gitbase=${vcs_comm[basedir]} if [[ -z ${gitbase} ]]; then # Bare repository gitbase=${gitdir:P} -- cgit v1.2.3 From 5fdd98552d2cdc7727eb29f75b53da73b39dee4b Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 19 Apr 2021 14:37:32 -0700 Subject: 47489: rename standout as italic --- ChangeLog | 4 ++++ Functions/Misc/colors | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 079b92d32..62595d85a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-04-19 Bart Schaefer + + * 47489: Functions/Misc/colors: rename standout as italic + 2021-04-19 Oliver Kiddle * Marlon Richert: 48621: Completion/Zsh/Function/_add-zsh-hook, diff --git a/Functions/Misc/colors b/Functions/Misc/colors index 027ca9a14..b221e6688 100644 --- a/Functions/Misc/colors +++ b/Functions/Misc/colors @@ -14,11 +14,12 @@ color=( 00 none # 20 gothic 01 bold # 21 double-underline 02 faint 22 normal - 03 standout 23 no-standout + 03 italic 23 no-italic # no-gothic 04 underline 24 no-underline 05 blink 25 no-blink # 06 fast-blink # 26 proportional 07 reverse 27 no-reverse +# 07 standout 27 no-standout 08 conceal 28 no-conceal # 09 strikethrough # 29 no-strikethrough -- cgit v1.2.3 From 9353b12e99827b29b224e5860bcb94636558d01a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 7 Apr 2021 21:48:48 +0000 Subject: users/26635 (tweaked): vcs_info hg: Compute the branch name correctly when get-revision is set and check-for-changes is not Tweak: Simplify an always-true condition. Review-by: Manuel Jacob --- ChangeLog | 7 +++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 429a258ec..d6fd08e48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-04-21 Daniel Shahaf + + * users/26635 (tweaked): + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: vcs_info hg: + Compute the branch name correctly when get-revision is set and + check-for-changes is not + 2021-04-20 Bart Schaefer * 48638: NEWS: mention TYPESET_TO_UNSET diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index f7e9d6f45..2806aee1d 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -49,7 +49,7 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then # Settling for a short (but unique!) hash because getting the full # 40-char hash in addition to all the other info we want isn't # available in a single hg invocation - hgid_args=( id -i -n -b ) + hgid_args=( id -i -n ) # Looking for changes is a tad bit slower since the dirstate cache must # first be refreshed before being read @@ -58,12 +58,12 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then local HGPLAIN HGPLAIN=1 ${vcs_comm[cmd]} ${(z)hgid_args} 2> /dev/null \ - | read -r r_csetid r_lrev r_branch + | read -r r_csetid r_lrev fi fi # If the user doesn't opt to invoke hg we can still get the current branch -if [[ -z ${r_branch} && -r ${branchfile} ]] ; then +if [[ -r ${branchfile} ]] ; then r_branch=$(< ${branchfile}) fi -- cgit v1.2.3 From b0bd14035d1e2747ff98c46ca8715aab4f9533ea Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 21 Apr 2021 21:59:45 +0000 Subject: 48606 + 48607 + unposted test: zmathfunc: Force arguments to be numbers and catch errors. --- ChangeLog | 4 ++++ Functions/Math/zmathfunc | 16 +++++++++++++--- Test/Z02zmathfunc.ztst | 8 +++++++- 3 files changed, 24 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index ac4c95c84..72c48a18b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-04-21 Daniel Shahaf + * 48606 + 48607 + unposted test: Functions/Math/zmathfunc, + Test/Z02zmathfunc.ztst: zmathfunc: Force arguments to be numbers + and catch errors. + * unposted (cf. 48156): Test/Z02zmathfunc.ztst: New test. * users/26635 (tweaked): diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc index 8e4b78549..12d2c2f3d 100644 --- a/Functions/Math/zmathfunc +++ b/Functions/Math/zmathfunc @@ -6,7 +6,12 @@ zsh_math_func_min() { shift local arg for arg ; do - (( $arg < result )) && result=$arg + (( arg < result )) + case $? in + (0) (( result = arg ));; + (1) ;; + (*) return $?;; + esac done (( result )) true # Careful here: `return 0` evaluates an arithmetic expression @@ -19,7 +24,12 @@ zsh_math_func_max() { shift local arg for arg ; do - (( $arg > result )) && result=$arg + (( arg > result )) + case $? in + (0) (( result = arg ));; + (1) ;; + (*) return $?;; + esac done (( result )) true # Careful here: `return 0` evaluates an arithmetic expression @@ -31,7 +41,7 @@ zsh_math_func_sum() { local sum local arg for arg ; do - (( sum += $arg )) + (( sum += arg )) done (( sum )) true # Careful here: `return 0` evaluates an arithmetic expression diff --git a/Test/Z02zmathfunc.ztst b/Test/Z02zmathfunc.ztst index 05e28c07a..2be770a13 100644 --- a/Test/Z02zmathfunc.ztst +++ b/Test/Z02zmathfunc.ztst @@ -44,7 +44,13 @@ ?(eval):1: wrong number of arguments: max() zsh_math_func_min "foo bar" x y z -2dDf:check errors from an unsupported use-case (workers/48156) +2d:check errors from an unsupported use-case (workers/48156) +# We expect one non-empty line of stderr, but don't care about the specific +# error message; thus, the expectation is a pattern (*), for stderr (?), which +# matches any non-empty string (?*). +# +# Sorry, Perl, but I had to give you a run for your money. +*??* F:Calling zsh_math_func_min directly isn't a supported use-case, but if it F:returns zero, something's probably wrong. -- cgit v1.2.3 From 231c049c022963f65f869b9c12e763473207b42a Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 15 May 2021 13:23:31 -0700 Subject: 48707: fix keymap handling when zed invokes read-from-minibuffer; update doc --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 21 +++++++++++---------- Functions/Zle/zed-set-file-name | 27 ++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 15 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 9392e39d9..63341d2bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-05-15 Bart Schaefer + + * 48707: Doc/Zsh/contrib.yo, Functions/Zle/zed-set-file-name: + fix keymap handling when zed invokes read-from-minibuffer + 2021-05-06 Peter Stephenson * 48787: Src/loop.c, Test/A01grammar.ztst: status was incorrect diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8bf1a208e..da7ab2a7c 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -4534,16 +4534,17 @@ suitable for putting into a startup file. Note that, if rerun, this will overwrite the existing tt(zed) and tt(zed-vicmd) keymaps. Completion is available, and styles may be set with the context prefix -`tt(:completion:zed)'. - -A zle widget tt(zed-set-file-name) is available. This can be called by -name from within zed using `tt(\ex zed-set-file-name)' (note, however, that -because of zed's rebindings you will have to type tt(^j) at the end instead -of the return key), or can be bound to a key in either of the tt(zed) or -tt(zed-vicmd) keymaps after `tt(zed -b)' has been run. When the widget is -called, it prompts for a new name for the file being edited. When zed -exits the file will be written under that name and the original file will -be left alone. The widget has no effect with `tt(zed -f)'. +`tt(:completion:zed:)'. + +findex(zed-set-file-name) +A zle widget tt(zed-set-file-name) is available. This can be called +by name from within zed using `tt(\ex zed-set-file-name)' or can be +bound to a key in either of the tt(zed) or tt(zed-vicmd) keymaps after +`tt(zed -b)' has been run. When the widget is called, it prompts for +a new name for the file being edited. When zed exits the file will be +written under that name and the original file will be left alone. The +widget has no effect when invoked from `tt(zed -f)'. The completion +context is changed to `tt(:completion:zed-set-file-name:)'. While tt(zed-set-file-name) is running, zed uses the keymap tt(zed-normal-keymap), which is linked from the main keymap in effect diff --git a/Functions/Zle/zed-set-file-name b/Functions/Zle/zed-set-file-name index da3421e71..745610660 100644 --- a/Functions/Zle/zed-set-file-name +++ b/Functions/Zle/zed-set-file-name @@ -2,8 +2,25 @@ emulate -L zsh autoload -Uz read-from-minibuffer -zle -K zed-normal-keymap - -local REPLY -read-from-minibuffer "File name: " -zed_file_name=$REPLY +case $curcontext in + (zed:::) + local curcontext=zed-set-file-name::: + # The call to vared from zed does the equivalent of + # bindkey -A zed main + # which confuses read-from-minibuffer. Fix it. + bindkey -A zed-normal-keymap main;; + (zed-set-file-name:::) + zle -M "zed-set-file-name: may not be called recursively" + return 1;; + (*) + zle -M "zed-set-file-name: not called from within zed" + return 1;; +esac +{ + local REPLY + read-from-minibuffer "File name: " + zed_file_name=$REPLY +} always { + # Re-install the zed keymap in the way vared should have all along + zle -K zed +} -- cgit v1.2.3 From acd20254b58ea689d8046ff127bc320d5fa91cf6 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 15 May 2021 13:37:35 -0700 Subject: 48710: histed + other zed updates --- ChangeLog | 4 +++ Completion/Zsh/Command/_zed | 16 ++++++++---- Doc/Zsh/contrib.yo | 21 +++++++++++++-- Functions/Misc/zed | 62 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 83 insertions(+), 20 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 52fd4be27..973455232 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-05-15 Bart Schaefer + * 48710: Completion/Zsh/Command/_zed, Doc/Zsh/contrib.yo, + Functions/Misc/zed: add "zed -h" aka "histed", update doc and + completion; improve compatibility with SH_WORD_SPLIT + * 48709: Completion/Base/Widget/_complete_help: suppress error messages from comptry diff --git a/Completion/Zsh/Command/_zed b/Completion/Zsh/Command/_zed index 6b68fadf0..f84993d73 100644 --- a/Completion/Zsh/Command/_zed +++ b/Completion/Zsh/Command/_zed @@ -1,10 +1,16 @@ -#compdef zed fned +#compdef zed fned histed case $service in (fned) _arguments -S : ':shell function:_functions';; +(histed) _arguments -S : \ + '1:history file:_files' \ + '2:history size: ';; (zed) _arguments -S : \ - '(- 2):file:_files' \ - '(1):shell function:_functions' \ - '(1)-x+[specify spaces to use for indentation in function expansion]:spaces' \ - '(1)-f[edit function]';; + '(-h 1 3 4)-f[edit function]' \ + '(-h 1 3 4)-x+[specify spaces to use for indentation in function expansion]:spaces' \ + '(-f -x 1 2)-h[edit history]' \ + '(- 2 3 4)1:file:_files' \ + '(3 4)2:shell function:_functions' \ + '3:history file:_files -g "*(D)"' \ + '4:history size';; esac diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index da7ab2a7c..b777703b3 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -4295,6 +4295,12 @@ Same as tt(zed -f). This function does not appear in the zsh distribution, but can be created by linking tt(zed) to the name tt(fned) in some directory in your tt(fpath). ) +findex(histed) +item(tt(histed) [ [ var(name) ] var(size) ])( +Same as tt(zed -h). This function does not appear in the zsh +distribution, but can be created by linking tt(zed) to the name tt(histed) +in some directory in your tt(fpath). +) findex(is-at-least) item(tt(is-at-least) var(needed) [ var(present) ])( Perform a greater-than-or-equal-to comparison of two strings having the @@ -4504,6 +4510,7 @@ tt(zargs) with the tt(-)tt(-help) option. ) findex(zed) xitem(tt(zed) [ tt(-f) [ tt(-x) var(num) ] ] var(name)) +xitem(tt(zed) [ tt(-h) [ var(name) ] var(size) ]) item(tt(zed -b))( This function uses the ZLE editor to edit a file or function. @@ -4518,7 +4525,14 @@ the given number of spaces; `tt(-x 2)' is consistent with the layout of functions distributed with the shell. Without tt(-f), var(name) is the path name of the file to edit, which need -not exist; it is created on write, if necessary. +not exist; it is created on write, if necessary. With tt(-h), the file is +presumed to contain history events. + +When no file name is provided for tt(-h) the current shell history is edited +in place. The history is renumbered when zed exits successfully. + +When editing history, multi-line events must have a trailing backslash on +every line before the last. While editing, the function sets the main keymap to tt(zed) and the vi command keymap to tt(zed-vicmd). These will be copied from the existing @@ -4544,7 +4558,10 @@ bound to a key in either of the tt(zed) or tt(zed-vicmd) keymaps after a new name for the file being edited. When zed exits the file will be written under that name and the original file will be left alone. The widget has no effect when invoked from `tt(zed -f)'. The completion -context is changed to `tt(:completion:zed-set-file-name:)'. +context is changed to `tt(:completion:zed-set-file-name:)'. When editing +the current history with `tt(zed -h)', the history is first updated and +then the file is written, but the global setting of tt(HISTFILE) is not +altered. While tt(zed-set-file-name) is running, zed uses the keymap tt(zed-normal-keymap), which is linked from the main keymap in effect diff --git a/Functions/Misc/zed b/Functions/Misc/zed index 9eb4b2d93..7d0d590db 100644 --- a/Functions/Misc/zed +++ b/Functions/Misc/zed @@ -5,16 +5,18 @@ # Edit small files with the command line editor. # Use ^X^W to save (or ZZ in vicmd mode), ^C to abort. # Option -f: edit shell functions. (Also if called as fned.) +# Option -h: edit shell history. (Also if called as histed.) setopt localoptions noksharrays local var opts zed_file_name # We do not want timeout while we are editing a file -integer TMOUT=0 okargs=1 fun bind +integer TMOUT=0 okargs=1 fun hist bind local -a expand -zparseopts -D -A opts f b x: +zparseopts -D -A opts f h b x: fun=$+opts[-f] +hist=$+opts[-h] bind=$+opts[-b] if [[ $opts[-x] == <-> ]]; then expand=(-x $opts[-x]) @@ -24,23 +26,28 @@ elif (( $+opts[-x] )); then fi [[ $0 = fned ]] && fun=1 +[[ $0 = histed ]] && hist=1 +(( hist && $# <= 2 )) && okargs=$# (( bind )) && okargs=0 -if (( $# != okargs )); then +if (( $# != okargs || bind + fun + hist > 1 )); then echo 'Usage: zed filename zed -f [ -x N ] function +zed -h [ filename [ size ] ] zed -b' >&2 return 1 fi local curcontext=zed::: -# Matching used in zstyle -m: hide result from caller. -# Variables not used directly here. -local -a match mbegin mend -zstyle -m ":completion:zed:*" insert-tab '*' || - zstyle ":completion:zed:*" insert-tab yes +() { + # Matching used in zstyle -m: hide result from caller. + # Variables not used directly here. + local -a match mbegin mend + zstyle -m ":completion:zed:*" insert-tab '*' || + zstyle ":completion:zed:*" insert-tab yes +} zmodload zsh/terminfo 2>/dev/null @@ -124,22 +131,51 @@ fi setopt localoptions nobanghist if ((fun)) then - var="$(functions $expand -- $1)" + var="$(functions $expand -- "$1")" # If function is undefined but autoloadable, load it if [[ $var = *\#\ undefined* ]] then - var="$(autoload +X $1; functions -- $1)" + var="$(autoload +X "$1"; functions -- "$1")" elif [[ -z $var ]] then var="${(q-)1} () { }" fi vared -M zed -m zed-vicmd -i __zed_init var && eval function "$var" +elif ((hist)) then + if [[ -n $1 ]]; then + { fc -p -a "$1" ${2:-$({ wc -l <"$1" } 2>/dev/null)} || return } + let HISTSIZE++ + print -s "" # Work around fc -p limitation + fi + # When editing the current shell history, the "zed -h" command is not + # itself included because the current event is not added to the ring + # until the next prompt is printed. This means "zed -h" is prepended + # to the result of the edit, because of the way "print -s" is defined. + var=( "${(@Oav)history}" ) + IFS=$'\n' vared -M zed -m zed-vicmd -i __zed_init var + if (( ? )); then + [[ -n $1 ]] && unset HISTFILE + else + local HISTSIZE=0 savehist=$#var + fc -R /dev/null # Remove entries other than those added here + HISTSIZE=$savehist # Resets on function exit because local + [[ -n $1 ]] && SAVEHIST=$savehist # Resets via foregoing fc -a + for (( hist=1; hist <= savehist; hist++ )) + do print -rs -- "$var[hist]" + done + if [[ -n $zed_file_name ]]; then + fc -W "$zed_file_name" + [[ -n $1 ]] && unset HISTFILE + fi + # Note prepend effect when global HISTSIZE greater than $savehist. + # This does not affect file editing. + fi else - zed_file_name=$1 - [[ -f $1 ]] && var="$(<$1)" + zed_file_name="$1" + [[ -f $1 ]] && var="$(<"$1")" while vared -M zed -m zed-vicmd -i __zed_init var do { - print -r -- "$var" >| $zed_file_name + print -r -- "$var" >| "$zed_file_name" } always { (( TRY_BLOCK_ERROR = 0 )) } && break -- cgit v1.2.3 From 7383baf4cff9a1621b9b5517689a5653ae86e123 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Sun, 16 May 2021 21:18:06 -0700 Subject: 48853: improved handling of theme resets when changing prompt themes, especially for theme preview --- ChangeLog | 4 ++ Doc/Zsh/contrib.yo | 10 +-- Functions/Prompts/promptinit | 165 +++++++++++++++++++------------------------ 3 files changed, 81 insertions(+), 98 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 7a50c3529..0eca118a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-05-16 Bart Schaefer + * Marlon Richert: 48853: Doc/Zsh/contrib.yo, + Functions/Prompts/promptinit: improved handling of theme resets + when changing prompt themes, especially for theme preview + * 48860: Etc/BUGS: remove mention of bugs that were fixed * 48857: Src/builtin.c, Src/exec.c, Src/loop.c, Src/makepro.awk, diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index b777703b3..a972f08d6 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2041,10 +2041,12 @@ setopts (tt(promptbang), etc.) are turned on, all other prompt-related options are turned off. The tt(prompt_opts) array preserves setopts even beyond the scope of tt(localoptions), should your function need that. ) -item(Modify precmd and preexec)( -Use of tt(add-zsh-hook) is recommended. The tt(precmd) and tt(preexec) -hooks are automatically adjusted if the prompt theme changes or is -disabled. +item(Modify hooks)( +Use of tt(add-zsh-hook) and tt(add-zle-hook-widget) is recommended (see +ifzman(the bf(Manipulating Hook Functions) section above)\ +ifnzman(noderef(Manipulating Hook Functions))\ +). All hooks that follow the naming pattern tt(prompt_)var(theme)tt(_)var(hook) +are automatically removed when the prompt theme changes or is disabled. ) item(Declare cleanup)( If your function makes any other changes that should be undone when the diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 37d69f100..20503d78b 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -14,6 +14,8 @@ prompt_themes=() promptinit () { emulate -L zsh setopt extendedglob + autoload -Uz add-zsh-hook add-zle-hook-widget + local ppath='' name theme local -a match mbegin mend @@ -32,9 +34,6 @@ promptinit () { fi done - # To manipulate precmd and preexec hooks... - autoload -Uz add-zsh-hook - # Variables common to all prompt styles prompt_newline=$'\n%{\r%}' } @@ -47,38 +46,23 @@ prompt_preview_safely() { return fi - # This handles all the stuff from the default :prompt-theme restore - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 - local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR - local -a precmd_functions preexec_functions prompt_preview_restore - local -aLl +h zle_highlight + # Run this in a subshell, so we don't need to clean up afterwards. + ( + # Execute current theme's cleanup sequence, if any. + zstyle -t :prompt-theme cleanup - { - # Save and clear current restore-point if any - zstyle -g prompt_preview_restore :prompt-theme restore - { - zstyle -d :prompt-theme restore - # Execute current cleanup sequence, if any. - zstyle -t :prompt-theme cleanup - - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _preview function that it's been autoloaded. + # If we can't find a _preview function, run the _setup function to see if + # it will create one. + typeset +f prompt_${1}_preview >&/dev/null || prompt_${1}_setup - if typeset +f prompt_${1}_preview >&/dev/null; then - prompt_${1}_preview "$@[2,-1]" - else - prompt_preview_theme "$@" - fi - } always { - # Run any theme-specific cleanup, then reset restore point - zstyle -t :prompt-theme cleanup - } - } always { - (( $#prompt_preview_restore )) && - zstyle -e :prompt-theme restore "${prompt_preview_restore[@]}" - } + # ...then try again. + if typeset +f prompt_${1}_preview >&/dev/null; then + prompt_${1}_preview "$@[2,-1]" + else + prompt_preview_theme "$@" + fi + ) } set_prompt() { @@ -97,21 +81,6 @@ Options: Use prompt -h for help on specific themes.' getopts "chlps:" opt - case "$opt" in - (h|p) - setopt localtraps - if [[ -z "$prompt_theme[1]" ]]; then - # Not using a prompt theme; save settings - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 - local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR - local -a precmd_functions preexec_functions - local theme_reset='' - else - local theme_reset='prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' - fi - trap 'zstyle -t :prompt-theme cleanup;'"${theme_reset:+ $theme_reset}" 0 - ;; - esac case "$opt" in c) if [[ -n $prompt_theme ]]; then print -n "Current prompt theme" @@ -123,21 +92,26 @@ Use prompt -h for help on specific themes.' return ;; h) if [[ -n "$2" && -n $prompt_themes[(r)$2] ]]; then - if functions prompt_$2_setup >/dev/null; then + # Run this in a subshell, so we don't need to clean up afterwards. + ( + # Execute current theme's cleanup sequence, if any. zstyle -t :prompt-theme cleanup - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _help function that it's been autoloaded. - prompt_$2_setup - fi - if functions prompt_$2_help >/dev/null; then - print "Help for $2 theme:\n" - prompt_$2_help - else - print "No help available for $2 theme." - fi - print "\nType \`prompt -p $2' to preview the theme, \`prompt $2'" - print "to try it out, and \`prompt -s $2' to use it in future sessions." + + # If we can't find a _help function, run the _setup function to see + # if it will create one. + typeset +f prompt_$2_help >/dev/null || + prompt_$2_setup + + # ...then try again. + if typeset +f prompt_$2_help >/dev/null; then + print "Help for $2 theme:\n" + prompt_$2_help + else + print "No help available for $2 theme." + fi + print "\nType \`prompt -p $2' to preview the theme, \`prompt $2'" + print "to try it out, and \`prompt -s $2' to use it in future sessions." + ) else print "$usage" fi @@ -178,8 +152,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" done typeset -ga zle_highlight=( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight @@ -192,11 +171,8 @@ Use prompt -h for help on specific themes.' prompt_cleanup () { local -a cleanup_hooks theme_active - if ! zstyle -g cleanup_hooks :prompt-theme cleanup - then - (( $+prompt_preview_restore == 0 )) && - if ! zstyle -g theme_active :prompt-theme restore - then + if ! zstyle -g cleanup_hooks :prompt-theme cleanup; then + if ! zstyle -g theme_active :prompt-theme restore; then print -u2 "prompt_cleanup: no prompt theme active" return 1 fi @@ -225,22 +201,21 @@ prompt () { [[ -o promptpercent ]] && prompt_opts+=(percent) [[ -o promptsp ]] && prompt_opts+=(sp) [[ -o promptsubst ]] && prompt_opts+=(subst) - zstyle -e :prompt-theme restore \ - 'zstyle -d :prompt-theme restore;' \ - 'prompt_default_setup;' \ - ${PS1+PS1="${(q)PS1}"} \ - ${PS2+PS2="${(q)PS2}"} \ - ${PS3+PS3="${(q)PS3}"} \ - ${PS4+PS4="${(q)PS4}"} \ - ${RPS1+RPS1="${(q)RPS1}"} \ - ${RPS2+RPS2="${(q)RPS2}"} \ - ${RPROMPT+RPROMPT="${(q)RPROMPT}"} \ - ${RPROMPT2+RPROMPT2="${(q)RPROMPT2}"} \ - ${PSVAR+PSVAR="${(q)PSVAR}"} \ - "precmd_functions=(${(q)precmd_functions[@]})" \ - "preexec_functions=(${(q)preexec_functions[@]})" \ - "prompt_opts=( ${prompt_opts[*]} )" \ - 'reply=(yes)' + zstyle -e :prompt-theme restore " + zstyle -d :prompt-theme restore + prompt_default_setup + ${PS1+PS1=${(q+)PS1}} + ${PS2+PS2=${(q+)PS2}} + ${PS3+PS3=${(q+)PS3}} + ${PS4+PS4=${(q+)PS4}} + ${RPS1+RPS1=${(q+)RPS1}} + ${RPS2+RPS2=${(q+)RPS2}} + ${RPROMPT+RPROMPT=${(q+)RPROMPT}} + ${RPROMPT2+RPROMPT2=${(q+)RPROMPT2}} + ${PSVAR+PSVAR=${(q+)PSVAR}} + prompt_opts=( $prompt_opts[*] ) + reply=( yes ) + " } set_prompt "$@" @@ -253,12 +228,6 @@ prompt () { prompt_preview_theme () { emulate -L zsh - # Check for proper state handling - (( $+prompt_preview_restore )) || { - prompt_preview_safely "$@" - return - } - # Minimal preview for prompts that don't supply one local -a prompt_opts print -n "$1 theme" @@ -268,12 +237,20 @@ prompt_preview_theme () { prompt_${1}_setup "$@[2,-1]" (( ${#prompt_opts} )) && setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" + + [[ -n ${chpwd_functions[(r)prompt_${1}_chpwd]} ]] && + prompt_${1}_chpwd [[ -n ${precmd_functions[(r)prompt_${1}_precmd]} ]] && - prompt_${1}_precmd - [[ -o promptcr ]] && print -n $'\r'; : - print -P "${PS1}command arg1 arg2 ... argn" + prompt_${1}_precmd + + # We'd like to call zle-line-init/finish hooks, too, but that's not possible + # while the ZLE is not active. + + [[ -o promptcr ]] && print -n $'\r' + :; print -P -- "${PS1}command arg1 arg2 ... argn" + [[ -n ${preexec_functions[(r)prompt_${1}_preexec]} ]] && - prompt_${1}_preexec + prompt_${1}_preexec } [[ -o kshautoload ]] || promptinit "$@" -- cgit v1.2.3 From a23f19bfbd8c4d7e0a452232659b733bf882474f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 16 Apr 2021 18:04:39 +0000 Subject: 48601/0005: zmathfuncdef: Fix the workers/48147 return status / 'set -e' bug. Not tested. --- ChangeLog | 3 +++ Functions/Misc/zmathfuncdef | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 38ce503a8..2179c62ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-05-18 Daniel Shahaf + * 48601/0005: Functions/Misc/zmathfuncdef: Fix the workers/48147 + return status / 'set -e' bug. + * 48601/0004: Doc/Zsh/builtins.yo: docs: return: Give examples of using arithmetic evaluation. diff --git a/Functions/Misc/zmathfuncdef b/Functions/Misc/zmathfuncdef index e5692e769..5ed991f68 100644 --- a/Functions/Misc/zmathfuncdef +++ b/Functions/Misc/zmathfuncdef @@ -78,7 +78,7 @@ if ! zmodload -e zsh/mathfunc; then fi { - eval "$fname() { (( $body )) }" + eval "$fname() { (( $body )); true }" } always { # Remove math function if shell function definition failed. if (( TRY_BLOCK_ERROR )); then -- cgit v1.2.3 From bd328a2a9c230a8232bdfbaa934874b61fa749d5 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Fri, 28 May 2021 22:20:33 +0900 Subject: 48942: Let EDITOR invoked by edit-command-line know it's a zsh script --- ChangeLog | 3 +++ Functions/Zle/edit-command-line | 1 + 2 files changed, 4 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index d8c20016a..78271d448 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-06-02 Oliver Kiddle + * Akinori MUSHA: 48942: Functions/Zle/edit-command-line: + Let EDITOR invoked by edit-command-line know it's a zsh script + * 48954: Src/Zle/complist.c: avoid crash in reverse-menu-complete from menuselect without 'menu' in $compstate[insert] diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 3781244b2..5f7ea321f 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -8,6 +8,7 @@ emulate -L zsh local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER +local TMPSUFFIX=.zsh # set up parameters depending on which context we are called from, # see below comment for more details if (( REGION_ACTIVE )); then -- cgit v1.2.3 From 1508dc7486636edcb54e81f6a2fcf0faf180c7fa Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Mon, 6 Sep 2021 13:45:36 -0700 Subject: 49218: run-help filters cmd_args before calling run-help- --- ChangeLog | 6 +++ Functions/Misc/run-help | 15 +++--- Functions/Misc/run-help-btrfs | 4 -- Functions/Misc/run-help-git | 10 +--- Functions/Misc/run-help-ip | 4 -- Functions/Misc/run-help-p4 | 2 +- Functions/Misc/run-help-svk | 2 +- Functions/Misc/run-help-svn | 2 +- Test/Z03run-help.ztst | 106 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 Test/Z03run-help.ztst (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index fdaea5678..ce40f65e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-09-06 Bart Schaefer + * Marlon Richert: 49218: Functions/Misc/run-help, + Functions/Misc/run-help-btrfs, Functions/Misc/run-help-git, + Functions/Misc/run-help-ip, Functions/Misc/run-help-p4, + Functions/Misc/run-help-svk, Functions/Misc/run-help-svn: + run-help filters cmd_args before calling run-help- + * unposted (cf. 49202 and 49217): Src/Zle/zle_hist.c: insertlastword ignores blank/missing history entries when repeating diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help index e351dd6a6..d52c1b032 100644 --- a/Functions/Misc/run-help +++ b/Functions/Misc/run-help @@ -101,12 +101,15 @@ do builtin getln cmd_args builtin print -z "$cmd_args" cmd_args=( ${(z)cmd_args} ) - # Discard environment assignments, etc. - while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]] - do - shift cmd_args || return 1 - done - eval "run-help-$1:t ${(q@)cmd_args[2,-1]}" + + # Discard the command itself & everything before it. + shift $cmd_args[(i)${run_help_orig_cmd:-$1}] cmd_args || + return + + # Discard options, parameter assignments & paths. + cmd_args=( ${cmd_args[@]:#([-+]*|*=*|*/*|\~*)} ) + + eval "run-help-$1:t ${(@q)cmd_args}" else POSIXLY_CORRECT=1 man $@:t fi diff --git a/Functions/Misc/run-help-btrfs b/Functions/Misc/run-help-btrfs index 0dc1dabcb..cb139e9b7 100644 --- a/Functions/Misc/run-help-btrfs +++ b/Functions/Misc/run-help-btrfs @@ -1,7 +1,3 @@ -while [[ $# != 0 && $1 == -* ]]; do - shift -done - case $1 in (b*) man btrfs-balance ;; (c*) man btrfs-check ;; diff --git a/Functions/Misc/run-help-git b/Functions/Misc/run-help-git index ce94d0d02..a841f89d6 100644 --- a/Functions/Misc/run-help-git +++ b/Functions/Misc/run-help-git @@ -1,9 +1 @@ -if [ $# -eq 0 ]; then - man git -else - local al - if al=$(git config --get "alias.$1"); then - 1=${al%% *} - fi - man git-$1 -fi +git help ${1:-git} diff --git a/Functions/Misc/run-help-ip b/Functions/Misc/run-help-ip index 8807f9ef1..b811ce352 100644 --- a/Functions/Misc/run-help-ip +++ b/Functions/Misc/run-help-ip @@ -14,10 +14,6 @@ if ! man -w ip-address >/dev/null 2>&1; then return fi -while [[ $# != 0 && $1 == -* ]]; do - shift -done - case $1 in (addrl*) man ip-addrlabel ;; (a*) man ip-address ;; diff --git a/Functions/Misc/run-help-p4 b/Functions/Misc/run-help-p4 index 662ce94fe..e48a4d068 100644 --- a/Functions/Misc/run-help-p4 +++ b/Functions/Misc/run-help-p4 @@ -2,4 +2,4 @@ if (( ! $# )); then p4 help commands else p4 help $1 -fi | ${=PAGER:-less} +fi | ${=PAGER:-more} diff --git a/Functions/Misc/run-help-svk b/Functions/Misc/run-help-svk index 92438a53f..782538246 100644 --- a/Functions/Misc/run-help-svk +++ b/Functions/Misc/run-help-svk @@ -1 +1 @@ -svk help ${${@:#-*}[1]} | ${=PAGER:-more} +svk help $1 | ${=PAGER:-more} diff --git a/Functions/Misc/run-help-svn b/Functions/Misc/run-help-svn index 5d1068588..d55a493a6 100644 --- a/Functions/Misc/run-help-svn +++ b/Functions/Misc/run-help-svn @@ -1 +1 @@ -svn help ${${@:#-*}[1]} | ${=PAGER:-more} +svn help $1 | ${=PAGER:-more} diff --git a/Test/Z03run-help.ztst b/Test/Z03run-help.ztst new file mode 100644 index 000000000..2bb3bceed --- /dev/null +++ b/Test/Z03run-help.ztst @@ -0,0 +1,106 @@ +%prep + PAGER=cat + unalias run-help + autoload +X -Uz $PWD/../Functions/Misc/run-help* + builtin() { + case "$1 $2" in + ( 'getln cmd_args' ) + cmd_args="$BUFFER_STACK" + ;; + ( 'print -z' ) + ;; + ( 'whence -va' ) + print -l "$3 is WHENCE:{$3}" + ;; + ( * ) + eval $@ + ;; + esac + } + man() { + [[ $1 == -w && -n $NO_SUBCMD_MANUALS ]] && + return 1 + print "MAN:{${(qq)@}}" + } + git svn () { + print "${(U)0}:{${(qq)@}}" + } + + +%test + + BUFFER_STACK='btrfs --help' + run-help btrfs +0:btrfs with option flag, no subcmd +>btrfs is WHENCE:{btrfs} +>MAN:{'btrfs'} + + BUFFER_STACK='btrfs subvolume snapshot –r /btrfs/SV1 /btrfs/SV1-rosnap' + run-help btrfs +0:btrfs with subcmd +>btrfs is WHENCE:{btrfs} +>MAN:{'btrfs-subvolume'} + + BUFFER_STACK="sudo $BUFFER_STACK" + run-help btrfs +0:sudo btrfs with subcmd +>btrfs is WHENCE:{btrfs} +>MAN:{'btrfs-subvolume'} + + BUFFER_STACK='ip addr add 192.168.50.5 dev eth1' + run-help ip +0:ip with subcmd +>ip is WHENCE:{ip} +>MAN:{'ip-address'} + + NO_SUBCMD_MANUALS=1 + run-help ip + unset NO_SUBCMD_MANUALS +0:ip with subcmd, but no subcmd manuals +>ip is WHENCE:{ip} +>MAN:{'ip'} + + BUFFER_STACK='ip -s -s link ls up' + run-help ip +0:ip with options and subcmd +>ip is WHENCE:{ip} +>MAN:{'ip-link'} + + BUFFER_STACK="sudo $BUFFER_STACK" + run-help ip +0:sudo ip with options and subcmd +>ip is WHENCE:{ip} +>MAN:{'ip-link'} + + BUFFER_STACK='svn -vq' + run-help svn +0:svn with options +>svn is WHENCE:{svn} +>SVN:{'help'} + + BUFFER_STACK+=' commit -m "log messages"' + run-help svn +0:svn with options and subcmd +>svn is WHENCE:{svn} +>SVN:{'help' 'commit'} + + BUFFER_STACK='git --exec-path' + run-help git +0:git with option +>git is WHENCE:{git} +>GIT:{'help' 'git'} + + BUFFER_STACK='git -C $PWD/.. difftool --no-prompt --tool opendiff --dir-diff' + run-help git +0:git with option, file & subcmd +>git is WHENCE:{git} +>GIT:{'help' 'difftool'} + + BUFFER_STACK='git -c http.proxy=someproxy clone https://github.com/user/repo.git' + run-help git +0:git with option, assignment & subcmd +>git is WHENCE:{git} +>GIT:{'help' 'clone'} + + +%clean -- cgit v1.2.3 From bb61da36aaeeaa70413cdf5bc66d7a71194f93e5 Mon Sep 17 00:00:00 2001 From: Stephane Chazelas Date: Mon, 6 Sep 2021 14:43:01 -0700 Subject: 45180: clarify doc for POSIX EREs, fix an issue with PCRE when the replacement was empty or generated more than one element --- ChangeLog | 5 +++ Doc/Zsh/contrib.yo | 5 ++- Functions/Example/zpgrep | 15 +++++-- Functions/Misc/regexp-replace | 102 +++++++++++++++++++++++++++++++----------- 4 files changed, 95 insertions(+), 32 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 4eea4b614..eb75cf235 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-09-06 Bart Schaefer + * Stephane Chazelas: 45180: Doc/Zsh/contrib.yo, + Functions/Example/zpgrep, Functions/Misc/regexp-replace: clarify + doc for POSIX EREs, fix an issue with PCRE when the replacement + was empty or generated more than one element + * zeurkous: 49154: Doc/Zsh/exec.yo: clarify status on exec failure * Marlon Richert: 49378: Src/parse.c: skip check for collision diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index e74528341..94059eff6 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -4335,7 +4335,7 @@ See also the tt(pager), tt(prompt) and tt(rprompt) styles below. findex(regexp-replace) item(tt(regexp-replace) var(var) var(regexp) var(replace))( Use regular expressions to perform a global search and replace operation -on a variable. POSIX extended regular expressions are used, +on a variable. POSIX extended regular expressions (ERE) are used, unless the option tt(RE_MATCH_PCRE) has been set, in which case Perl-compatible regular expressions are used (this requires the shell to be linked against the tt(pcre) @@ -4353,6 +4353,9 @@ and arithmetic expressions which will be replaced: in particular, a reference to tt($MATCH) will be replaced by the text matched by the pattern. The return status is 0 if at least one match was performed, else 1. + +Note that if using POSIX EREs, the tt(^) or word boundary operators +(where available) may not work properly. ) findex(run-help) item(tt(run-help) var(cmd))( diff --git a/Functions/Example/zpgrep b/Functions/Example/zpgrep index 8b1edaa1c..556e58cd6 100644 --- a/Functions/Example/zpgrep +++ b/Functions/Example/zpgrep @@ -2,24 +2,31 @@ # zpgrep() { -local file pattern +local file pattern ret pattern=$1 shift +ret=1 if ((! ARGC)) then set -- - fi -pcre_compile $pattern +zmodload zsh/pcre || return +pcre_compile -- "$pattern" pcre_study for file do if [[ "$file" == - ]] then - while read -u0 buf; do pcre_match $buf && print $buf; done + while IFS= read -ru0 buf; do + pcre_match -- "$buf" && ret=0 && print -r -- "$buf" + done else - while read -u0 buf; do pcre_match $buf && print $buf; done < "$file" + while IFS= read -ru0 buf; do + pcre_match -- "$buf" && ret=0 && print -r -- "$buf" + done < "$file" fi done +return "$ret" } diff --git a/Functions/Misc/regexp-replace b/Functions/Misc/regexp-replace index dec105524..0d5948075 100644 --- a/Functions/Misc/regexp-replace +++ b/Functions/Misc/regexp-replace @@ -8,36 +8,84 @@ # $ and backtick substitutions; in particular, $MATCH will be replaced # by the portion of the string matched by the regular expression. -integer pcre +# we use positional parameters instead of variables to avoid +# clashing with the user's variable. Make sure we start with 3 and only +# 3 elements: +argv=("$1" "$2" "$3") -[[ -o re_match_pcre ]] && pcre=1 +# $4 records whether pcre is enabled as that information would otherwise +# be lost after emulate -L zsh +4=0 +[[ -o re_match_pcre ]] && 4=1 emulate -L zsh -(( pcre )) && setopt re_match_pcre - -# $4 is the string to be matched -4=${(P)1} -# $5 is the final string -5= -# 6 indicates if we made a change -6= + + local MATCH MBEGIN MEND local -a match mbegin mend -while [[ -n $4 ]]; do - if [[ $4 =~ $2 ]]; then - # append initial part and subsituted match - 5+=${4[1,MBEGIN-1]}${(e)3} - # truncate remaining string - 4=${4[MEND+1,-1]} - # indicate we did something - 6=1 - else - break - fi -done -5+=$4 - -eval ${1}=${(q)5} -# status 0 if we did something, else 1. -[[ -n $6 ]] +if (( $4 )); then + # if using pcre, we're using pcre_match and a running offset + # That's needed for ^, \A, \b, and look-behind operators to work + # properly. + + zmodload zsh/pcre || return 2 + pcre_compile -- "$2" && pcre_study || return 2 + + # $4 is the current *byte* offset, $5, $6 reserved for later use + 4=0 6= + + local ZPCRE_OP + while pcre_match -b -n $4 -- "${(P)1}"; do + # append offsets and computed replacement to the array + # we need to perform the evaluation in a scalar assignment so that if + # it generates an array, the elements are converted to string (by + # joining with the first chararacter of $IFS as usual) + 5=${(e)3} + argv+=(${(s: :)ZPCRE_OP} "$5") + + # for 0-width matches, increase offset by 1 to avoid + # infinite loop + 4=$((argv[-2] + (argv[-3] == argv[-2]))) + done + + (($# > 6)) || return # no match + + set +o multibyte + + # $5 contains the result, $6 the current offset + 5= 6=1 + for 2 3 4 in "$@[7,-1]"; do + 5+=${(P)1[$6,$2]}$4 + 6=$(($3 + 1)) + done + 5+=${(P)1[$6,-1]} +else + # in ERE, we can't use an offset so ^, (and \<, \b, \B, [[:<:]] where + # available) won't work properly. + + # $4 is the string to be matched + 4=${(P)1} + + while [[ -n $4 ]]; do + if [[ $4 =~ $2 ]]; then + # append initial part and substituted match + 5+=${4[1,MBEGIN-1]}${(e)3} + # truncate remaining string + if ((MEND < MBEGIN)); then + # zero-width match, skip one character for the next match + ((MEND++)) + 5+=${4[1]} + fi + 4=${4[MEND+1,-1]} + # indicate we did something + 6=1 + else + break + fi + done + [[ -n $6 ]] || return # no match + 5+=$4 +fi + +eval $1=\$5 -- cgit v1.2.3 From 356dcb20cef387a5eea5f8fcbfe123b24e3bb928 Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Fri, 12 Nov 2021 23:33:37 +0200 Subject: github #82: Fix typos --- ChangeLog | 11 +++++++++++ Completion/BSD/Command/_kdump | 2 +- Completion/BSD/Command/_ktrace | 2 +- Completion/Debian/Command/_aptitude | 2 +- Completion/Linux/Command/_modutils | 2 +- Completion/Linux/Command/_sysstat | 2 +- Completion/Mandriva/Command/_urpmi | 2 +- Completion/Redhat/Command/_dnf | 2 +- Completion/Unix/Command/_ansible | 2 +- Completion/Unix/Command/_gcc | 4 ++-- Etc/FAQ.yo | 4 ++-- Etc/NEWS-4.3 | 2 +- Functions/Chpwd/cdr | 2 +- Functions/Misc/regexp-replace | 2 +- Functions/Newuser/zsh-newuser-install | 2 +- NEWS | 2 +- Src/Zle/compmatch.c | 8 ++++---- Src/exec.c | 2 +- Src/math.c | 4 ++-- Test/A01grammar.ztst | 2 +- Test/B12limit.ztst | 2 +- 21 files changed, 37 insertions(+), 26 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index de6bbb08b..1dfe2e39a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2021-11-12 Oliver Kiddle + * github #82: Dimitris Apostolou: Completion/BSD/Command/_kdump, + Completion/Redhat/Command/_dnf, Completion/BSD/Command/_ktrace, + Completion/Linux/Command/_modutils, Test/A01grammar.ztst, + Completion/Linux/Command/_sysstat, Functions/Chpwd/cdr, + Completion/Unix/Command/_ansible, Completion/Unix/Command/_gcc, + Completion/Mandriva/Command/_urpmi, Etc/NEWS-4.3, + Completion/Debian/Command/_aptitude, Etc/FAQ.yo, + Functions/Newuser/zsh-newuser-install, NEWS, + Functions/Misc/regexp-replace, Src/Zle/compmatch.c, + Src/exec.c, Src/math.c, Test/B12limit.ztst: fix typos + * Marlon: 49572: Completion/Base/Completer/_expand, Test/Y01completion.ztst: Let _expand preserve array form w/out zstyle glob diff --git a/Completion/BSD/Command/_kdump b/Completion/BSD/Command/_kdump index 946296a75..e5c7c4cce 100644 --- a/Completion/BSD/Command/_kdump +++ b/Completion/BSD/Command/_kdump @@ -30,7 +30,7 @@ local args=( '-f+[use the specified file (- for stdin)]:dump file:_files' '-l[loop reading the trace file]' '-m+[maximum I/O bytes to display]:max data bytes:' - '-n[supress ad hoc translations]' + '-n[suppress ad hoc translations]' '-p+[show output only for the specified pid]: :_kdump_pid' '(-E -T)-R[display relative timestamps]' '(-E -R )-T[display absolute timestamps]' diff --git a/Completion/BSD/Command/_ktrace b/Completion/BSD/Command/_ktrace index 13c11f15d..9613ba2bf 100644 --- a/Completion/BSD/Command/_ktrace +++ b/Completion/BSD/Command/_ktrace @@ -4,7 +4,7 @@ local args=( '-a[append to the trace file]' '(*)-C[disable tracing on all user owned processes or all processes if executed by root]' '-c[clear the trace points]' - '-d[trace current decendants]' + '-d[trace current descendants]' '-f+[log trace to specified file]:trace file:_files' '(-p *)-g+[enable/disable tracing on specified process group]:pgid:_pgids' '-i[inherit trace flags on future children]' diff --git a/Completion/Debian/Command/_aptitude b/Completion/Debian/Command/_aptitude index 91d233f11..5b10adb80 100644 --- a/Completion/Debian/Command/_aptitude +++ b/Completion/Debian/Command/_aptitude @@ -15,7 +15,7 @@ _arguments -C \ '(-F --display-format)'{-F,--display-format}'[specify output format for search command]:format:->format-strings' \ '--group-by=[control how the versions command groups its output]:grouping:(archive auto none package source-package source-version)' \ '--log-file=[specify output log file]:file:_files' \ - '*--log-level=[specify mimimum message level to log]:level:compadd -o nosort off fatal error warn info debug trace' \ + '*--log-level=[specify minimum message level to log]:level:compadd -o nosort off fatal error warn info debug trace' \ '--log-resolver[set some standard log levels related to the resolver]' \ '(--allow-new-installs)--no-new-installs[prevent safe-upgrade from installing any new packages]' \ '(--allow-new-upgrades)--no-new-upgrades[prevent safe-upgrade from upgrading packages regardless]' \ diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils index 1205f2506..3e46130a2 100644 --- a/Completion/Linux/Command/_modutils +++ b/Completion/Linux/Command/_modutils @@ -105,7 +105,7 @@ _modutils() { loaded-modules|loadable-modules) if [[ -r /proc/modules ]]; then loaded_modules=(${${(f)"$(tp != CPAT_ANY || wp->tp != CPAT_ANY) @@ -1496,7 +1496,7 @@ pattern_match_restrict(Cpattern p, Cpattern wp, convchar_t *wsc, int wsclen, * characters. We're matching two patterns against * one another to generate a character to insert. * This is a bit too psychedelic, so I'm going to - * bale out now. See you on the ground. + * bail out now. See you on the ground. */ return 0; } @@ -1564,7 +1564,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws) c = unmeta_one(s, &len); /* * If either is "?", they match each other; no further tests. - * Apply this even if the character wasn't convertable; + * Apply this even if the character wasn't convertible; * there's no point trying to be clever in that case. */ if (p->tp != CPAT_ANY || wp->tp != CPAT_ANY) @@ -1934,7 +1934,7 @@ bld_line(Cmatcher mp, ZLE_STRING_T line, char *mword, char *word, * This is the nightmare case: we have line and * and word matchers and some pattern which restricts * the value on the line without us knowing exactly - * what it is. Despatch to the special function + * what it is. Dispatch to the special function * for that. */ if (mp && !mp->flags && mp->wlen <= wlen && diff --git a/Src/exec.c b/Src/exec.c index 1f23a862d..1860a10ed 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3954,7 +3954,7 @@ execcmd_exec(Estate state, Execcmd_params eparams, if (type == WC_AUTOFN) { /* * We pre-loaded this to get any redirs. - * So we execuate a simplified function here. + * So we execute a simplified function here. */ lastval = execautofn_basic(state, do_exec); } else diff --git a/Src/math.c b/Src/math.c index ade02d80c..4f24361a4 100644 --- a/Src/math.c +++ b/Src/math.c @@ -162,7 +162,7 @@ static int unary = 1; #define TOKCOUNT 53 /* - * Opeator recedences: in reverse order, i.e. lower number, high precedence. + * Operator precedences: in reverse order, i.e. lower number, high precedence. * These are the C precedences. * * 0 Non-operators: NUM (numeric constant), ID (identifier), @@ -219,7 +219,7 @@ static int c_prec[TOKCOUNT] = }; /* - * Opeator recedences: in reverse order, i.e. lower number, high precedence. + * Operator precedences: in reverse order, i.e. lower number, high precedence. * These are the default zsh precedences. * * 0 Non-operators: NUM (numeric constant), ID (identifier), diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index c114ff103..ac39a4eea 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -922,7 +922,7 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci x=1 x=2 | echo $x echo $x -0:Assignment-only current shell commands in LHS of pipelin +0:Assignment-only current shell commands in LHS of pipeline >1 >1 diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst index 48d33e6e3..9dce59824 100644 --- a/Test/B12limit.ztst +++ b/Test/B12limit.ztst @@ -11,7 +11,7 @@ %test limit | grep UNKNOWN || print OK -0:Check if there is unknown resouce(s) in the system +0:Check if there is unknown resource(s) in the system >OK F:A failure here does not indicate any error in zsh. It just means there F:is a resource in your system that is unknown to zsh developers. Please -- cgit v1.2.3 From 2876c25a28b8052d6683027998cc118fc9b50157 Mon Sep 17 00:00:00 2001 From: Matt Alexander Date: Sat, 1 Jan 2022 14:47:53 -0800 Subject: 49667: Include US spelling of "grey" ("gray") Co-authored-by: Daniel Shahaf --- ChangeLog | 4 ++++ Functions/Misc/colors | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 2a1db9cc1..c7b2cb59c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2022-01-01 Bart Schaefer + + * Matt Alexander: 49667: Functions/Misc/colors: include "gray" + 2021-12-29 Oliver Kiddle * Aaron Schrab: 49664: Completion/Unix/Command/_git: diff --git a/Functions/Misc/colors b/Functions/Misc/colors index b221e6688..5e9d77d10 100644 --- a/Functions/Misc/colors +++ b/Functions/Misc/colors @@ -83,9 +83,11 @@ for k in ${color[(I)3?]}; do color[fg-${color[$k]}]=$k; done # This is inaccurate, but the prompt theme system needs it. -color[grey]=${color[black]} -color[fg-grey]=${color[grey]} -color[bg-grey]=${color[bg-black]} +for k in grey gray; do + color[$k]=${color[black]} + color[fg-$k]=${color[$k]} + color[bg-$k]=${color[bg-black]} +done # Assistance for the color-blind. -- cgit v1.2.3 From 8460d75869fcddaaa2a6beed9b4d78c60a9fed19 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 25 Jan 2022 08:23:27 +0000 Subject: 49709: vcs_info hg: Keep $HGPLAIN set for hooks if it had been set outside vcs_info If someone does 'HGPLAIN=1 vcs_info', any vcs_info hooks should be called with HGPLAIN set. Declaring it 'local' broke that. --- ChangeLog | 6 ++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 1bc824b4a..200c28d1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-01-25 Daniel Shahaf + + * 49709: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: + vcs_info hg: Keep $HGPLAIN set for hooks if it had been set + outside vcs_info + 2022-01-23 Andreas Schneider * gitlab !17: Completion/Unix/Command/_quilt: Add missing diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 2806aee1d..b123e2270 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -56,7 +56,6 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" \ "check-for-changes" || hgid_args+=( -r. ) - local HGPLAIN HGPLAIN=1 ${vcs_comm[cmd]} ${(z)hgid_args} 2> /dev/null \ | read -r r_csetid r_lrev fi -- cgit v1.2.3 From b99599b4f48325e104704eb8f077b81e938f50c7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 27 Jan 2022 16:41:54 +0000 Subject: unposted: vcs_info quilt: Remove a no-op variable assignment --- ChangeLog | 5 +++++ Functions/VCS_Info/VCS_INFO_quilt | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 200c28d1d..7441db2df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-01-27 Daniel Shahaf + + * unposted: Functions/VCS_Info/VCS_INFO_quilt: vcs_info quilt: + Remove a no-op variable assignment + 2022-01-25 Daniel Shahaf * 49709: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index 264dbed0e..06feb4cce 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -133,7 +133,6 @@ function VCS_INFO_quilt-patch2subject() { # This zstyle call needs to be moved further up if `quilt' needs # to be run in more places than this one. zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt' - quilt_env=() if [ -z "$patches" ]; then zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" if [[ "${patches}" != /* ]]; then -- cgit v1.2.3 From e52062170a41dd2ba5a03aef22af0545cbc1d58c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 27 Jan 2022 17:58:13 +0000 Subject: 49722: vcs_info quilt: Refactor for readability. No functional change. --- ChangeLog | 3 +++ Functions/VCS_Info/VCS_INFO_quilt | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 328844766..750f8d350 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2022-01-29 Daniel Shahaf + * 49722: Functions/VCS_Info/VCS_INFO_quilt: vcs_info quilt: + Refactor for readability. No functional change. + * 49715: Completion/Unix/Command/_subversion: add: Complete target arguments to this subcommand diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index 06feb4cce..22212171a 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -92,7 +92,7 @@ function VCS_INFO_quilt-patch2subject() { emulate -L zsh setopt extendedglob local mode="$1" - local patches pc tmp qstring root + local patches pc qstring root local -i ret local context local -a applied unapplied applied_string unapplied_string quiltcommand quilt_env @@ -135,12 +135,13 @@ function VCS_INFO_quilt-patch2subject() { zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt' if [ -z "$patches" ]; then zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" + : ${patches:="patches"} if [[ "${patches}" != /* ]]; then - tmp=${patches:-patches} - VCS_INFO_quilt-dirfind "${tmp}" - ret=$? patches=$REPLY - (( ret )) && return ${ret} - patches=${patches}/${tmp} + if VCS_INFO_quilt-dirfind "${patches}"; then + patches="$REPLY/${patches}" + else + return $? + fi else [[ -d ${patches} ]] || return 1 fi -- cgit v1.2.3 From ee5e3d0c9d07ce3297959b89f96238dbff9b6400 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 27 Jan 2022 17:58:14 +0000 Subject: 49723: vcs_info quilt: Use quilt-patch-dir and ${QUILT_PATCHES} even when get-unapplied hasn't been set This affects the post-quilt hook. Before this patch, if no patches have been applied and get-unapplied hasn't been set, the second argument to that hook would undergo null elision. The generation of patch subjects for the gen-applied-string, gen-unapplied-string, and set-patch-format hooks was unaffected since it was guarded by [[ -n $patches ]]. --- ChangeLog | 4 ++++ Functions/VCS_Info/VCS_INFO_quilt | 45 +++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 750f8d350..1aa704c23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2022-01-29 Daniel Shahaf + * 49723: Functions/VCS_Info/VCS_INFO_quilt: vcs_info quilt: + Use quilt-patch-dir and ${QUILT_PATCHES} even when get-unapplied + hasn't been set + * 49722: Functions/VCS_Info/VCS_INFO_quilt: vcs_info quilt: Refactor for readability. No functional change. diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index 22212171a..ee242f552 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -113,9 +113,12 @@ function VCS_INFO_quilt-patch2subject() { ;; esac - VCS_INFO_quilt-dirfind .pc .version - ret=$? pc=$REPLY - if (( ret == 0 )); then + # Look for the patches directory. + # + # 1. Check if there's a .pc/.version file in a parent dir. If so, use the + # patches dir from the corresponding .pc/.quilt_patches. + if VCS_INFO_quilt-dirfind .pc .version; then + pc=$REPLY [[ ${quiltmode} == 'standalone' ]] && root=${pc} pc=${pc}/.pc if [[ -e ${pc}/applied-patches ]]; then @@ -128,25 +131,27 @@ function VCS_INFO_quilt-patch2subject() { fi patches=$(<$pc/.quilt_patches) patches=`builtin cd -q "${pc:h}" && print -r - ${patches:P}` + # 2. Else, locate a patches dir using the style settings. + else + zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" + : ${patches:="patches"} + if [[ "${patches}" != /* ]]; then + if VCS_INFO_quilt-dirfind "${patches}"; then + patches=$REPLY/$patches + else + return $? + fi + else + [[ -d ${patches} ]] || return 1 + fi + quilt_env+=(QUILT_PATCHES="$patches") fi + # At this point, $patches is set and points to an existing directory. + if zstyle -t "${context}" get-unapplied; then # This zstyle call needs to be moved further up if `quilt' needs # to be run in more places than this one. zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt' - if [ -z "$patches" ]; then - zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}" - : ${patches:="patches"} - if [[ "${patches}" != /* ]]; then - if VCS_INFO_quilt-dirfind "${patches}"; then - patches="$REPLY/${patches}" - else - return $? - fi - else - [[ -d ${patches} ]] || return 1 - fi - quilt_env+=(QUILT_PATCHES="$patches") - fi unapplied=( ${(f)"$(if (( $+quilt_env[1] )); then export ${quilt_env[@]}; fi $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} ) unapplied=( ${unapplied:#} ) @@ -154,8 +159,7 @@ function VCS_INFO_quilt-patch2subject() { unapplied=() fi - if [[ -n $patches ]]; then - () { + { local i for ((i=1; i<=$#applied; i++)); do if VCS_INFO_quilt-patch2subject "$patches/$applied[$i]" && (( $+REPLY )) @@ -173,8 +177,7 @@ function VCS_INFO_quilt-patch2subject() { unapplied[$i]+=" ?" fi done - } - fi + } VCS_INFO_set-patch-format 'applied' 'applied_string' \ 'unapplied' 'unapplied_string' \ -- cgit v1.2.3 From c055c6464de20da13a6c805f017543f94b6e0ca9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 11:08:21 +0000 Subject: unposted: vcs_info: Add Vim modelines ... for consistency with all other vcs_info function files. --- ChangeLog | 5 +++++ Functions/VCS_Info/VCS_INFO_patch2subject | 2 ++ Functions/VCS_Info/VCS_INFO_set-branch-format | 2 ++ Functions/VCS_Info/VCS_INFO_set-patch-format | 2 ++ Misc/vcs_info-examples | 2 ++ 5 files changed, 13 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 1aa704c23..92646df79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-01-29 Daniel Shahaf + * unposted: Functions/VCS_Info/VCS_INFO_patch2subject, + Functions/VCS_Info/VCS_INFO_set-branch-format, + Functions/VCS_Info/VCS_INFO_set-patch-format: vcs_info: Add + Vim modelines + * 49723: Functions/VCS_Info/VCS_INFO_quilt: vcs_info quilt: Use quilt-patch-dir and ${QUILT_PATCHES} even when get-unapplied hasn't been set diff --git a/Functions/VCS_Info/VCS_INFO_patch2subject b/Functions/VCS_Info/VCS_INFO_patch2subject index a467edcdb..5aa9efd23 100644 --- a/Functions/VCS_Info/VCS_INFO_patch2subject +++ b/Functions/VCS_Info/VCS_INFO_patch2subject @@ -1,3 +1,5 @@ +## vim:ft=zsh +# # This function takes as an argument a filename of a patch and sets $REPLY to # a single-line "subject", or unsets it if no subject could be extracted. { diff --git a/Functions/VCS_Info/VCS_INFO_set-branch-format b/Functions/VCS_Info/VCS_INFO_set-branch-format index 8cff51b9a..cbab60e29 100644 --- a/Functions/VCS_Info/VCS_INFO_set-branch-format +++ b/Functions/VCS_Info/VCS_INFO_set-branch-format @@ -1,3 +1,5 @@ +## vim:ft=zsh +# # A function for calling the branch-format hook # # Return the value to use in REPLY diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format index e387110a2..c35b695c3 100644 --- a/Functions/VCS_Info/VCS_INFO_set-patch-format +++ b/Functions/VCS_Info/VCS_INFO_set-patch-format @@ -1,3 +1,5 @@ +## vim:ft=zsh +# # This function is the common guts of the gen-applied-string / # gen-unapplied-string / set-patch-format dance of several backends. # diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples index c2b02a2ac..94c47278d 100644 --- a/Misc/vcs_info-examples +++ b/Misc/vcs_info-examples @@ -1,3 +1,5 @@ +## vim:ft=zsh +# # A collection of vcs_info usage examples ### Running vcs_info ######################################################### -- cgit v1.2.3 From 42f1e99f816d7b8d2376caea69d0acd85ee729a4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 12:47:54 +0000 Subject: unposted: vcs_info git: Deconfuse $EDITOR Work around . --- ChangeLog | 3 +++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 92646df79..79fbec278 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2022-01-29 Daniel Shahaf + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: Deconfuse $EDITOR + * unposted: Functions/VCS_Info/VCS_INFO_patch2subject, Functions/VCS_Info/VCS_INFO_set-branch-format, Functions/VCS_Info/VCS_INFO_set-patch-format: vcs_info: Add diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index eb04d4b41..ba588c874 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -207,7 +207,7 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then # Comment line. Skip. return 0 ;; - ((p|pick|e|edit|r|reword|f|fixup|s|squash)' '*) + (''(p|pick|e|edit|r|reword|f|fixup|s|squash)' '*) # The line is of the form "pick $hash $subject". # Just strip the verb and we're good to go. p=${p#* } @@ -230,7 +230,7 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then p="${p%% *} ?" fi ;; - ((x|exec) *) + (''(x|exec) *) # The line is of the form 'exec foo bar baz' where 'foo bar # baz' is a shell command. There's no way to map _that_ to # "$hash $subject", but I hope this counts as making an effort. -- cgit v1.2.3 From 10ee9e5bd74367dcbf598f27d54ceab43ca68374 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 13:06:50 +0000 Subject: unposted: vcs_info git: Add a missing guard against redefining a function. --- ChangeLog | 3 +++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 1 + 2 files changed, 4 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 79fbec278..ff9bc0bce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2022-01-29 Daniel Shahaf + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: + vcs_info git: Add a missing guard against redefining a function. + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: Deconfuse $EDITOR diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index ba588c874..fe084dffb 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -196,6 +196,7 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then # 'git rebase -i' patchdir="${gitdir}/rebase-merge" local p + (( ${+functions[VCS_INFO_git_map_rebase_line_to_hash_and_subject]} )) || VCS_INFO_git_map_rebase_line_to_hash_and_subject() { local p=$1 unset REPLY -- cgit v1.2.3 From 75c3664a62010dfae620d77930f8ea5aae78b602 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 13:10:26 +0000 Subject: unposted: vcs_info git: Teach the rebase-apply test case generator to also generate rebase-merge test cases --- ChangeLog | 5 +++++ Functions/VCS_Info/test-repo-git-rebase-apply | 12 +++++++++++- Functions/VCS_Info/test-repo-git-rebase-merge | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 120000 Functions/VCS_Info/test-repo-git-rebase-merge (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index ff9bc0bce..57c26fb38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-01-29 Daniel Shahaf + * unposted: Functions/VCS_Info/test-repo-git-rebase-apply, + Functions/VCS_Info/test-repo-git-rebase-merge: vcs_info git: + Teach the rebase-apply test case generator to also generate + rebase-merge test cases + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: Add a missing guard against redefining a function. diff --git a/Functions/VCS_Info/test-repo-git-rebase-apply b/Functions/VCS_Info/test-repo-git-rebase-apply index cb4ea4f58..ce49690cd 100755 --- a/Functions/VCS_Info/test-repo-git-rebase-apply +++ b/Functions/VCS_Info/test-repo-git-rebase-apply @@ -44,6 +44,16 @@ append_lines 7 8 9 # Specify a rebase that would create the history [1,3,4,5,6,7,8,9]. # This will conflict because r7 depends on r2 which is not included. git checkout -b myref -git rebase --onto=rebase_onto_this rebase_from_this myref +case $0:P in + (*/test-repo-git-rebase-apply) + git rebase --onto=rebase_onto_this rebase_from_this myref + ;; + (*/test-repo-git-rebase-merge) + git -c core.editor=true rebase -i --onto=rebase_onto_this rebase_from_this myref + ;; + (*) + echo >&2 "$0: unrecognized basename" + ;; +esac diff --git a/Functions/VCS_Info/test-repo-git-rebase-merge b/Functions/VCS_Info/test-repo-git-rebase-merge new file mode 120000 index 000000000..fce9e9178 --- /dev/null +++ b/Functions/VCS_Info/test-repo-git-rebase-merge @@ -0,0 +1 @@ +test-repo-git-rebase-apply \ No newline at end of file -- cgit v1.2.3 From 2b66ed35b014b3d93f37a67951c2bd00916c9370 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 17 Jan 2022 22:58:13 +0100 Subject: security/82: VCS_Info: Fix typo in hook_com[base-name_orig] assignment Tweaked per discussion in security/90, security/91 (cherry picked from commit b34d33e3b3c5ae30e8315111f07634c1e7507531) --- ChangeLog | 4 ++++ Functions/VCS_Info/VCS_INFO_formats | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 255a3dbe8..5deb9f8d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2022-02-12 dana + * Marc Cornellà: security/82 (tweaked): + Functions/VCS_Info/VCS_INFO_formats: Fix typo in + hook_com[base-name_orig] assignment + * CVE-2021-45444: NEWS, README: Document preceding two changes * Marc Cornellà: security/89: diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats index e0e1dc738..daf169f26 100644 --- a/Functions/VCS_Info/VCS_INFO_formats +++ b/Functions/VCS_Info/VCS_INFO_formats @@ -28,7 +28,7 @@ hook_com=( vcs_orig "${vcs}" ) hook_com[base-name]="${${hook_com[base]}:t}" -hook_com[base-name_orig]="${hook_com[base_name]}" +hook_com[base-name_orig]="${hook_com[base-name]}" hook_com[subdir]="$(VCS_INFO_reposub ${hook_com[base]})" hook_com[subdir_orig]="${hook_com[subdir]}" -- cgit v1.2.3 From b8b7d9b46ac54c4494ec74b2b7ca4c06861eb75d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 20 Feb 2022 09:45:39 +0000 Subject: unposted: vcs_info hg mg (with get-unapplied set): Stop leaking a variable to global scope --- ChangeLog | 6 ++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 1fd675c14..6576ec634 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-02-20 Daniel Shahaf + + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: + vcs_info hg mg (with get-unapplied set): Stop leaking a variable + to global scope + 2022-02-16 Jun-ichi Takimoto * 49757 (sourceforge #1): samcarter: Completion/Unix/Command/_tex: diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index b123e2270..97086670c 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -14,7 +14,7 @@ local hgbase bmfile branchfile topicfile rebasefile dirstatefile mqseriesfile \ local -a hgid_args defrevformat defbranchformat \ hgbmarks mqpatches mqguards mqunapplied hgmisc \ - i_patchguards i_negguards i_posguards + i_patch i_patchguards i_negguards i_posguards local -A hook_com -- cgit v1.2.3 From 80389df48067bab3711ad1604bc9554d08fb9994 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 16:15:25 +0000 Subject: 49727 (+ comment): vcs_info quilt: Pass the patches dir path to the gen-applied-string, gen-unapplied-string, and set-patch-format hooks I use that in my gen-applied-string hook. --- ChangeLog | 8 ++++++++ Doc/Zsh/contrib.yo | 15 +++++++++++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 2 +- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 2 +- Functions/VCS_Info/VCS_INFO_quilt | 7 ++++++- Functions/VCS_Info/VCS_INFO_set-patch-format | 8 +++++++- 6 files changed, 38 insertions(+), 4 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 6576ec634..a856cc47f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2022-02-20 Daniel Shahaf + * 49727 (+ comment): Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_git, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, + Functions/VCS_Info/VCS_INFO_quilt, + Functions/VCS_Info/VCS_INFO_set-patch-format: vcs_info + quilt: Pass the patches dir path to the gen-applied-string, + gen-unapplied-string, and set-patch-format hooks + * unposted: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: vcs_info hg mg (with get-unapplied set): Stop leaking a variable to global scope diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index eb5bbafb2..0adef7334 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1669,6 +1669,11 @@ available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. This hook is, in concert with tt(set-patch-format), responsible for tt(%)-escaping that value for use in the prompt. (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) + +COMMENT(This paragraph is repeated above/below)\ +The tt(quilt) backend passes to this hook the inputs +tt(${hook_com[quilt-patches-dir]}) and, if it has been +determined, tt(${hook_com[quilt-pc-dir]}). ) item(tt(gen-unapplied-string))( Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with @@ -1687,6 +1692,11 @@ tt(patch-format) and tt(nopatch-format) styles. This hook is, in concert with tt(set-patch-format), responsible for tt(%)-escaping that value for use in the prompt. (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) + +COMMENT(This paragraph is repeated above/below)\ +The tt(quilt) backend passes to this hook the inputs +tt(${hook_com[quilt-patches-dir]}) and, if it has been +determined, tt(${hook_com[quilt-pc-dir]}). ) item(tt(gen-mqguards-string))( Called in the tt(hg) backend when tt(guards-string) is generated; the @@ -1769,6 +1779,11 @@ This hook is, in concert with the tt(gen-applied-string) or tt(gen-unapplied-string) hooks if they are defined, responsible for tt(%)-escaping the final tt(patch-format) value for use in the prompt. (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) + +COMMENT(This paragraph is repeated above/below)\ +The tt(quilt) backend passes to this hook the inputs +tt(${hook_com[quilt-patches-dir]}) and, if it has been +determined, tt(${hook_com[quilt-pc-dir]}). ) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_)var(N)tt(_)' message is set. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index fe084dffb..e45eebc8e 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -132,7 +132,7 @@ VCS_INFO_git_handle_patches () { VCS_INFO_set-patch-format 'git_patches_applied' 'git_applied_s' \ 'git_patches_unapplied' 'git_unapplied_s' \ ":vcs_info:${vcs}:${usercontext}:${rrn}" gitmsg \ - '' '' + '' '' '' gitmisc=$REPLY } diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 97086670c..e7123f0bf 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -225,7 +225,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ VCS_INFO_set-patch-format 'mqpatches' 'applied_string' \ 'mqunapplied' 'unapplied_string' \ ":vcs_info:${vcs}:${usercontext}:${rrn}" hgmqstring \ - extra_hook_com VCS_INFO_hg_extra_zformats + extra_hook_com VCS_INFO_hg_extra_zformats '' hgmqstring=$REPLY fi diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index ee242f552..ce5b41f24 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -179,10 +179,15 @@ function VCS_INFO_quilt-patch2subject() { done } + typeset -A quilt_extra_info=( + quilt-patches-dir ${patches} + ${pc:+"quilt-pc-dir"} $pc + ) + VCS_INFO_set-patch-format 'applied' 'applied_string' \ 'unapplied' 'unapplied_string' \ ${context} qstring \ - '' '' + quilt_extra_info '' quilt_extra_info qstring=$REPLY case ${mode} in diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format index c35b695c3..1c774a7f6 100644 --- a/Functions/VCS_Info/VCS_INFO_set-patch-format +++ b/Functions/VCS_Info/VCS_INFO_set-patch-format @@ -15,6 +15,8 @@ # $7 - name of an assoc parameter with extra $hook_com key-value pairs for the # set-patch-format hook invocation, or '' for none # $8 - name of a function that sets $reply to extra arguments for the patch-format zformat call, or '' for none +# $9 - name of an assoc parameter with extra $hook_com key-value pairs for the +# gen-applied-string & gen-unapplied-string hook invocations, or '' for none # # The expanded patch-format string is returned in $REPLY. # @@ -22,8 +24,10 @@ # - $hook_com is overwritten and the keys 'applied', 'applied-n', # 'unapplied', 'unapplied-n', 'all-n' are set. { + hook_com=() + local applied_needs_escaping='unknown' - local unapplied_needs_escaping='unknown' + hook_com+=( ${9:+"${(@kvP)9}"} ) if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then if (( ${(P)#1} )); then REPLY=${(P)1[1]} @@ -37,6 +41,8 @@ : ${(P)2::=$REPLY} hook_com=() + local unapplied_needs_escaping='unknown' + hook_com+=( ${9:+"${(@kvP)9}"} ) if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then REPLY=${(P)#3} unapplied_needs_escaping='yes' -- cgit v1.2.3 From 421f5d7f67976e369ef8613c455d8232e2326f3a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Jan 2022 16:15:26 +0000 Subject: 49728: vcs_info hg mq: Don't include applied patches in the unapplied patches For instance, with 4 applied patches, 5 unapplied patches, and no guards involved, the patch-format style would indicate 9 (= 4+5) unapplied patches and 4 applied patches. --- ChangeLog | 4 ++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 3 +++ 2 files changed, 7 insertions(+) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index a856cc47f..a3e6497c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2022-02-20 Daniel Shahaf + * 49728: Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: + vcs_info hg mq: Don't include applied patches in the unapplied + patches + * 49727 (+ comment): Doc/Zsh/contrib.yo, Functions/VCS_Info/Backends/VCS_INFO_get_data_git, Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index e7123f0bf..ea3798b81 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -183,6 +183,9 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ # Skip commented lines [[ ${i_patch} == [[:space:]]#"#"* ]] && continue + # Skip applied patches + (( ${+mqpatches[(re)${i_patch}]} )) && continue + # Separate negative and positive guards to more easily find the # intersection of active guards with patch guards i_patchguards=( ${(s: :)i_patchguards} ) -- cgit v1.2.3 From 28410bd5bc71fda6343b13c2b6abad06bd2eaaee Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 23 Feb 2022 19:45:43 +0100 Subject: promptinit: only exclude current theme from preview if no arguments are given --- ChangeLog | 5 +++++ Functions/Prompts/promptinit | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Functions') diff --git a/ChangeLog b/ChangeLog index 35e8693ac..fd2b2bb34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-03-08 Mikael Magnusson + + * 49773: Functions/Prompts/promptinit: promptinit: only exclude + current theme from preview if no arguments are given + 2022-03-06 Jun-ichi Takimoto * 49802 (+ 49804:Daniel): Test/W03jobparameters.ztst: pass diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 20503d78b..0c06699e8 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -73,7 +73,7 @@ set_prompt() { Options: -c Show currently selected theme and parameters -l List currently available prompt themes - -p [] Preview given themes (defaults to all) + -p [] Preview given themes (defaults to all except current theme) -h [] Display help (for given theme) -s Set and save theme Switch to new theme immediately (changes not saved) @@ -120,10 +120,9 @@ Use prompt -h for help on specific themes.' print $prompt_themes return ;; - p) preview=( $prompt_themes ) + p) preview=( ${prompt_themes:#$prompt_theme} ) (( $#* > 1 )) && preview=( "$@[2,-1]" ) for theme in $preview; do - [[ "$theme" == "$prompt_theme[*]" ]] && continue prompt_preview_safely "$=theme" done print -P "%b%f%k" -- cgit v1.2.3 From 67f932e7c5cfad02cdcc552dcd57e63536b7f965 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 27 Mar 2022 10:46:25 -0700 Subject: 49897: Eliminate reliance on $jobstates parameter, fix -P exit status check. --- Functions/Misc/zargs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'Functions') diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs index ecd69f7e4..81916a3ac 100644 --- a/Functions/Misc/zargs +++ b/Functions/Misc/zargs @@ -43,14 +43,12 @@ # than 127 for "command not found" so this function incorrectly returns # 123 in that case if used with zsh 4.0.x. # -# With the --max-procs option, zargs may not correctly capture the exit -# status of the backgrounded jobs, because of limitations of the "wait" -# builtin. If the zsh/parameter module is not available, the status is -# NEVER correctly returned, otherwise the status of the longest-running -# job in each batch is captured. +# Because of "wait" limitations, --max-procs spawns max-procs jobs, then +# waits for all of those, then spawns another batch, etc. # -# Also because of "wait" limitations, --max-procs spawns max-procs jobs, -# then waits for all of those, then spawns another batch, etc. +# The maximum number of parallel jobs for which exit status is available +# is determined by the sysconf CHILD_MAX parameter, which can't be read +# or changed from within the shell. # # Differences from POSIX xargs: # @@ -69,6 +67,9 @@ # -I/-L and implementations reportedly differ.) In zargs, -i/-I have # this behavior, as do -l/-L, but when -i/-I appear anywhere then -l/-L # are ignored (forced to 1). +# +# * The use of SIGUSR1 and SIGUSR2 to change the number of parallel jobs +# is not supported. # First, capture the current setopts as "sticky emulation" if zmodload zsh/parameter @@ -86,7 +87,7 @@ fi emulate -L zsh || return 1 local -a opts eof n s l P i -local ZARGS_VERSION="1.5" +local ZARGS_VERSION="1.7" if zparseopts -a opts -D -- \ -eof::=eof e::=eof \ @@ -264,17 +265,19 @@ if (( P != 1 && ARGC > 1 )) then # These setopts are necessary for "wait" on multiple jobs to work. setopt nonotify nomonitor - bg='&' - if zmodload -i zsh/parameter 2>/dev/null - then - wait='wait ${${jobstates[(R)running:*]/#*:/}/%=*/}' - else - wait='wait' - fi + local -a _zajobs + local j + bg='& _zajobs+=( $! )' + wait='wait' + analyze=' + for j in $_zajobs; do + wait $j + '"$analyze"' + done; _zajobs=()' fi -# Everything has to be in a subshell just in case of backgrounding jobs, -# so that we don't unintentionally "wait" for jobs of the parent shell. +# Everything has to be in a subshell so that we don't "wait" for any +# unrelated jobs of the parent shell. ( while ((ARGC)) -- cgit v1.2.3