meta+period should insert last argument of previous command #89

Closed
jab opened this Issue Jun 9, 2012 · 31 comments

Comments

Projects
None yet
@jab

jab commented Jun 9, 2012

First of all, thanks for fish, it's totally awesome.

I just switched from bash, and the thing I'm acutely missing is meta+period to insert the last argument of the previous command. I've tried in both Terminal and iTerm 2, both of which I have configured to send +Esc for the left option key, but when I hit option+period, it just prints the period. Some way to make this work?

@lonetwin

This comment has been minimized.

Show comment
Hide comment
@lonetwin

lonetwin Jun 10, 2012

@jab, from one bash user to another -- I accidentally discovered that you can get what you want by simply typing out (possibly with tab-completion) the command, adding a space and then pressing the up-down arrow to scroll thru' the previous command's argument list. Pretty cool stuff ! I agree, fish is awesome.

@jab, from one bash user to another -- I accidentally discovered that you can get what you want by simply typing out (possibly with tab-completion) the command, adding a space and then pressing the up-down arrow to scroll thru' the previous command's argument list. Pretty cool stuff ! I agree, fish is awesome.

@jab

This comment has been minimized.

Show comment
Hide comment
@jab

jab Jun 11, 2012

thanks @lonetwin, but that doesn't seem to be working for me. for me pressing up only shows completions from previous commands matching what i've typed so far (everything to the left of the cursor). So if I have:

> ls /some/deeply/nested/directory/

And I see a file in there "foo" I want to edit, in bash I could just type "vim ", then meta+period to insert that long path, and then just add "foo".

But in fish, typing "vim " and then hitting up does not complete from the previous command, since "vim " does not match "ls".

(Incidentally, I always use Ctrl+P instead of up arrow and Ctrl+N instead of down in order to avoid taking my hands away from the home row.)

jab commented Jun 11, 2012

thanks @lonetwin, but that doesn't seem to be working for me. for me pressing up only shows completions from previous commands matching what i've typed so far (everything to the left of the cursor). So if I have:

> ls /some/deeply/nested/directory/

And I see a file in there "foo" I want to edit, in bash I could just type "vim ", then meta+period to insert that long path, and then just add "foo".

But in fish, typing "vim " and then hitting up does not complete from the previous command, since "vim " does not match "ls".

(Incidentally, I always use Ctrl+P instead of up arrow and Ctrl+N instead of down in order to avoid taking my hands away from the home row.)

@timbertson

This comment has been minimized.

Show comment
Hide comment
@timbertson

timbertson Jun 12, 2012

Contributor

+1 to this, I miss it sorely too.

Contributor

timbertson commented Jun 12, 2012

+1 to this, I miss it sorely too.

@ecraven

This comment has been minimized.

Show comment
Hide comment
@ecraven

ecraven Jun 12, 2012

Contributor

+1 for this! missing it too

Contributor

ecraven commented Jun 12, 2012

+1 for this! missing it too

@ecraven ecraven referenced this issue Jun 12, 2012

Closed

yank-last-arg #118

@christfo

This comment has been minimized.

Show comment
Hide comment

+1

@jab

This comment has been minimized.

Show comment
Hide comment
@jab

jab Jun 16, 2012

I see this has been marked for fish-future, but seems to have substantial user interest. Would this be hard to add?

If someone from the community wanted to take a crack at it, would a good patch be accepted? Any pointers on how to do it for someone who hasn't looked at the code before?

jab commented Jun 16, 2012

I see this has been marked for fish-future, but seems to have substantial user interest. Would this be hard to add?

If someone from the community wanted to take a crack at it, would a good patch be accepted? Any pointers on how to do it for someone who hasn't looked at the code before?

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 17, 2012

The following binding will do what you're looking for, though it breaks if the first character is a hyphen. Maybe someone can help with that?

bind \e. 'commandline -i (echo $history[1] | cut -d " " -f2-)'

The following binding will do what you're looking for, though it breaks if the first character is a hyphen. Maybe someone can help with that?

bind \e. 'commandline -i (echo $history[1] | cut -d " " -f2-)'

@timbertson

This comment has been minimized.

Show comment
Hide comment
@timbertson

