cat filename.txt
Up | grep “thing I want”
Is fewer keystrokes than cat filename.txt
grep “thing I want” filename.txt
Or more likely cat filename.txt
grep filename.txt “thing I want”
grep “thing I want” filename.txt cat filename.txt
Up | grep “thing I want”
Is fewer keystrokes than cat filename.txt
grep “thing I want” filename.txt
Or more likely cat filename.txt
grep filename.txt “thing I want”
grep “thing I want” filename.txt grep “thing I want” !$
Bash (and similar) will replace !$ with the last parameter of the previous command.This is a trick I’ve used lots when wanting to perform a non-piping operation on a command I’ve ‘cat’ed (eg ‘rm -v !$’)
I’d never criticise anyone for “useless” use of ‘cat’ though. If the fork() overhead was really that critical then it wouldn’t be a shell command to begin with.
bind '"\e."':yank-last-arg
So [esc] _ does it on systems where I haven't customised my environment. A major drawback though is it doesn't go through history like alt . does.However, when 'set -o vi' is enabled you can easily go through history and edit with familiar vi keystrokes, or press 'fc' and fix the previous command in EDITOR, or 'v' to edit the current command in EDITOR.
I think you meant 'vv' and I wonder if it's not something that's set up by oh-my-zsh ? It's great though
I wasn't aware that bash and zsh did it differently, I assumed they'd both use the same readline - now I'm aware there's more to understand about it :)
I find that zsh's mode is actually better than readline's For example it can handle visual mode which is why the same function is `vv` and not just `v` Zsh can handle text objects too, very useful to be able to ci" for example Fish's can too and is quite good IIRC
Too bad the `v` command does not work in gdb so it seems it's more of a bash thing than a readline thing
Relevant : https://superuser.com/questions/1543120/make-readline-edit-i...
Press Escape, then the number of the argument from the previous command, confirm with Ctrl+Alt+Y.
Example:
> command arg1 arg2 arg3
Escape, 1, Ctrl+Alt+Y gives you arg1. cat filename.txt
grep "what I want" $_
expands "$_" to "filename.txt"Then I can look at it before hitting return
useful shorthand
> sudo !!
for example.
Again, bash specific.
$ cat file
$ grep stuff alt-.
Alternatively, make use off the READNULLCMD mechanism in Zsh: $ < file
translates to $ ${READNULLCMD:-more} < file
Thus you can $ < file
then UP (or ctrl-p which I find more ergonomic) and continue with "grep stuff": $ < file grep stuff
(Redirections can be anywhere in the command.)https://zsh.sourceforge.io/Doc/Release/Redirection.html#Redi...
cat log | not spam1 | not spam2 | not 'spam(3|4)' | .... | less alias -g V='| grep -vE'
alias -g L="| $PAGER"
Then you can do cat log V spam1 V spam2 L
I also like alias -g G='| grep'
alias -g X='| xargs'
The possibilities are endless...Really I’d be more worried about accidental invocations. Aliases are not scoped, so if you’re dealing with one of those programs with non standards option handling and uppercase single character switches…
And an accidental typo is not really a big deal, certainly not an "injection possibility".
As for accidental invocations, yeah I agree it feels dangerous, but in a few hundred thousand lines of shell history since I set them, never had a problem.
What I really wish for is some sort of tool that would let me pipeline like that, but also easily examine each step in the chain for sanity. Sort of a workbook for shell.
function expand-alias() {
zle _expand_alias
zle self-insert
}
zle -N expand-alias
bindkey -M main ' ' expand-aliasUUoC criticism, to me, belongs when one sits down to script.
cat “filename.txt”
Up | grep “thing”
Up | grep -v “not thing”
Up | grep -v “other thing”
Etc. it’s just easier to build this way even if the initial cat is unnecessary.
> grep “thing I want” filename.txt.
…every time
< file.txt grep pattern
Less keystrokes. < file.txt cat
But then one has to ctrl-w cat. It is a pity that this is not an alternative to cat for a single file: < file.txt