Using previous command arguments in a new line

A friend of mine was talking about his design for a shell that would allow you to programatically reuse arguments. I started looking and found that bash can do this but not programatically (at least as far as I know). The syntax was slighty confusing but here is the summary, it blew my mind when I started using it (but I'll probably forget it again soon enough, like all the awesome things you can do in vi if you can remember...)

Here goes, lets copy a file from a deeply nested path to our location by first tab-completing the filename with ls


[thomas@host ~]$ ls /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd
/usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd

Now type cp on the new line and then Meta-Control-y
(That is, hold down Meta, Control and then type y ((hopefully you know where your Meta key is, on my keyboard it's the left-alt)))


[thomas@host ~]$ cp /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd .

Cool, now what about a line with many arguments:


[thomas@host ~]$ ls /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd /usr/share/texmf/tex/plain/plgraph/picture.tex /usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty
/usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd /usr/share/texmf/tex/plain/plgraph/picture.tex

To get the last argument, type cp then Meta-.


[thomas@host ~]$ cp /usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty .

Now the one that was somwhat tricky to get would be how to change the argument number


[thomas@host ~]$ ls /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd /usr/share/texmf/tex/plain/plgraph/picture.tex /usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty
/usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd /usr/share/texmf/tex/plain/plgraph/picture.tex

To get the second argument: Meta-2 then (without letting go of Meta) Meta-Control-y


[thomas@host ~]$ ls /usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd /usr/share/texmf/tex/plain/plgraph/picture.tex /usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty
/usr/share/texmf/tex/latex/gnuplottex/gnuplottex.sty
/usr/share/texmf/tex/latex/mathdesign/mdput/ts1mdput.fd
/usr/share/texmf/tex/plain/plgraph/picture.tex
(arg: 2) ls
[thomas@host ~]$ ls /usr/share/texmf/tex/plain/plgraph/picture.tex
/usr/share/texmf/tex/plain/plgraph/picture.tex

Comments

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

About the Author...

Slides from LISA 2019 Linux systems troubleshooting #LISA2019 https://t.co/D4dMKflK6R Tue Oct 29 05:59:30 +0000 2019

https://t.co/AGeihMALAv configuring grub2 with EFI Fri Sep 13 05:20:01 +0000 2019

I published a Thing on @thingiverse! https://t.co/IYpRyEb7Hz #thingalert Tue Jul 23 19:27:57 +0000 2019

Nokogiri install on MacOSX https://t.co/v3An0miW9L Fri Jul 12 15:06:49 +0000 2019

HTML email with plain mailer plugin on Jenkins https://t.co/Z6FSDMDjy8 Thu Jul 11 21:07:25 +0000 2019