Live data from Hacker News

Shell Tricks That Make Life Easier (and Save Your Sanity)

blog.hofstede.it

241–250 of 287 posts

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#241
post #87

One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down

Once you start using CTRL+r, you may find that you never reach for up arrow again.

Atuin[1] feels like the best of both worlds to me.

[1] https://github.com/atuinsh/atuin

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#243

I'd advise against using sudo !! though since it adds the command to history and then it's very easy to accidentally trigger, running some undesired command as root without any prior confirmation. IMO pressing up, Ctrl-A and typing "sudo " isn't much longer but saves you from running unknown commands as root by accident

in zsh pressing esc twice appends sudo to the last command

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#244

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.

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 s…

Powershell and nushell are both miles better than bash and its descendants. I switched to nushell and you couldn't pay me to go back to bash. I only wish that it was kosher to install it on servers at work, but alas it isn't so I have to suffer with bash when managing systems.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#245

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.

We did! Nushell and Powershell are both so much better than bash that it's not even funny. There's zero reason to use a bash derivative in this day and age, they only persist through inertia + a minority of masochists actually like bash.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#246

Earlier quoted context omitted.

What is it like to be this proud of not learning the tools you use? Do you really think several paragraphs to an agent that may or may not be correct is the "easy" way compared to just checking the manual for the flag you want? I will never understand people like you.

Tools are means to end. They don't matter much to me.

That's fine to a point. But if you don't learn your tools, you will have rendered yourself unable to catch when the LLM gets things wrong (and it will get things wrong because it doesn't understand anything it touches). That, in turn, will mean that you're going to struggle to reach your desired ends but won't have the understanding to figure out what's wrong.

"Tools are just a means to an end" means you need to not get attached to a tool if it's not doing the job. It doesn't mean you don't need to understand your tools.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#247

One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down

I'd try this, but I often find that I want to repeat a cycle of two or more commands. Yes, I probably should edit and put them on one line with semicolons (or even make a function), but.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#248

Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.

Eh, it's not that different from the default readline commands

A mistake 3 words earlier? No problem: 3 Alt-b Alt-d

Want to delete the whole thing? Even easier: Ctrl-U

I can even use Ctrl-X Ctrl-e to open the command inside a fully-fledged EDITOR instance for more complex rework.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#249

Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.

This reminds me of an excerpt from an old Emacs manual: . . . if you forget which commands deal with windows, just type @b[ESC-?]@t[window]@b[ESC]. This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think the better advice for command-line editing would be to set up the mouse.

I think you're confused by the markup. It looks like it's saying Alt-? (Alt and Esc are interchangeable due to terminal reasons) to open up the help search and then type 'window' to search for window commands. Sounds pretty simple to me

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#250

One trick I use all the time: You're typing a long command, then before running it you remember you have to do some stuff first. Instead of Ctrl-C to cancel it, you push it to history in a disabled form. Prepend the line with # to comment it, run the commented line so it gets added to history, do whatever it is you remembered, then up arrow to retrieve the first command. $ long_command $ #long_command $ stuff_1 $ stu…

Fwiw, in Bash, alt-shift-3 will prepend the current command with # and start a new command.

Thank you so much! I do this constantly. For me it was Ctrl-A Shift-3 Enter - two keystrokes too many.
Post reply on HN