- cross-posted to:
- [email protected]
- cross-posted to:
- [email protected]
Ctrl R
The number of people who don’t reverse-I-search is too damn high
CTRL+R for those unitiated
reverse-i-search + fzf = <3
It was quite a while before I realised that was possible.
Then not long after starting to use it, that I got fed up and just started opening up the history file and searching in it.why not
history | grep -i
and the search term?even if there are several, you can use ! and the command’s line number to run it again
history
is shell dependent.
Fish once again undefeated. If I want to find that weird image magick command I used earlier with foo.png in it I just type
foo.png
, hit up and its usually the first one. It doesnt matter where foo.png occurs in the command, fish will find it.I typed it once, I’m not typing it again
I write part of the command then ctrl+r. Using FZF mind you. Such a great utility.
You have to be a linux user to use the console now?
cat ~/.bash_history | grep
Useless use of cat?
Yes, it was meant to be a self deprecating admission that I have used this unnecessarily verbose command.
Ah. Well. I can not be blameless on this. I also probably use cat unnecessarily still. But less so with grep these days. I’m getting better… I swear!
You saying I can just skip cat in that command and it works?
history | grep 'cat'
My output was empty for that command.
Guess why?
Becausehistory
only gives the last few lines in my system.
grep ~/.bash_history
How did I not know this. Thank you!
it’s
grep STRING FILE
to be preciseor
awk '/STRING/′ FILE
if you prefer that for some reason
history | grep 'gre[p]' | less -S
Does fuck all when you can’t remember even a piece of the command lol
That’s when you start spamming Page Up/Down, Home, End, and
/
to search withinless
. Usually seeing various commands jogs my memory, especially when they aregrep
commands searching for one I use often enough to be useful but infrequently enough to not remember off the top of my head.
- zsh-autosuggestions
history | fzf
alias cat="bat --plain --theme=gruvbox-dark"
Aliasing
cat
or any other ubiquitous shell utility to a replacement is a mistake. Garuda did this, and it was driving me crazy whycat
was giving me errors. Turns out that they had aliasedbat
tocat
, and sincebat
is a different program, it didn’t work in exactly the same way, and an update had introduced some unexpected behavior.Drop-in replacements are dumb. Just learn to use a different command.
I think it’s ok to add this in a personal
.zshrc
, not on a distro level:If it breaks something - I’d probably know why and can easily fix it by removing alias/calling cat directly.
Also, scripts almost always use bash or sh in shebang, not zsh. So it only triggers if I type
cat
in terminal.Also, even zsh scripts don’t read your .zshrc by default.
It’s better to learn the new command, then it still works when you use a different machine that doesn’t have your alias
If you are me, there is no brain space for remembering new commands. I can already barely hold on to few dozens that I use often. And occasionally when I need “that one that does that niche thing… how was it?” program - I just sit there sifting through logs for couple minutes.
Today it was
od
(tbh it’sod
almost half the time; not really the best name to memorize (I really need to make a note or something, so I stop forgetting it, lol))Also, for this reason I went to great lengths to keep my
~/.zsh_history
protected from being randomly deleted/overwritten by mistake, as it happened a couple of times. Currently it’s sitting at around 30_000 lines, oldest command is 2 years old.
Too many people still use Bash.
I like zsh on mac because pretty colors
Too many distributions still ship with Bash.
In the real world, the only thing better than perfect is standardized.
Yeah, true. But, it’s easy to change.
Bash is the Internet Explorer of shells. It’s great for installing a more useful shell.
That’s super unkind and incorrect. IE was a trash software that was widely available because MS was trying to extend their monopoly into new areas.
Even if it’s not your taste, bash is a mature, stable FLOSS package with wide community support. The reason it is so common is due to it’s positive attributes, not because there is a plot to make it the only choice available to you.
Bash might be better than IE. But I think we can agree that it is no longer a good shell.
Its syntax is awful, and lacks many features that other shells have.
It is only so widely used because it is a de facto standard. If bash was created today, barely no one would us it.
That’s not true. Internet Explorer was fucking useless for scripting together things, unlike bash.
Internet Explorer shell expansion always trips me up.
What shell do you recommend?
I like zsh, but some people say great things about fish.
My problem with those is bash is always there and just works.
Yes, just like Internet Explorer.
It’s good to know how to do things in bash, since you’re going to encounter it pretty often. But, that doesn’t mean you shouldn’t customize your shell on the machine(s) you use most often. Why stick with the default when there are better options? You’re just hobbling yourself.
history | grep then !cmd no
I just use mcfly
Not sure I understand the point of mcfly. zsh and fish have this functionality built in, where pressing Up with a command partially typed will give auto-completions to that partial match.
Yeah. I also use auto-completions for that. McFly does fuzzy finding and because it’s a different separate db, for me it works better across many sessions to find commands I had just recently used in another session.
…Yeah, you got me.
Being able to just enter a partial command, and hit [up] to jump to prior commands that started in the same way in zsh is a godsend.
If you ever have to go back to bash, it supports it as well. In my bashrc:
bind '"\C-p":history-search-backward'
That’s ctrl-p, but I’m sure the up arrow is possible too.
I use vim keybindings and have
ESC,/
to do a reverse command search.
The one people see me doing that gets a “huh?” Is:
~$ !find find -type f -name '*blah*' -print0 | xargs -0 gzip ~$
“Wait! What did you do?” “Oh. Do you not know about bang?”
I love the excitement of using !?
Did I remember correctly what command sequence I last used that pattern with? Will my data be gone? Will I send a vulgar email to my boss? Who knows, let’s find out!
That’s why you can add “:p” to the end just to print it.
I don’t understand people who have the confidence to just blindly run the last matching command like that. Like, are you 100% sure that the last time you ran find was that one, not the one that piped to
xargs rm
?At least with zsh you can tab to complete the
!find
and verify it’s what you want before running it. And, AFAIK by default, the shell optionhist_verify
is set, so if you do just type!find
and hit enter, it doesn’t run the command, it loads the command into the editing buffer so you can look it over first. Maybe I just have a weak memory, but I really appreciate the footgun prevention. At worst I have to hit enter twice. At best, I save myself a lot of grief.Normally the use case is
- Constructed a long command, but it didn’t work for some reason.
- I go fix the reason it didn’t work
- I do the first thing again
It’s in my recent memory, but maybe there’s been 10 or so commands of me fixing stuff in-between.