4

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

paweloque
  • 18,466
  • 26
  • 80
  • 136
  • See also: [shortcut to reference the path of the first argument](http://stackoverflow.com/questions/5505827/is-there-any-shortcut-to-reference-the-path-of-the-first-argument-in-a-mv-command) for different ways to achieve something similar. – Mikel May 12 '11 at 09:41

1 Answers1

6

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

Mikel
  • 24,855
  • 8
  • 65
  • 66