Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes I need to reuse certain long arguments like paths.

If I use history search (CTRL+R), I may find some command that contains the path, but I still need to delete anything else in the old command, and then move cursor around to write the new command. Worse is that I cannot do this for more than once in a line.

I wonder if any shell provides an argument-level history search?

Tab-completion that looks into history commands (and arguments) somehow helps. But completion has to match the prefix you type, instead of any substrings.

share|improve this question
    
I was thinking of tab-completion, too. What is the difference between "the prefix" and "any substring"? –  michas Jan 20 '13 at 3:25
    
Say I have a long path /usr/local/foo/bar/baz/my-server. What is interesting is "my-server". If I am using tab-completion, I will have to remember what is the front part of the path, which is what I am trying to avoid.. –  user716468 Jan 20 '13 at 23:54

3 Answers 3

In bash(1) (this comes originally from the C shell) you can repeat previous commands using ! (as long as they are in the history). So, e.g.:

enter code here

frob --vigorous extremely/super/cali/fragi/listic/file/name
...
...
xemacs !frob:$       # Edit last argument to last frob command
!frob                # Repeat last frobbing
fiddle !frob:1-$     # Fiddle, use arguments 1 to last of !frob

The syntax takes some getting used to, and (due to the luxury of readline) I use it rarely, but it is quite handy. It is (or used to be) somehwat fragile, in that for example it worked unpredictably in scripts (but there I'd very much make thrice sure I'm running the right command, so...).

share|improve this answer

In zsh, with new-style completion active (i.e. with compinit in your .zshrc), the _history_complete_word function provides this feature. It is accessible through two widgets: _history-complete-older and _history-complete-newer, bound to ESC , and ESC / by default. These two commands cycle through all the words in the shell history that have the current word as a prefix.

share|improve this answer
    
This is close, but it still requires prefix. –  user716468 Feb 22 '13 at 23:26

If I understand correctly, you are after dynamic-complete-history (see e.g. man bash or http://www.cl.cam.ac.uk/local/sys/unix/applications/bash/), by default bound to M-Tab.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.