timbertson Jun 17, 2012

Contributor

bind \e. 'commandline -i (echo -- $history[1] | cut -d " " -f2-)'

should fix that problem with the dash. But it's notably missing:

  • proper argument parsing (it would break on any quoted argument with a space, e.g if the last arg was "1 2 3" it should insert that whole thing)
  • repeat-use should replace the inserted item: in bash, pressing alt-dot twice in a row will leave you with the last argument from two commands ago ($history[2] in fish's case)
Contributor

timbertson commented Jun 17, 2012

bind \e. 'commandline -i (echo -- $history[1] | cut -d " " -f2-)'

should fix that problem with the dash. But it's notably missing:

  • proper argument parsing (it would break on any quoted argument with a space, e.g if the last arg was "1 2 3" it should insert that whole thing)
  • repeat-use should replace the inserted item: in bash, pressing alt-dot twice in a row will leave you with the last argument from two commands ago ($history[2] in fish's case)
@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 17, 2012

Close! I had to move the -- outside of the parens. (advice from maxfl at Issue 140)

bind \e. 'commandline -i -- (echo $history[1] | cut -d " " -f2-)'

This fixes the problem with the dash, but it turns out I was solving the wrong problem. :) This inserts ALL arguments from the previous command, not the last one. All these years of bash/zsh and I was never aware of this feature. I'll take another stab at it when I have the chance.

Thanks for the advice.

Close! I had to move the -- outside of the parens. (advice from maxfl at Issue 140)

bind \e. 'commandline -i -- (echo $history[1] | cut -d " " -f2-)'

This fixes the problem with the dash, but it turns out I was solving the wrong problem. :) This inserts ALL arguments from the previous command, not the last one. All these years of bash/zsh and I was never aware of this feature. I'll take another stab at it when I have the chance.

Thanks for the advice.

@jab

This comment has been minimized.

Show comment
Hide comment
@jab

jab Jun 18, 2012

Thanks for sharing your progress on a DIY version, @mikewho and @gfxmonk. Look forward to trying once you get a chance to take another stab at it. Being able to cycle through the last arguments of multiple previous commands by continuing to hit period would be awesome, but even just being able to get the most recent command's could go a long way. Of course, I'm also still hoping the fish core developers will notice this ticket and provide built-in support. You there, guys?

jab commented Jun 18, 2012

Thanks for sharing your progress on a DIY version, @mikewho and @gfxmonk. Look forward to trying once you get a chance to take another stab at it. Being able to cycle through the last arguments of multiple previous commands by continuing to hit period would be awesome, but even just being able to get the most recent command's could go a long way. Of course, I'm also still hoping the fish core developers will notice this ticket and provide built-in support. You there, guys?

@timbertson

This comment has been minimized.

Show comment
Hide comment
@timbertson

timbertson Jun 18, 2012

Contributor

Agreed, for the reasons I pointed out above I don't think the script based
solution could ever be sufficient, the feature will need support in fish
itself.

Contributor

timbertson commented Jun 18, 2012

Agreed, for the reasons I pointed out above I don't think the script based
solution could ever be sufficient, the feature will need support in fish
itself.

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 18, 2012

I think it's tricky, but possible for a script based solution.
The hardest part is detecting when to move back in history or when to start over, but I have an idea.

I think it's tricky, but possible for a script based solution.
The hardest part is detecting when to move back in history or when to start over, but I have an idea.

@ecraven

This comment has been minimized.

Show comment
Hide comment
@ecraven

ecraven Jun 19, 2012

Contributor

If anyone could point me towards the right .cpp file, I could give it a try. I just haven't found the time yet to read through enough of the code to understand how things work together :-/

Contributor

ecraven commented Jun 19, 2012

If anyone could point me towards the right .cpp file, I could give it a try. I just haven't found the time yet to read through enough of the code to understand how things work together :-/

@maxfl

This comment has been minimized.

Show comment
Hide comment
@maxfl

maxfl Jun 19, 2012

Contributor

Hi, have you tried AltUp/AltDown keys?
These keys a binded to the functions history-token-search-forward/history-token-search-backward and allow to cycle through the arguments. If no keys after space were pressed it cycles simply through the arguments (starting from the last argument of the previous command), and if some keys were pressed, it cycles only through arguments, which begin with the same symbols.

