News for hackers. Stuff that matters.
Re:Matrix.org hacked by jyap on Friday April 12, 2019 @04:23AM (#19643032)
Reason why you would do that (and I often do) is that you have further piping options so it becomes standard work flow and muscle memory.

What I usually do is cat the file to inspect it, hit Control+C, then up arrow for previous command, then further pipe and head/tail/grep the file.

Starting a grep command is fine if you know that's all you're going to be doing.

Re:Matrix.org hacked by laumars on Friday April 12, 2019 @04:59AM (#19643212)
You can use Bash (and I assumed it works in zsh too) variables to save you there. eg

    grep something !$
`!$` will be replaced with the last parameter of the previous command. Crude example

    cat /etc/hosts
    grep 12.34.56.78 $! # will be executed as grep 12.34.56.78 /etc/hosts
I find this extremely useful for when I'm cat'ing a file to get a sense of it's output then wanting to do something more meaningful with it in the next command.

That all said, I have absent-mindedly done my fair share of stuff like this too:

    !! | less
    # eg will run as `cat /etc/hosts | less`
    # if `cat /etc/hosts` was the previous command run
so I certainly wouldn't look down on people who have "abused" cat due to muscle memory.
Re:Matrix.org hacked by shpx on Friday April 12, 2019 @05:09AM (#19643271)
You can also hit Alt-. to insert the last argument of the previous command.
Re:Matrix.org hacked by laumars on Friday April 12, 2019 @05:15AM (#19643291)
Unfortunately not on Macs :(

That's one of the features I miss the most when using terminals on a Mac.

Re:Matrix.org hacked by lelf on Friday April 12, 2019 @05:29AM (#19643359)
Of course you can. It’s «ESC .» or «^[.»

Or you can check “Profiles → Keyboard → Use Option as Meta” for Terminal.app [or just press ⌥⌘O]. And then use option as meta.

Re:Matrix.org hacked by laumars on Friday April 12, 2019 @05:56AM (#19643474)
> Of course you can. It’s «ESC .» or «^[.»

Thanks, I wasn't aware of that. However it's a different hotkey and only pulls the last parameter. The shell I use, you could hit <alt>+<number> and you would get a parameter of that number completed - not just the last parameter. It was very handy for rebuilding long command lines with different arguments.

> Or you can check “Profiles → Keyboard → Use Option as Meta” for Terminal.app [or just press ⌥⌘O]. And then use option as meta.

I use iTerm2 - which does seem to have similar options but I'm yet to get it working. I know that's down to user error but it's still a real pity that it isn't just the default behaviour (in either iTerm or Terminal).

Re:Matrix.org hacked by lelf on Friday April 12, 2019 @06:33AM (#19643596)
ctrl-meta-y (readline’s yank-nth-arg) pulls any argument.
Re:Matrix.org hacked by frou_dh on Friday April 12, 2019 @05:27AM (#19643342)
Works fine here (Terminal.app + bash 5.0.3 from homebrew).

Also, isn't that special variable $_ and not $! ?

Re:Matrix.org hacked by laumars on Friday April 12, 2019 @05:50AM (#19643445)
> Works fine here. Terminal.app + bash 5.0.3 from homebrew.?

Doesn't work for me. Maybe I've broken something on my build? Or maybe you've redefined your keys to emulate the [alt] key?

> Also, isn't that special variable $_ and not $! ?

Sorry I meant `!$` not `$!` (updated my post accordingly).

Yes, $_ does the same thing too.

Re:Matrix.org hacked by shpx on Friday April 12, 2019 @09:41PM (#19650531)
Go to settings and enable "use option as meta key"
Re:Matrix.org hacked by lelf on Friday April 12, 2019 @05:23AM (#19643323)
I just use M-. (meta+.⃣) for that (aka M-_ aka readline’s yank-last-arg)
Re:Matrix.org hacked by SpaceInvader on Friday April 12, 2019 @07:17AM (#19643773)
that is correct, but this case is obviously different :-)