shell 的动态缩写扩展

paw*_*que 4 linux emacs shell

Linux shell 之一上是否有类似 emacs dabbrev-expand 的功能?

Mik*_*kel 6

首先给出一个定义:

M-x描述函数Enterdabbrev-expandEnter

...
Expands to the most recent, preceding word for which this is a prefix.
Run Code Online (Sandbox Code Playgroud)

鉴于这bash似乎受 Emacs 的影响最大,首先查看那里会发现一些可能性:

man bash(1),readline 部分

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.
Run Code Online (Sandbox Code Playgroud)

默认情况下(或者至少是我的系统),M-/已经绑定到complete-filename:

$ bind -l | grep /
"\e/": complete-filename
Run Code Online (Sandbox Code Playgroud)

您可以通过放置来重新绑定它

"\e/": dabbrev-expand
Run Code Online (Sandbox Code Playgroud)

在你~/.inputrc或/etc/inputrc.

请注意,据我所知,它似乎只完成了第一个单词(命令),并且仅来自历史记录,而不是来自当前命令行。

在 zsh 中,我在手册页中看不到任何执行此操作的内容,但应该可以通过找出适当的compctl命令(Google 镜像)来实现此目的。