如何将所有选项卡完成添加到我当前的命令?
How to add all tab completitions to my current command?
所以我输入了一个命令 (pacman -S perl-),然后点击选项卡,看到有一大堆完成(大约 40),我意识到我想 运行每一次完成(所以我不会不小心从 CPAN 安装已经内置的东西)。
我如何运行完成一条命令的所有操作?
奖励:我如何 运行 多于一个且少于所有命令(无需单独输入)?
示例情况(实际情况):
XXXXXXXXXXXXXXXXX ❯❯❯ pacman -S perl-<Tab> ⏎
-- packages --
perl perl-IPC-Run3
perl-ack perl-libwww
perl-Archive-Zip perl-Locale-Gettext
perl-Authen-SASL perl-LWP-MediaTypes
perl-Benchmark-Timer perl-LWP-Protocol-https
perl-Capture-Tiny perl-MailTools
perl-common-sense perl-MIME-tools
perl-Compress-Bzip2 perl-Mozilla-CA
perl-Convert-BinHex perl-Net-DNS
perl-Crypt-SSLeay perl-Net-HTTP
perl-DBI perl-Net-IP
perl-Digest-HMAC perl-Net-SMTP-SSL
perl-Encode-Locale perl-Net-SSLeay
perl-Error perl-Path-Class
perl-Exporter-Lite perl-Probe-Perl
perl-ExtUtils-Depends perl-Regexp-Common
perl-ExtUtils-PkgConfig perl-Socket6
perl-File-Copy-Recursive perl-Sys-CPU
perl-File-Listing perl-TermReadKey
perl-File-Next perl-Test-Pod
perl-File-Which perl-Test-Script
perl-Getopt-Tabular perl-TimeDate
perl-HTML-Parser perl-Try-Tiny
perl-HTML-Tagset perl-URI
perl-HTTP-Cookies perl-WWW-RobotRules
perl-HTTP-Daemon perl-XML-LibXML
perl-HTTP-Date perl-XML-NamespaceSupport
perl-HTTP-Message perl-XML-Parser
perl-HTTP-Negotiate perl-XML-SAX
perl-IO-HTML perl-XML-SAX-Base
perl-IO-Socket-INET6 perl-XML-Simple
perl-IO-Socket-SSL perl-YAML
perl-IO-stringy perl-YAML-Syck
我找到了解决我的问题的方法,它完成了工作,但这不是我想要的那种解决方案。
我在屏幕上选择了完成文本(我使用的是 mintty)并将其复制到我的编辑器中。然后我像这样重新格式化它:
perl perl-IPC-Run3 \
perl-ack perl-libwww \
perl-Archive-Zip perl-Locale-Gettext \
perl-Authen-SASL perl-LWP-MediaTypes \
perl-Benchmark-Timer perl-LWP-Protocol-https \
perl-Capture-Tiny perl-MailTools \
perl-common-sense perl-MIME-tools \
perl-Compress-Bzip2 perl-Mozilla-CA \
perl-Convert-BinHex perl-Net-DNS \
perl-Crypt-SSLeay perl-Net-HTTP \
perl-DBI perl-Net-IP \
perl-Digest-HMAC perl-Net-SMTP-SSL \
perl-Encode-Locale perl-Net-SSLeay \
perl-Error perl-Path-Class \
perl-Exporter-Lite perl-Probe-Perl \
perl-ExtUtils-Depends perl-Regexp-Common \
perl-ExtUtils-PkgConfig perl-Socket6 \
perl-File-Copy-Recursive perl-Sys-CPU \
perl-File-Listing perl-TermReadKey \
perl-File-Next perl-Test-Pod \
perl-File-Which perl-Test-Script \
perl-Getopt-Tabular perl-TimeDate \
perl-HTML-Parser perl-Try-Tiny \
perl-HTML-Tagset perl-URI \
perl-HTTP-Cookies perl-WWW-RobotRules \
perl-HTTP-Daemon perl-XML-LibXML \
perl-HTTP-Date perl-XML-NamespaceSupport \
perl-HTTP-Message perl-XML-Parser \
perl-HTTP-Negotiate perl-XML-SAX \
perl-IO-HTML perl-XML-SAX-Base \
perl-IO-Socket-INET6 perl-XML-Simple \
perl-IO-Socket-SSL perl-YAML \
perl-IO-stringy perl-YAML-Syck
并在 pacman -S
之后将其粘贴回我的终端。
我已经说过这不是我想要的解决方案,所以我应该提及我正在寻找的解决方案。
我正在寻找类似 pacman -S perl-*
的东西,它看起来可能会包含所有完成项或其他东西(它没有)。
下面是我自己的处理方案,
- 为完成结果应用匹配。
- 将所有完成匹配项插入命令行。
- 激活菜单select离子和select完成多个。
要为完成结果应用匹配,可以使用 _match
.
这是一个例子 ~/.zshrc
:
# below is same as the zsh default effect
# zstyle ':completion:*::::' completer _complete _ignored
zstyle ':completion:*::::' completer _complete _match _ignored
# I don't like expand-or-complete to <Tab>, so I moved it to <C-x><Tab>
bindkey '^I' complete-word
bindkey '^X^I' expand-or-complete
现在,使用 *
s 可以得到这样的效果:
% ls m*e* ;# I have some local files that matches the glob.
main.epro mem.c mem.pro modentry.c module.o modules.stamp
makepro.awk mem.epro mem.syms module.c module.pro
math.epro mem.o mkmakemod.sh module.epro module.syms
% git m*e*<Tab>
;# This prompts completions rather than expands the local files
;# like this:
% git merge
merge -- join two or more development histories together
merge-base -- find as good a common ancestor as possible for a merge
merge-file -- run a three-way file merge
merge-index -- run merge for files needing merging
merge-one-file -- standard helper-program to use with git merge-index
merge-tree -- show three-way merge without touching index
mergetool -- run merge conflict resolution tools to resolve merge conflicts
mktree -- build tree-object from git ls-tree formatted text
m*e*
要将所有的 compliteon 匹配项插入命令行,可以使用 all-matches
来完成。如果您的 ~/.zshrc
中有以下片段:
zle -C all-matches complete-word _my_generic
zstyle ':completion:all-matches::::' completer _all_matches
zstyle ':completion:all-matches:*' old-matches only
_my_generic () {
local ZSH_TRACE_GENERIC_WIDGET= # works with "setopt nounset"
_generic "$@"
}
bindkey '^X^a' all-matches
键入 Tab 然后 Control-x,Control-a 将完成匹配插入到命令行。
例如:
% vim string.<Tab>
string.c string.epro string.syms
;# then hit <C-x><C-a>
% vim string.c string.epro string.syms
要激活菜单 selection 和 select 完成多个 ,可以通过自定义 menuselect
键盘映射来完成。
(From zhmodules(1)
22.7.3 Menu selection)
zstyle ':completion:*' menu select=0
zmodload zsh/complist
bindkey -M menuselect "^[a" accept-and-hold
bindkey -M menuselect '^[^[' vi-insert
此活动菜单 select用于完成结果。在菜单 selection 处于活动状态时,键入 M-a(或 Esc-a)将插入 selected 条目并将 "menu cursor" 推进到下一个条目。
例如会话:
% ls sig*
sigcount.h signals.h signals.syms signames.o signames1.awk
signals.c signals.o signames.c signames.pro signames2.awk
signals.epro signals.pro signames.epro signames.syms
% vim sig<Tab> ;# this lists the matches
sigcount.h signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# hitting <Tab> second time, the "menu cursor" appears and
;# the first entry will be activated
;# Note: "[[]]" denotes the "menu cursor" here
% vim sigcount.h
[[sigcount.h]] signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# then hit <M-a>(Esc a)
;# "sigcount.h" is now in the command line and
;# the "menu cursor" points "signals.c" now.
% vim sigcout.h signals.c
sigcount.h signals.epro signals.syms signames.epro signames1.awk
[[signals.c]] signals.h signames.c signames.syms signames2.awk
;# then <Tab><Tab>
% vim sigcount.h signals.h
sigcount.h signals.epro signals.syms signames.epro signames1.awk
signals.c [[signals.h]] signames.c signames.syms signames2.awk
因此,您可以 select 完成结果中的多个条目以按 M-a(或 Esc-a)作为你喜欢
下一段还不错知道
在这个示例配置中,点击 EscEsc(我们在上面的代码片段中做了 bindkey -M menuselect '^[^[' vi-insert
),而菜单 selection处于活动状态,它允许我们根据输入模式交互式地限制完成结果。
;# activate "menu selection" and hit <Esc><Esc>,
;# the "interacitve:" mode will be shown at this point.
% vim sig*
interactive: sig[]
[[sigcount.h]] signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# hitting "*awk" while interactive is activetad,
;# it colud limit the completion to "sig*awk"
% vim sig*awk
interactive: sig[]
[[signames1.awk]]signames2.awk
sig*awk
我不确定我描述的是否正确,所以这里是菜单 selection 的 "interactive mode".[= 的 zsh 文档部分33=]
vi-insert
this toggles between normal and interactive mode; in interactive mode the keys bound to self-insert and self-insert-unmeta insert into the command line as in normal editing mode but without leaving menu selection; after each character completion is tried again and the list changes to contain only the new matches; the completion widgets make the longest unambiguous string be inserted in the command line and undo and backward-delete-char go back to the previous set of matches
也可以看看 edit-command-line
处理相当大的命令行缓冲区。
现在在我的debian系统上,我可以得到如下效果:
# apt-get install perl-*<Tab><C-x><C-a><C-w>
;# ⇓
# apt-get install perl-base perl-byacc perl-cross-debian perl-debug perl-depends perl-doc perl-doc-html perl-modules perl-stacktrace perl-tk
所以我输入了一个命令 (pacman -S perl-),然后点击选项卡,看到有一大堆完成(大约 40),我意识到我想 运行每一次完成(所以我不会不小心从 CPAN 安装已经内置的东西)。
我如何运行完成一条命令的所有操作?
奖励:我如何 运行 多于一个且少于所有命令(无需单独输入)?
示例情况(实际情况):
XXXXXXXXXXXXXXXXX ❯❯❯ pacman -S perl-<Tab> ⏎
-- packages --
perl perl-IPC-Run3
perl-ack perl-libwww
perl-Archive-Zip perl-Locale-Gettext
perl-Authen-SASL perl-LWP-MediaTypes
perl-Benchmark-Timer perl-LWP-Protocol-https
perl-Capture-Tiny perl-MailTools
perl-common-sense perl-MIME-tools
perl-Compress-Bzip2 perl-Mozilla-CA
perl-Convert-BinHex perl-Net-DNS
perl-Crypt-SSLeay perl-Net-HTTP
perl-DBI perl-Net-IP
perl-Digest-HMAC perl-Net-SMTP-SSL
perl-Encode-Locale perl-Net-SSLeay
perl-Error perl-Path-Class
perl-Exporter-Lite perl-Probe-Perl
perl-ExtUtils-Depends perl-Regexp-Common
perl-ExtUtils-PkgConfig perl-Socket6
perl-File-Copy-Recursive perl-Sys-CPU
perl-File-Listing perl-TermReadKey
perl-File-Next perl-Test-Pod
perl-File-Which perl-Test-Script
perl-Getopt-Tabular perl-TimeDate
perl-HTML-Parser perl-Try-Tiny
perl-HTML-Tagset perl-URI
perl-HTTP-Cookies perl-WWW-RobotRules
perl-HTTP-Daemon perl-XML-LibXML
perl-HTTP-Date perl-XML-NamespaceSupport
perl-HTTP-Message perl-XML-Parser
perl-HTTP-Negotiate perl-XML-SAX
perl-IO-HTML perl-XML-SAX-Base
perl-IO-Socket-INET6 perl-XML-Simple
perl-IO-Socket-SSL perl-YAML
perl-IO-stringy perl-YAML-Syck
我找到了解决我的问题的方法,它完成了工作,但这不是我想要的那种解决方案。
我在屏幕上选择了完成文本(我使用的是 mintty)并将其复制到我的编辑器中。然后我像这样重新格式化它:
perl perl-IPC-Run3 \
perl-ack perl-libwww \
perl-Archive-Zip perl-Locale-Gettext \
perl-Authen-SASL perl-LWP-MediaTypes \
perl-Benchmark-Timer perl-LWP-Protocol-https \
perl-Capture-Tiny perl-MailTools \
perl-common-sense perl-MIME-tools \
perl-Compress-Bzip2 perl-Mozilla-CA \
perl-Convert-BinHex perl-Net-DNS \
perl-Crypt-SSLeay perl-Net-HTTP \
perl-DBI perl-Net-IP \
perl-Digest-HMAC perl-Net-SMTP-SSL \
perl-Encode-Locale perl-Net-SSLeay \
perl-Error perl-Path-Class \
perl-Exporter-Lite perl-Probe-Perl \
perl-ExtUtils-Depends perl-Regexp-Common \
perl-ExtUtils-PkgConfig perl-Socket6 \
perl-File-Copy-Recursive perl-Sys-CPU \
perl-File-Listing perl-TermReadKey \
perl-File-Next perl-Test-Pod \
perl-File-Which perl-Test-Script \
perl-Getopt-Tabular perl-TimeDate \
perl-HTML-Parser perl-Try-Tiny \
perl-HTML-Tagset perl-URI \
perl-HTTP-Cookies perl-WWW-RobotRules \
perl-HTTP-Daemon perl-XML-LibXML \
perl-HTTP-Date perl-XML-NamespaceSupport \
perl-HTTP-Message perl-XML-Parser \
perl-HTTP-Negotiate perl-XML-SAX \
perl-IO-HTML perl-XML-SAX-Base \
perl-IO-Socket-INET6 perl-XML-Simple \
perl-IO-Socket-SSL perl-YAML \
perl-IO-stringy perl-YAML-Syck
并在 pacman -S
之后将其粘贴回我的终端。
我已经说过这不是我想要的解决方案,所以我应该提及我正在寻找的解决方案。
我正在寻找类似 pacman -S perl-*
的东西,它看起来可能会包含所有完成项或其他东西(它没有)。
下面是我自己的处理方案,
- 为完成结果应用匹配。
- 将所有完成匹配项插入命令行。
- 激活菜单select离子和select完成多个。
要为完成结果应用匹配,可以使用 _match
.
这是一个例子 ~/.zshrc
:
# below is same as the zsh default effect
# zstyle ':completion:*::::' completer _complete _ignored
zstyle ':completion:*::::' completer _complete _match _ignored
# I don't like expand-or-complete to <Tab>, so I moved it to <C-x><Tab>
bindkey '^I' complete-word
bindkey '^X^I' expand-or-complete
现在,使用 *
s 可以得到这样的效果:
% ls m*e* ;# I have some local files that matches the glob.
main.epro mem.c mem.pro modentry.c module.o modules.stamp
makepro.awk mem.epro mem.syms module.c module.pro
math.epro mem.o mkmakemod.sh module.epro module.syms
% git m*e*<Tab>
;# This prompts completions rather than expands the local files
;# like this:
% git merge
merge -- join two or more development histories together
merge-base -- find as good a common ancestor as possible for a merge
merge-file -- run a three-way file merge
merge-index -- run merge for files needing merging
merge-one-file -- standard helper-program to use with git merge-index
merge-tree -- show three-way merge without touching index
mergetool -- run merge conflict resolution tools to resolve merge conflicts
mktree -- build tree-object from git ls-tree formatted text
m*e*
要将所有的 compliteon 匹配项插入命令行,可以使用 all-matches
来完成。如果您的 ~/.zshrc
中有以下片段:
zle -C all-matches complete-word _my_generic
zstyle ':completion:all-matches::::' completer _all_matches
zstyle ':completion:all-matches:*' old-matches only
_my_generic () {
local ZSH_TRACE_GENERIC_WIDGET= # works with "setopt nounset"
_generic "$@"
}
bindkey '^X^a' all-matches
键入 Tab 然后 Control-x,Control-a 将完成匹配插入到命令行。
例如:
% vim string.<Tab>
string.c string.epro string.syms
;# then hit <C-x><C-a>
% vim string.c string.epro string.syms
要激活菜单 selection 和 select 完成多个 ,可以通过自定义 menuselect
键盘映射来完成。
(From zhmodules(1)
22.7.3 Menu selection)
zstyle ':completion:*' menu select=0
zmodload zsh/complist
bindkey -M menuselect "^[a" accept-and-hold
bindkey -M menuselect '^[^[' vi-insert
此活动菜单 select用于完成结果。在菜单 selection 处于活动状态时,键入 M-a(或 Esc-a)将插入 selected 条目并将 "menu cursor" 推进到下一个条目。
例如会话:
% ls sig*
sigcount.h signals.h signals.syms signames.o signames1.awk
signals.c signals.o signames.c signames.pro signames2.awk
signals.epro signals.pro signames.epro signames.syms
% vim sig<Tab> ;# this lists the matches
sigcount.h signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# hitting <Tab> second time, the "menu cursor" appears and
;# the first entry will be activated
;# Note: "[[]]" denotes the "menu cursor" here
% vim sigcount.h
[[sigcount.h]] signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# then hit <M-a>(Esc a)
;# "sigcount.h" is now in the command line and
;# the "menu cursor" points "signals.c" now.
% vim sigcout.h signals.c
sigcount.h signals.epro signals.syms signames.epro signames1.awk
[[signals.c]] signals.h signames.c signames.syms signames2.awk
;# then <Tab><Tab>
% vim sigcount.h signals.h
sigcount.h signals.epro signals.syms signames.epro signames1.awk
signals.c [[signals.h]] signames.c signames.syms signames2.awk
因此,您可以 select 完成结果中的多个条目以按 M-a(或 Esc-a)作为你喜欢
下一段还不错知道
在这个示例配置中,点击 EscEsc(我们在上面的代码片段中做了 bindkey -M menuselect '^[^[' vi-insert
),而菜单 selection处于活动状态,它允许我们根据输入模式交互式地限制完成结果。
;# activate "menu selection" and hit <Esc><Esc>,
;# the "interacitve:" mode will be shown at this point.
% vim sig*
interactive: sig[]
[[sigcount.h]] signals.epro signals.syms signames.epro signames1.awk
signals.c signals.h signames.c signames.syms signames2.awk
;# hitting "*awk" while interactive is activetad,
;# it colud limit the completion to "sig*awk"
% vim sig*awk
interactive: sig[]
[[signames1.awk]]signames2.awk
sig*awk
我不确定我描述的是否正确,所以这里是菜单 selection 的 "interactive mode".[= 的 zsh 文档部分33=]
vi-insert
this toggles between normal and interactive mode; in interactive mode the keys bound to self-insert and self-insert-unmeta insert into the command line as in normal editing mode but without leaving menu selection; after each character completion is tried again and the list changes to contain only the new matches; the completion widgets make the longest unambiguous string be inserted in the command line and undo and backward-delete-char go back to the previous set of matches
也可以看看 edit-command-line
处理相当大的命令行缓冲区。
现在在我的debian系统上,我可以得到如下效果:
# apt-get install perl-*<Tab><C-x><C-a><C-w>
;# ⇓
# apt-get install perl-base perl-byacc perl-cross-debian perl-debug perl-depends perl-doc perl-doc-html perl-modules perl-stacktrace perl-tk