From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29985 invoked from network); 20 Apr 2021 13:37:33 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Apr 2021 13:37:33 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618925853; b=aBiPiZw4GyM0vRLjgt6jILO98m1jWYUT9AWhxLBKFLLFzRQhooArlMkduHouBI5JR5gHRuKR+Q Us0Z18Jlnao6fyOcqJtqGyr1VzJLqZjtNhaI28Dn+sG3OxmpXBhqrdDld7u0eYe+oUuWc0Rdab E8Z8oP9IAWXaxOaE/rmolZhU6na6i4SxafjGiL09lr1GqIbdg+8I1OM958GAv6iWvetRTrbDwK UJblY/7LYg0xjUca/lKGyuutrSSvLLqKiD966DBa1O+dsqc7f03YkZHBjVgz/aoO0X1m1JKmQz psKmVXdwcd8kqfKTfBQQmlwyNda2kefMQr8gAhUVi3F7NQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f54.google.com) smtp.remote-ip=209.85.167.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1618925853; bh=MXgcj/ili0wDN0yHSxOADVdCMpmqWOqFuAQ5KMshYrA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:Date:Message-ID:Subject:MIME-Version:Content-Type:From: DKIM-Signature:DKIM-Signature; b=LiPl7QRb7v9FKauAkj/B66Vxfm4FSgaSzvqOrpJs6roGchx7A1CTm+jIbmaUkUksJ0bxBm2NuS VB5rmzXPN4FZp7Qdfkuvd5VGvgO8qGQnrmH/SNxu9g+cPXqMN60SQfciL0sN9don6WnjblUpOH W6nFnfg6qgNldW71UYb6heuVRo+oseUrU/E3CbZ5jwQfCt5+45jIRjhwjijGyH/iby7ZWUwg82 zD9FtdJCwTQNllqM2s+uRHhLEc1KB2EpV3pvCZFICd0uq2IYj5lLx1MnB55x/1n4uQdgbwsb0+ 8ncolh5XhQfYVQXRH6v4JEMGJvy4HgzUwDhxgvzji57xIA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:Date:Message-Id:Subject: Mime-Version:Content-Type:From:Reply-To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=vqnyg/ictQWzfxCadWVPkLDPfsCcLPC3inyrKM5RrRw=; b=j3qak7vAjzPpHRDIlVl6vEYvJ6 tdTxpW5BQu4Eea9aJEh4evuFVS5Smq/MdSK039pwROwB4c5ol0qN+NUp7b9wulYqzaVVQQrDO9JZw JzlaweNfA/bRZlwVn+tdxE5JqLSO72AvpDNfhPJ/pfbdSc5bzQKkdGadfmzZwUj6Eim6xgcWQBvGK VACHwe0iHc0lyTBRqK8XaY5WGDM7Jpz/bDhAHQCHv8Cp2MBndo/nSvYe8C2gketCZ+4b3Ja/8olJO zVMPF97ll1bddwncH3C9ril2WgviN1Dueni9dLpWjX2vzuUusz3LkLYRH6DNWKIpO3n7cGuMnLh3/ 3YATsK4A==; Received: from authenticated user by zero.zsh.org with local id 1lYqZE-000BVe-KJ; Tue, 20 Apr 2021 13:37:28 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f54.google.com) smtp.remote-ip=209.85.167.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f54.google.com ([209.85.167.54]:45771) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lYqYO-000BHi-M8; Tue, 20 Apr 2021 13:36:37 +0000 Received: by mail-lf1-f54.google.com with SMTP id g8so61558528lfv.12 for ; Tue, 20 Apr 2021 06:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=vqnyg/ictQWzfxCadWVPkLDPfsCcLPC3inyrKM5RrRw=; b=AxO7aBqZAv8WM6y2Qnhhj70Yn3ByiKplPUh4MdXuRW0uid72hQmd5nyUlWRqv2iiEY wOw1aM7xHyqe6Mhr/S8UmoflG2cxb3IQmm7HUdh8PYR5orwdTET/56iaIg9pjTSuTWkG MLL8FXoZxh3FII4izrr8UzZJOwwL8peiaOmJz2YaDeySmLca0FYaHaQaVPU4URansX0r H9dXGjGDEwXKv4/xPilynogRqcG8PfYhIoUI558I1ePuboWcn0MW+ViDLRi2ty9GUj74 IBgM4XFO+S4iSAbBTePRWUS6vn26o9CWMD7wpXhjIEHqwPoX6gJQOleyGbAbxju9mV9b 7VAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=vqnyg/ictQWzfxCadWVPkLDPfsCcLPC3inyrKM5RrRw=; b=aiMPqRZws3Lj/oU2jqSgceDZ9Nu5z1J3foV5zGiiuIECBqN9CMHeVisL1T2OY6TBrG IZshzFrzXxDdvUfHb7fzBzmrjGLvKZuHOTMotH3FxxuRXL5by7Upi7BLusvWQx/FyJn5 l+FzxekJMFGqeFM84uZXrKEO1VwpfKpeF1gL1UPTiZKni14lrWKsMCEUEiWa8GHlYR2g i1wTwS6fXWRtW504H2og46Irty8RQlCt/7GQf75QhaBH+c6gKeXJWtOzRw5QwmW8zf2R NbYt6a33sjwGjhY6LccPD7PZPNXJ02gHuHESt+8ljWDxiwvK+zYsOtVIrN9Hv6vsRnaF XzHQ== X-Gm-Message-State: AOAM5332GKZ2i6if8iXqnEkdtkS23lwNp2icwxRmtjX2wAMZIi//zJ3G cMaJ2xDJtpW5ZX6rzUKVChzRSasAbBQVGw== X-Google-Smtp-Source: ABdhPJwmu2027QLZet9hLV9XAkv0FpJQNalQyR+cGbIUjtzCf3uXrHEpW7oO8U6Y9wx8HyCwGcUeIg== X-Received: by 2002:a05:6512:3d04:: with SMTP id d4mr10827731lfv.216.1618925795421; Tue, 20 Apr 2021 06:36:35 -0700 (PDT) Received: from [192.168.1.15] (hag-tkubng22-50df3e-132.dhcp.inet.fi. [80.223.62.132]) by smtp.gmail.com with ESMTPSA id r13sm233103ljn.39.2021.04.20.06.36.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Apr 2021 06:36:34 -0700 (PDT) From: Marlon Richert Content-Type: multipart/mixed; boundary="Apple-Mail=_012A91B3-3CA5-4978-8FD1-EDF3718E25BF" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: [RFC][PATCH] Add change-directory() widget function Message-Id: <95CDA630-4EE5-4003-8D9C-CCCB9A47F109@gmail.com> Date: Tue, 20 Apr 2021 16:36:33 +0300 To: Zsh hackers list X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48622 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --Apple-Mail=_012A91B3-3CA5-4978-8FD1-EDF3718E25BF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Attached is the widget that was discussed in workers/48408 and ancestors = (Re: Rewrite of zsh-newuser-install). There was some discussion as to whether this should or shouldn=E2=80=99t = leave the executed commands visible in the terminal and/or history. I = tried a version of it that doesn=E2=80=99t put the commands in the = buffer but executes them directly and then does zle .reset-prompt, but = this can leave the prompt in an incorrect state if the prompt uses = precmd hooks. I also tried =E2=80=9Cmanually=E2=80=9D running = precmd_functions before zle .reset-prompt, but this causes problems when = any precmd hook contains code that doesn=E2=80=99t work when executed = inside a widget (for example, echoing an escape code that result in a = response from the terminal). Therefore, I instead settled on pushing the = current line, setting the buffer, and then accepting the line. This = seems to me the least likely to break anything, but I=E2=80=99m open to = alternatives. --Apple-Mail=_012A91B3-3CA5-4978-8FD1-EDF3718E25BF Content-Disposition: attachment; filename=0001-Add-change-directory-widget-function.txt Content-Type: text/plain; x-unix-mode=0644; name="0001-Add-change-directory-widget-function.txt" Content-Transfer-Encoding: quoted-printable =46rom 7cf2d34d4066a5979d47256865680b36ea08d0c0 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Tue, 20 Apr 2021 16:25:07 +0300 Subject: [PATCH] Add change-directory() widget function --- Doc/Zsh/contrib.yo | 73 ++++++++++++++++++++-------------- Functions/Zle/change-directory | 29 ++++++++++++++ 2 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 Functions/Zle/change-directory diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 3c4fdded0..519f0db43 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -123,9 +123,9 @@ If the tt(-p) option is given, the var(arg)s are = interpreted as one or more sets of arguments for tt(zcompile), separated by `tt(-)tt(-)'. For example: =20 -example(zrecompile -p \=20 - -R ~/.zshrc -- \=20 - -M ~/.zcompdump -- \=20 +example(zrecompile -p \ + -R ~/.zshrc -- \ + -M ~/.zcompdump -- \ ~/zsh/comp.zwc ~/zsh/Completion/*/_*) =20 This compiles tt(~/.zshrc) into tt(~/.zshrc.zwc) if that doesn't exist = or @@ -529,7 +529,7 @@ are shown first. The special value tt(+) can appear = in the list to indicate the default file should be read at that point. This allows effects like the following: =20 -example(zstyle ':chpwd:*' recent-dirs-file \=20 +example(zstyle ':chpwd:*' recent-dirs-file \ ~/.chpwd-recent-dirs-${TTY##*/} +) =20 Recent directories are read from a file numbered according to @@ -890,9 +890,9 @@ subsect(Quickstart) To get this feature working quickly (including colors), you can do the following (assuming, you loaded tt(vcs_info) properly - see above): =20 -example(zstyle ':vcs_info:*' actionformats \=20 +example(zstyle ':vcs_info:*' actionformats \ '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' -zstyle ':vcs_info:*' formats \=20 +zstyle ':vcs_info:*' formats \ '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f ' zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' precmd () { vcs_info } @@ -1418,7 +1418,7 @@ to know which patches of a series are not yet = applied, you need to activate the tt(get-unapplied) style in the appropriate context. =20 tt(vcs_info) allows for very detailed control over how the gathered -information is presented (see=20 +information is presented (see ifzman(the bf(Configuration) and bf(Hooks in vcs_info) sections)\ ifnzman(noderef(vcs_info Configuration) and noderef(vcs_info Hooks))), all of which are documented below. Note there are a number of @@ -1826,7 +1826,7 @@ example(zstyle ':vcs_info:bzr:*' use-simple true) If you do use tt(use-simple), please report if it does = `the-right-thing[tm]'. =20 Display the revision number in yellow for tt(bzr) and tt(svn): -example(zstyle ':vcs_info:(svn|bzr):*' \=20 +example(zstyle ':vcs_info:(svn|bzr):*' \ branchformat '%b%%F{yellow}:%r') =20 The doubled percent sign is explained in @@ -1834,7 +1834,7 @@ ifzman(the bf(Oddities) = section)ifnzman(noderef(vcs_info Oddities)). =20 Alternatively, one can use the raw colour codes directly: =20 -example(zstyle ':vcs_info:(svn|bzr):*' \=20 +example(zstyle ':vcs_info:(svn|bzr):*' \ branchformat '%b%{'${fg[yellow]}'%}:%r') =20 Normally when a variable is interpolated into a format string, the = variable @@ -2273,7 +2273,7 @@ Neither of the styles tt(word-chars) nor = tt(word-class) is used in this case. Here are some examples of use of the tt(word-context) style to extend the context. =20 -example(zstyle ':zle:*' word-context \=20 +example(zstyle ':zle:*' word-context \ "*/*" filename "[[:space:]]" whitespace zstyle ':zle:transpose-words:whitespace' word-style shell zstyle ':zle:transpose-words:filename' word-style normal @@ -2383,7 +2383,7 @@ paste itself from proceeding. Loading tt(bracketed-paste-magic) defines tt(backward-extend-paste), a helper function for use in tt(paste-init). =20 -example(zstyle :bracketed-paste-magic paste-init \=20 +example(zstyle :bracketed-paste-magic paste-init \ backward-extend-paste) =20 When a paste would insert into the middle of a word or append text to a @@ -2403,16 +2403,16 @@ the paste itself from proceeding. Loading tt(bracketed-paste-magic) also defines tt(quote-paste), a = helper function for use in tt(paste-finish). =20 -example(zstyle :bracketed-paste-magic paste-finish \=20 +example(zstyle :bracketed-paste-magic paste-finish \ quote-paste -zstyle :bracketed-paste-magic:finish quote-style \=20 +zstyle :bracketed-paste-magic:finish quote-style \ qqq) =20 When the pasted text is inserted into tt(BUFFER), it is quoted per the tt(quote-style) value. To forcibly turn off the built-in numeric = prefix quoting of tt(bracketed-paste), use: =20 -example(zstyle :bracketed-paste-magic:finish quote-style \=20 +example(zstyle :bracketed-paste-magic:finish quote-style \ none) ) enditem() @@ -2423,6 +2423,21 @@ history is restricted, so cursor motions, etc., = may not pass outside of the pasted content. Text assigned to tt(BUFFER) by the active widgets is copied back into tt(PASTED) before tt(paste-finish). ) +tindex(change-directory) +item(tt(change-directory))( +This function implements the widgets tt(cd-upward), tt(cd-backward) and +tt(cd-forward). They can be used, respectively, to change to the = current +directory's parent or the previous/next entry in the directory stack. = They +should be initialized as follows: + +example(autoload -Uz change-directory +zle -N cd-upward change-directory +zle -N cd-backward change-directory +zle -N cd-forward change-directory +bindkey '^[^[OA' cd-upward # Alt-Up +bindkey '^[^[OD' cd-backward # Alt-Left +bindkey '^[^[OC' cd-forward # Alt-Right +) tindex(copy-earlier-word) item(tt(copy-earlier-word))( This widget works like a combination of tt(insert-last-word) and @@ -2447,7 +2462,7 @@ function based completion system may know about = multiple places in this string where characters are missing or differ from at least one of the possible matches. It will then place the cursor on the position it considers to be the most interesting one, i.e. the one -where one can disambiguate between as many matches as possible with as=20= +where one can disambiguate between as many matches as possible with as little typing as possible. =20 This widget allows the cursor to be easily moved to the other = interesting @@ -2516,9 +2531,9 @@ the history. Although you tt(autoload) only one function, the commands to use it are slightly different because it implements two widgets. =20 -example(zle -N history-beginning-search-backward-end \=20 +example(zle -N history-beginning-search-backward-end \ history-search-end -zle -N history-beginning-search-forward-end \=20 +zle -N history-beginning-search-forward-end \ history-search-end bindkey '\e^P' history-beginning-search-backward-end bindkey '\e^N' history-beginning-search-forward-end) @@ -2543,7 +2558,7 @@ in the text typed is treated as a wildcard and can = match anything (hence a leading space is equivalent to giving a numeric argument). Both forms can be combined, for example: =20 -example(zle -N history-beginning-search-menu-space-end \=20 +example(zle -N history-beginning-search-menu-space-end \ history-beginning-search-menu) ) tindex(history-pattern-search) @@ -2865,7 +2880,7 @@ non-zero. =20 Here is a trivial example of a widget using this feature. example(local state -narrow-to-region -p $'Editing restricted region\n' \=20 +narrow-to-region -p $'Editing restricted region\n' \ -P '' -S state zle recursive-edit narrow-to-region -R state) @@ -3300,11 +3315,11 @@ and for these widgets. For example, to use = completion, approximation and correction for normal completion, completion and correction for incremental completion and only completion for prediction one could = use: =20 -example(zstyle ':completion:*' completer \=20 +example(zstyle ':completion:*' completer \ _complete _correct _approximate -zstyle ':completion:incremental:*' completer \=20 +zstyle ':completion:incremental:*' completer \ _complete _correct -zstyle ':completion:predict:*' completer \=20 +zstyle ':completion:predict:*' completer \ _complete) =20 It is a good idea to restrict the completers used in prediction, = because @@ -3324,7 +3339,7 @@ been tried. Values are: startitem() item(tt(complete))( The cursor is left where it was when completion finished, but only if -it is after a character equal to the one just inserted by the user. If=20= +it is after a character equal to the one just inserted by the user. If it is after another character, this value is the same as `tt(key)'. ) item(tt(key))( @@ -3333,7 +3348,7 @@ after the var(n)th occurrence of the character = just inserted, where var(n) is the number of times that character appeared in the word before completion was attempted. In short, this has the effect of leaving the cursor after the character just typed even if the -completion code found out that no other characters need to be inserted=20= +completion code found out that no other characters need to be inserted at that position. ) enditem() @@ -3344,7 +3359,7 @@ position where the completion code left it. kindex(list, widget style) item(tt(list))( When using the tt(incremental-complete-word) widget, this style says -if the matches should be listed on every key press (if they fit on the=20= +if the matches should be listed on every key press (if they fit on the screen). Use the context prefix `tt(:completion:incremental)'. =20 The tt(insert-and-predict) widget uses this style to decide if the @@ -3410,7 +3425,7 @@ Like `tt(break-keys)', this uses the = `tt(:incremental)' context. kindex(stop-keys, widget style) item(tt(stop-keys))( This style is used by the tt(incremental-complete-word) widget. Its = value -is treated similarly to the one for the tt(break-keys) style (and uses=20= +is treated similarly to the one for the tt(break-keys) style (and uses the same context: `tt(:incremental)'). However, in this case all keys matching the pattern given as its value will stop incremental completion and will then execute their usual function. @@ -4401,7 +4416,7 @@ tt(openssl), tt(p4), tt(sudo), tt(svk), -and=20 +and tt(svn), commands. ) @@ -4646,8 +4661,8 @@ This makes defining styles a bit simpler by using = a single `tt(+)' as a special token that allows you to append a context name to the = previously used context name. Like this: =20 -example(zstyle+ ':foo:bar' var(style1) var(value1) \=20 - + ':baz' var(style2) var(value2) \=20 +example(zstyle+ ':foo:bar' var(style1) var(value1) \ + + ':baz' var(style2) var(value2) \ + ':frob' var(style3) var(value3)) =20 This defines var(style1) with var(value1) for the context tt(:foo:bar) = as usual, diff --git a/Functions/Zle/change-directory = b/Functions/Zle/change-directory new file mode 100644 index 000000000..376e4414c --- /dev/null +++ b/Functions/Zle/change-directory @@ -0,0 +1,29 @@ +zle .push-line-or-edit +case $WIDGET in + *-upward ) + if [[ -o autocd ]]; then + BUFFER=3D'..' + else + BUFFER=3D'cd ..' + fi + ;; + *-backward ) + if [[ -o pushdminus ]]; then + BUFFER=3D'pushd -1' + else + BUFFER=3D'pushd +1' + fi + ;; + *-forward ) + if [[ -o pushdminus ]]; then + BUFFER=3D'pushd +0' + else + BUFFER=3D'pushd -0' + fi + ;; + * ) + print -u2 'change-directory: widget name should end in = -(up|back|for)ward' + return 1 + ;; +esac +zle .accept-line --=20 2.31.1 --Apple-Mail=_012A91B3-3CA5-4978-8FD1-EDF3718E25BF Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_012A91B3-3CA5-4978-8FD1-EDF3718E25BF--