This feature comes from the original fish, but was broken in the first beta. Now it works.

Contributor

maxfl commented Jun 19, 2012

Hi, have you tried AltUp/AltDown keys?
These keys a binded to the functions history-token-search-forward/history-token-search-backward and allow to cycle through the arguments. If no keys after space were pressed it cycles simply through the arguments (starting from the last argument of the previous command), and if some keys were pressed, it cycles only through arguments, which begin with the same symbols.

This feature comes from the original fish, but was broken in the first beta. Now it works.

@timbertson

This comment has been minimized.

Show comment
Hide comment
@timbertson

timbertson Jun 19, 2012

Contributor

Ahh excellent - that works great @maxfl. Especially paired with bind \e. 'history-token-search-backward' (for the benefit of muscle memory).

Contributor

timbertson commented Jun 19, 2012

Ahh excellent - that works great @maxfl. Especially paired with bind \e. 'history-token-search-backward' (for the benefit of muscle memory).

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 21, 2012

history-token-search-backward suits me, but is there still a demand for a yank-last-arg script? I'm halfway through coding it.

history-token-search-backward suits me, but is there still a demand for a yank-last-arg script? I'm halfway through coding it.

@jab

This comment has been minimized.

Show comment
Hide comment
@jab

jab Jun 21, 2012

Yes please!

jab commented Jun 21, 2012

Yes please!

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 21, 2012

Cool. I'll keep at it. It's kind of fun working within the limitations of what's available. Just curious.. what use cases do you find yank-last-arg an advantage over history-token-search-backward?

Cool. I'll keep at it. It's kind of fun working within the limitations of what's available. Just curious.. what use cases do you find yank-last-arg an advantage over history-token-search-backward?

@lanterndev

This comment has been minimized.

Show comment
Hide comment
@lanterndev

lanterndev Jun 25, 2012

I want to do something like:

$ ls path/to/deeply/nested/directory
$ cd (Alt+.)

all the time, but I don't see how history-token-search-backward helps with that. Am I missing something?

I want to do something like:

$ ls path/to/deeply/nested/directory
$ cd (Alt+.)

all the time, but I don't see how history-token-search-backward helps with that. Am I missing something?

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 26, 2012

history-token-search-backward would do the same thing in that case. Where it differs is that if you pressed Alt+. again, the next token would be "ls", not the last argument of the command prior to "ls path/to/deeply/nested/directory".

history-token-search-backward would do the same thing in that case. Where it differs is that if you pressed Alt+. again, the next token would be "ls", not the last argument of the command prior to "ls path/to/deeply/nested/directory".

@lanterndev

This comment has been minimized.

Show comment
Hide comment
@lanterndev

lanterndev Jun 26, 2012

When I press Alt+. in the context above, nothing happens. bind \e. 'history-token-search-backward' didn't make a difference. I'm using the left option key on a Macbook keyboard for Alt. I've tested on OS X in Terminal.app with "Use option as meta key" set and in iTerm2 with "Option key acts as" both "Meta" and "+Esc", as well is in gnome-terminal in an Ubuntu 12.04 virtual machine. How are you getting this to work?

When I press Alt+. in the context above, nothing happens. bind \e. 'history-token-search-backward' didn't make a difference. I'm using the left option key on a Macbook keyboard for Alt. I've tested on OS X in Terminal.app with "Use option as meta key" set and in iTerm2 with "Option key acts as" both "Meta" and "+Esc", as well is in gnome-terminal in an Ubuntu 12.04 virtual machine. How are you getting this to work?

@mikebobroski

This comment has been minimized.

Show comment
Hide comment
@mikebobroski

mikebobroski Jun 26, 2012

I'm using OS X with iTerm2 using "Option key acts as +Esc". There could be a few issues. history-token-search-backward only started working a week or two ago for me, so definitely try compiling from the latest source. I know the OS X Installer is a little behind. Also, by default history-token-search-backward is bound to Alt-Up. Maybe give that a shot.

