Top
Best
New

Posted by zdw 23 hours ago

Shell Tricks That Make Life Easier (and Save Your Sanity)(blog.hofstede.it)
492 points | 228 commentspage 4
SoftTalker 7 hours ago|
I knew most of these but the $_ variable and "ESC + ." to reference or insert the last argument of the previous command. I can see getting some use out of that, so thanks for posting.
t312227 7 hours ago|
or - as an alternative to <esc> + ".":

for the last argument

* <alt> + "."

if you want the -<n>th argument:

* <alt> + "_" # n times :=)

* <alt> + "."

cheers a..z

arttaboi 7 hours ago||
"cd -" is a lifesaver. Thank you so much for this.
thibran 5 hours ago||
Its almost ironical that we still use the Terminal - and many use it like in the eighties using Bash - and seem to have forgotten that we should invent a better terminal & shell than doing all the workarounds to handle the quirks of the current systems.
mmh0000 4 hours ago|
Make a better system, and we'll consider using it.

A Terminal + Bash/ZSH is soooo sticky because they are VERY good at what they do once you learn the basics and quirks. And now with LLMs, CLIs are even better because LLMs talk in text and CLIs talk in text.

Microsoft tried with PowerShell to design a better system; it "technically" is better, but not "better enough" to justify the cost of switching (on Linux). The same is true of nushell; it is "better", but not better enough to justify switching for most people.

I believe we're at "peak input method" until someone invents Brain<->Computer interfaces.

thibran 4 hours ago||
I use the Terminal all the time and write my own CLI tools, but I'm feeling more and more the limits of the current system. With the years I have used almost all available shells (EShell was even my default for some time). Right now my favorite shell is Nushell, but still, it feels dated compare to what is possible on modern computers.

> Make a better system, and we'll consider using it. It's on my TODO list, but it will break with all conventions and tools (no TTY). My idea is to bring the chain-things-together idea to the 21st century using a keyboard first GUI.

Joker_vD 14 hours ago||
> The “Works (Almost) Everywhere” Club

> The Backspace Replacements

Also known as "emacs editing mode". Funnily enough, what POSIX mandates is the support for "vi editing mode" which, to my knowledge, almost nobody ever uses. But it's there in most shells, and you can enable it with "set -o vi" in e.g. bash.

ZeroGravitas 14 hours ago||
Vi mode is also available in Claude code and gemini-cli to give some recent examples, and a bunch of other places you might not expect it, as well the more obvious places where code is written.

Once you get used to it, it is painful to go back.

mr_mitm 14 hours ago||
My biggest complaint about the fish shell is the lack of true vi mode. They attempt to emulate it and it works to some degree, but it's no comparison to readline's implementation.
dunb 8 hours ago|||
What is it lacking in your eyes that makes it not true? I find fish’s vi mode more ergonomically complete for things like editing multi-line commands
mr_mitm 7 hours ago||
Just pressing `xp` to swap two characters does not work in fish. Combining deletion with a movement also does not work (e.g. `d3w` to delete three words).
maleldil 9 hours ago||||
You can always use Alt-E to open the command line in $EDITOR if you need more powerful commands. I find it better to use readline for small changes and jumping to vim for bigger ones.
umanwizard 8 hours ago|||
Have you tried a recent version? An issue I opened about this years ago was finally closed, they claim it’s fixed now. I haven’t tried the purported fix, though.
mr_mitm 7 hours ago||
Yes. It has improved, but it's still not there, and probably never will be. See my reply to your sibling comment.
worksonmine 13 hours ago||
And if you set `set editing-mode vi` in ~/.inputrc (readline configuration) you'll have it in even more places.
ta8903 14 hours ago||
Something that should be mentioned is starting a command with a space doesn't add it to your history in most shells, really useful for one-off commands that you don't want cluttering your history.

Also, increase your `$HISTSIZE` to more than you think you would need, there have been cases where it helped me find some obscure command I ran like 3 years before.

account42 10 hours ago|
HISTCONTROL=erasedups can also help keeping more obscure commands in your history, at the expense of context around commands.
egorfine 11 hours ago||
I'm using bash for over 30 years and I still find new things. Nice.
vdm 14 hours ago||
Ctrl-r works well at searching character trigrams, which can include space. Trigrams without space work well with auto_resume=substring .

`| sudo tee file` when current user does not have permission to >file

williamcotton 11 hours ago||
Undo:

  Ctrl + _ (Ctrl + underscore)
bandie91 9 hours ago|
it did not work for me in putty, so i added ctrl-x + ctrl-u too:

  bind '"\C-x\C-u": undo'
  bind '"\C-_": undo'
More comments...