Wow I didn't realize !! is treated like an escape sequence, so it will expand even inside quotes (double quotes, but not single quotes). I can imagine someone going echo "hello world!!" and being very confused.
one pro tip i use all the time is jobs. Ctrl+Z to suspend/pause the current shell command and then fg to get back to it. jobs to list all currently suspended commands.
Should have mentioned this (coppied from bash(1)): operate-and-get-next (C-o) Accept the current line for execution and fetch the next line relative to the current line from the history for editing. A numeric argument, if supplied, specifies the history entry to use instead of the current line. Basically in bash, after doing a reverse search (C-r) you can run that command and get the next ready to run, and the next and the next... (possibly changing them before running) This is very useful.
Wow, very cool stuff :) didn't know about reverse-search. I always just grep on my history command, then use `!` for the entry I want to run. If I want to edit it I use `!:p`. Re: fc, I usually run `set -o vi` so I can run vi motions from the terminal, from there I can use `v` to edit commands. Nice post!
I think `Ctrl+Shift+u` for unicode is not Bash, but rather a GTK+ feature; which is where the shell session is running (inside a gnome-terminal, which happens to be GTK+). It also works in many other shells inside a GTK-based terminal, and further-more even in the web-browser. For instance, it doesn't work on Bash running inside Alacritty, and it works different on Kitty Terminal
Reverse search (Crtl-r) is pretty universal. It works in python REPL, bash, zsh, PowerShell and many more. You can import prompt_toolkit and replace "input" with "prompt" and have your own reverse search. Its very easy: from prompt_toolkit import PromptSession session = PromptSession() while True: answer = session.prompt("Give me some input: ") print(f"You said: {answer}") if answer == "exit": break
^R is a readline feature -- all those things use readline when available (python on windows for example does not support it, and very frequently pyenv-compiled python doesn't either)
Ctrl+D doesn't work if the connection is stuck. For example if your wifi got disconnected while you were ssh'd into a server, neither ctrl+C or ctrl+D will do anything, you will have to close the terminal. But ~. worked to my surprise and it's a nice trick to know
Ctrl + x then Ctrl + e opens the current terminal line in an editor, so similar to fc, but is better, because it works across multiple shells and together with history navigation is slightly more powerful.
@@anthonywritescode I did, but missed the mention of it also missed the Alt + . (dot) the first time. Just spaced out. At least the info that it works in shells other than bash was not in the vid ;D
Wow I didn't realize !! is treated like an escape sequence, so it will expand even inside quotes (double quotes, but not single quotes). I can imagine someone going echo "hello world!!" and being very confused.
heh and this is why I almost always use hard-quotes (single quotes)
hah, quite the gotcha indeed
Or trying to do a commit with the inline message "Done!!"
I actually had this happen to me early on when using bash.
one pro tip i use all the time is jobs. Ctrl+Z to suspend/pause the current shell command and then fg to get back to it. jobs to list all currently suspended commands.
yep -- I go over that in th-cam.com/video/lkQOQAc65ZA/w-d-xo.html
Nice, some really good-to-knows there :) I also like Ctrl+p+q for detaching from an interactive docker container.
Should have mentioned this (coppied from bash(1)):
operate-and-get-next (C-o)
Accept the current line for execution and fetch the next line
relative to the current line from the history for editing. A
numeric argument, if supplied, specifies the history entry to
use instead of the current line.
Basically in bash, after doing a reverse search (C-r) you can run that command and get the next ready to run, and the next and the next... (possibly changing them before running) This is very useful.
Wow, very cool stuff :) didn't know about reverse-search. I always just grep on my history command, then use `!` for the entry I want to run. If I want to edit it I use `!:p`. Re: fc, I usually run `set -o vi` so I can run vi motions from the terminal, from there I can use `v` to edit commands. Nice post!
I think `Ctrl+Shift+u` for unicode is not Bash, but rather a GTK+ feature; which is where the shell session is running (inside a gnome-terminal, which happens to be GTK+). It also works in many other shells inside a GTK-based terminal, and further-more even in the web-browser.
For instance, it doesn't work on Bash running inside Alacritty, and it works different on Kitty Terminal
indeed! a few have shown me this before as well
afaik ctrl-shift-u is a Gnome-specific unicode entry mode. It works everywhere in Gnome, but not outside of Gnome.
Actually, it's GTK+ specific. It doesn't work, even inside GNOME, if the application is not GTK-based. For instance Alacritty or XTerm
I find it easier to memorize the ESC+ instead.
Eg: ESC+. will write the paste the last argument. ESC+backspace will delete the last word. etc...
I assume you map capslock to control, otherwise those are quite the stretch!
Alt+. will also produce the same effect, though the escape method allows you to fully press and release escape before tapping dot, etc.
you can also do control-[ + . as well
As always brilliant content !
Absolutely love these kind of videos! Thanks :)
I use mcfly as a ctrl-r extension. It’s recommendation algo and easy viewing of previous commands is really usefull
You're a total boss, dude! Your videos are gold!
Great video. Can I fork the wiki for the references?
Reverse search (Crtl-r) is pretty universal. It works in python REPL, bash, zsh, PowerShell and many more. You can import prompt_toolkit and replace "input" with "prompt" and have your own reverse search. Its very easy:
from prompt_toolkit import PromptSession
session = PromptSession()
while True:
answer = session.prompt("Give me some input: ")
print(f"You said: {answer}")
if answer == "exit":
break
^R is a readline feature -- all those things use readline when available (python on windows for example does not support it, and very frequently pyenv-compiled python doesn't either)
@@anthonywritescode Just checked both cmd and new Microsoft Terminal on windows and reverse search works in python with no problem.
you must've installed readline -- the official distributions do not come with functioning readline
@@anthonywritescode You are right, I installed pyreadline. Forgot about this module
Cool keyboard, what is it?
it's the kinesis freestyle pro! here's my thoughts on it: th-cam.com/video/DZgCUWf9DZM/w-d-xo.html
how to get out of the editor after the fc command?
just quit the editor like normal -- (so if it's vim, you'd `:wq`, if it's babi you'd `^X`)
ctrl+. for emoji chart or tabel ,
unlike ctrl+shift+u youdont have to remember the unicode value
😉
doesn't work on linux or windows -- must be a mac specific thing
`y` does work on gitlab. Unfortunately know this from experience.
you poor soul, gl with your choo choos
@@anthonywritescode "run train is against our coc"
Hi anthony, FYI, you typed your password while recording your keyboard ...
I think he uses a virtual machine to make videos so it doesn't actually matter : }
yep -- my password is literally "bad password"
you can use ctrl - D instead of ~. to close ssh connection. Or get out of the attached docker container terminal
Ctrl+D doesn't work if the connection is stuck. For example if your wifi got disconnected while you were ssh'd into a server, neither ctrl+C or ctrl+D will do anything, you will have to close the terminal. But ~. worked to my surprise and it's a nice trick to know
nope! ~. is specifically needed when the session is stuck and you want to forcibly detach
Ctrl + x then Ctrl + e opens the current terminal line in an editor, so similar to fc, but is better, because it works across multiple shells and together with history navigation is slightly more powerful.
you didn't watch the video
@@anthonywritescode I did, but missed the mention of it also missed the Alt + . (dot) the first time. Just spaced out. At least the info that it works in shells other than bash was not in the vid ;D
@@con-f-use Doesn't work in zsh apparently
Timestamps would be very much appreciated. 🤙
if you compile them I'll put them into the description!
Title should have been useful bash tricks I wish I knew
not all of them are bash
^r is a great one thanks ! There was me doing history | grep git all this time