Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic abbrev expand for the shell

Tags:

linux

shell

emacs

Is there a function on one of the linux shells like the emacs dabbrev-expand?

like image 302
paweloque Avatar asked Oct 19 '25 05:10

paweloque


1 Answers

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).

like image 101
Mikel Avatar answered Oct 21 '25 23:10

Mikel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!