我有一个坏习惯,就是TAB在使用终端时按太多次。如果调用的 bash 完成例程特别慢,这会导致长时间的等待,而终端会向我显示完成列表 2-3 次(或TAB按了多少次)。
有没有办法让 bash 完成忽略重复的按键?
答案1
手册页定义了一大组“变量”,可以在您的 ~/.inputrc 文件中定义这些变量来调整支持的完成键。
通过战略性地分配右键正确使用函数,你也许会得到想要的效果。但是,你无法真正阻止替身重复TAB做同样的工作。
示例 ~/.inputrc 文件:
C-TAB: complete
TAB: complete-filename
手册页中关注的区域如下:
Completing
complete (TAB)
Attempt to perform completion on the text before point. Bash attempts
completion treating the text as a variable (if the text begins with $),
username (if the text begins with ~), hostname (if the text begins with @),
or command (including aliases and functions) in turn. If none of
these produces a match, filename completion is attempted.
possible-completions (M-?)
List the possible completions of the text before point.
insert-completions (M-*)
Insert all completions of the text before point that would have been
generated by possible-completions.
menu-complete
Similar to complete, but replaces the word to be completed with a
single match from the list of possible completions. Repeated execution of
menu-complete steps through the list of possible completions, inserting
each match in turn. At the end of the list of completions, the bell is
rung (subject to the setting of bell-style) and the original text
is restored. An argument of n moves n positions forward in the list of
matches; a negative argument may be used to move backward through the list.
This command is intended to be bound to TAB, but is unbound by
default.
menu-complete-backward
Identical to menu-complete, but moves backward through the list of possible
completions, as if menu-complete had been given a negative argument.
This command is unbound by default.
delete-char-or-list
Deletes the character under the cursor if not at the beginning or end of
the line (like delete-char). If at the end of the line, behaves identi‐
cally to possible-completions. This command is unbound by default.
complete-filename (M-/)
Attempt filename completion on the text before point.
possible-filename-completions (C-x /)
List the possible completions of the text before point, treating it as
a filename.
complete-username (M-~)
Attempt completion on the text before point, treating it as a username.
possible-username-completions (C-x ~)
List the possible completions of the text before point, treating it as
a username.
complete-variable (M-$)
Attempt completion on the text before point, treating it as a shell variable.
possible-variable-completions (C-x $)
List the possible completions of the text before point, treating it as
a shell variable.
complete-hostname (M-@)
Attempt completion on the text before point, treating it as a hostname.
possible-hostname-completions (C-x @)
List the possible completions of the text before point, treating it as
a hostname.
complete-command (M-!)
Attempt completion on the text before point, treating it as a
command name. Command completion attempts to match the text against aliases,
reserved words, shell functions, shell builtins, and finally executable
filenames, in that order.
possible-command-completions (C-x !)
List the possible completions of the text before point, treating it as
a command name.
dynamic-complete-history (M-TAB)
Attempt completion on the text before point, comparing the text against
lines from the history list for possible completion matches.
dabbrev-expand
Attempt menu completion on the text before point, comparing the text
against lines from the history list for possible completion matches.
complete-into-braces (M-{)
Perform filename completion and insert the list of possible completions
enclosed within braces so the list is available to the shell (see Brace
Expansion above).