I'm using OS X with iTerm2 using "Option key acts as +Esc". There could be a few issues. history-token-search-backward only started working a week or two ago for me, so definitely try compiling from the latest source. I know the OS X Installer is a little behind. Also, by default history-token-search-backward is bound to Alt-Up. Maybe give that a shot.

@lanterndev

This comment has been minimized.

Show comment
Hide comment
@lanterndev

lanterndev Jul 3, 2012

Ah, that was it. I had been running from the .pkg installed version from http://ridiculousfish.com/shell/beta.html. Built my own from latest git master and history-token-search-backward (with the \e. binding) is working like a charm. Thanks @mikewho!

Ah, that was it. I had been running from the .pkg installed version from http://ridiculousfish.com/shell/beta.html. Built my own from latest git master and history-token-search-backward (with the \e. binding) is working like a charm. Thanks @mikewho!

@stereoit

This comment has been minimized.

Show comment
Hide comment
@stereoit

stereoit Jul 26, 2012

Hi, I am coming from BASH and this (atl+. even repeated several times) is one of most used features for me, it would be great to have that in fish.

ls -l update.conf
ls -l /long/path/update.conf.new
vimdiff alt.. alt.

Hi, I am coming from BASH and this (atl+. even repeated several times) is one of most used features for me, it would be great to have that in fish.

ls -l update.conf
ls -l /long/path/update.conf.new
vimdiff alt.. alt.

@ecraven

This comment has been minimized.

Show comment
Hide comment
@ecraven

ecraven Jul 26, 2012

Contributor

function fish_user_keybindings
bind \e. 'history-token-search-backward'
end

in .config/fish/config.fish makes M-. available for me on recent fish. it does cycle through all parameters, not only the last, but I'd consider that a feature :)

Contributor

ecraven commented Jul 26, 2012

function fish_user_keybindings
bind \e. 'history-token-search-backward'
end

in .config/fish/config.fish makes M-. available for me on recent fish. it does cycle through all parameters, not only the last, but I'd consider that a feature :)

@amitkot

This comment has been minimized.

Show comment
Hide comment
@amitkot

amitkot Apr 28, 2013

The function name has since changed from fish_user_keybindings to fish_user_key_bindings.
To get this binding working you now have to add the following function to ~/.config/fish/config.fish:

function fish_user_key_bindings
    bind \e. 'history-token-search-backward'
end

amitkot commented Apr 28, 2013

The function name has since changed from fish_user_keybindings to fish_user_key_bindings.
To get this binding working you now have to add the following function to ~/.config/fish/config.fish:

function fish_user_key_bindings
    bind \e. 'history-token-search-backward'
end
@mrshu

This comment has been minimized.

Show comment
Hide comment
@mrshu

mrshu Aug 16, 2013

Contributor

I believe the issue has been resolved here.

Can it be closed now?

Contributor

mrshu commented Aug 16, 2013

I believe the issue has been resolved here.

Can it be closed now?

@timbertson

This comment has been minimized.

Show comment
Hide comment
@timbertson

timbertson Aug 17, 2013

Contributor

@mrshu I understood the issue was about making this part of fish by default, rather than requiring writing your own keybindings. So I wouldn't consider it closed until that's done (or else it's declared that it won't be part of fish).

Contributor

timbertson commented Aug 17, 2013

@mrshu I understood the issue was about making this part of fish by default, rather than requiring writing your own keybindings. So I wouldn't consider it closed until that's done (or else it's declared that it won't be part of fish).

@lanterndev

This comment has been minimized.

Show comment
Hide comment
@lanterndev

lanterndev Dec 30, 2013

function fish_user_key_bindings
   bind \e. 'history-token-search-backward'
end

ping @ridiculousfish, any interest in making this the default behavior?

function fish_user_key_bindings
   bind \e. 'history-token-search-backward'
end

ping @ridiculousfish, any interest in making this the default behavior?

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Dec 30, 2013

Member

I don't have any objection.

Member

ridiculousfish commented Dec 30, 2013

I don't have any objection.

@ghost ghost assigned zanchey Jan 6, 2014

@zanchey zanchey closed this in 02bd933 Jan 8, 2014

@jab

This comment has been minimized.

Show comment
Hide comment
@jab

jab Jan 8, 2014

hooray!

jab commented Jan 8, 2014

hooray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment