Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

jab opened this issue Jun 9, 2012 · 31 comments
Assignees
Milestone

Comments

@jab
Copy link

@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
Copy link

@lonetwin lonetwin commented 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
Copy link
Author

@jab 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
Copy link
Contributor

@timbertson timbertson commented Jun 12, 2012

+1 to this, I miss it sorely too.

@ecraven
Copy link
Contributor

@ecraven ecraven commented Jun 12, 2012

+1 for this! missing it too

@ecraven ecraven mentioned this issue Jun 12, 2012
@christfo
Copy link

@christfo christfo commented Jun 13, 2012

+1

@jab
Copy link
Author

@jab 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
Copy link

@mikebobroski mikebobroski commented 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-)'

@timbertson
Copy link
Contributor

@timbertson 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
Copy link

@mikebobroski mikebobroski commented 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.

@jab
Copy link
Author

@jab 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
Copy link
Contributor

@timbertson 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
Copy link

@mikebobroski mikebobroski commented 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.

@ecraven
Copy link
Contributor

@ecraven 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
Copy link
Contributor

@maxfl 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
Copy link
Contributor

@timbertson 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
Copy link

@mikebobroski mikebobroski commented 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.

@jab
Copy link
Author

@jab jab commented Jun 21, 2012

Yes please!

@mikebobroski
Copy link

@mikebobroski mikebobroski commented 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?

@lanterndev
Copy link

@lanterndev lanterndev commented 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?

@mikebobroski
Copy link

@mikebobroski mikebobroski commented 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".

@lanterndev
Copy link

@lanterndev lanterndev commented 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?

@mikebobroski
Copy link

@mikebobroski mikebobroski commented 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.

@lanterndev
Copy link

@lanterndev lanterndev commented 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!

@stereoit
Copy link

@stereoit stereoit commented 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.

@ecraven
Copy link
Contributor

@ecraven 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
Copy link

@amitkot 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
Copy link
Contributor

@mrshu mrshu commented Aug 16, 2013

I believe the issue has been resolved here.

Can it be closed now?

@timbertson
Copy link
Contributor

@timbertson 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
Copy link

@lanterndev lanterndev commented 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?

@ridiculousfish
Copy link
Member

@ridiculousfish 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
Copy link
Author

@jab jab commented Jan 8, 2014

hooray!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.