开发者

Dynamic abbrev expand for the shell

Is there a functi开发者_StackOverflow社区on on one of the linux shells like the emacs dabbrev-expand?


First to give a definition:

M-xdescribe-functionEnterdabbrev-expandEnter

...
Expands to the most recent, preceding word for which this is a prefix.

Given that bash seems to be most heavily influenced by Emacs, looking there first reveals a few possibilities:

man bash(1), readline section

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.

By default (or my system at least), M-/ is already bound to complete-filename:

$ bind -l | grep /
"\e/": complete-filename

You could re-bind it by putting

"\e/": dabbrev-expand

in your ~/.inputrc or /etc/inputrc.

Note that it only seems to complete the first word (the command), and only from history, not from the current command line as far as I can tell.

In zsh, I can't see anything in the man page that does this, but it should be possible to make it happen by figuring out the appropriate compctl command (Google mirror).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