Live data from Hacker News

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

blog.hofstede.it

61–70 of 287 posts

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

#61

I love this, from a comment on the article: He had in his path a script called `\#` that he used to comment out pipe elements like `mycmd1 | \# mycmd2 | mycmd3`. This was how the script was written: ``` #!/bin/sh cat ```

What does it provide over mycmd1 #| mycmd2

Theirs "turns off" one element of a pipeline; yours turns off everything after a certain point.

This will output the stdout of mycmd1:

    mycmd1 #| mycmd2 | mycmd3
This will output the stdout of mycmd3:

    mycmd1 | \# mycmd2 | mycmd3

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

#62
post #13

Earlier quoted context omitted.

In my terminal it's the exact opposite – Alt-Backspace deletes to the previous space, whereas Ctrl-W deletes to the last non-alphanumeric (such as /). I'm using fish shell in an Alacritty terminal. Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.

> Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend. Fun fact: despite having absolutely no menu entry for it, and I believe not even a command available with Ctrl+Shift+P, Vscode supports Ctrl+Shift+T to re-open a closed tab. Discovered out of pure muscle memory.

It's a normal command called "View: Reopen Closed Editor".

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

#63

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.

> cc

Doing control+o in insert mode temporarily places you into normal mode so that you can execute one normal-mode command, and then go back to insert mode again--no need to hit 'i' again.

So, instead of 'cc', 'S'.

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

#65

I just open, agent in tui, and ask it to do what I want and make a plan, i read the plan edit it and run it. Simple, no need to learn any commandline these days. I used to use arch and all, and managed many big projects. I find little value in learning new tools anymore, just feed it docs and it generated working plan most of the time Now I've moved to coding in Haskell, which i find suits me better than wasting my t…

I'm confused; how is writing a shell command (using shortcuts like those in the article!) "wasting time", but describing what you want to an LLM, having it make a plan, reading the plan, editing it, and running it is somehow not a waste of time?

You also mention there being "little value", when your proposed approach costs literal money in form of API/token usage (when using hosted models).

> Now I've moved to coding in Haskell

You might like https://hackage.haskell.org/package/turtle or http://nellardo.com/lang/haskell/hash/

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

#66
Another useful "Emergency exit" is CTRL+Z which stops the process and cannot be intercepted.

It's often faster than hitting CTRL+C and waiting for process cleanup, especially when many resources are used. Then you can do e.g. `kill -9 $(jobs -p)` to kill the stopped tasks.

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

#67
post #66

Another useful "Emergency exit" is CTRL+Z which stops the process and cannot be intercepted. It's often faster than hitting CTRL+C and waiting for process cleanup, especially when many resources are used. Then you can do e.g. `kill -9 $(jobs -p)` to kill the stopped tasks.

ctrl-z pauses the process, it doesn't terminate. I think of z as in zombie as you can then run fg to bring it back from paused state or as you suggested kill in it for good

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

#68

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.

I've been a (n)vim user for 20+ years now, but I hate vi-mode in the shell. However if I feel that I need to do a complex command, I just do ctrl-x+e to open up in neovim (with EDITOR=nvim set). I find it a good middle ground.

Huh. I don’t use vi-mode for more than jumping to the beginning or end of a line, which I like a lot.

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

#69

Is it just me, or is it an LLM language? The article tries very hard to be correct but somehow lacks experience. I've never used the majority of these tricks for decades, except for brace expansion, process substitutions, and complex redirections.

I knew many of these tricks, but learned many new tricks I didn't know and looks very useful (like you can do Ctrl-Y after an Ctrl-U, the 'reset' or 'disown' thing).

Regarding experience, I'm also struck by how many "experienced" engineers are just clueless with the keyboard.

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

#70

Earlier quoted context omitted.

I've been a (n)vim user for 20+ years now, but I hate vi-mode in the shell. However if I feel that I need to do a complex command, I just do ctrl-x+e to open up in neovim (with EDITOR=nvim set). I find it a good middle ground.

Huh. I don’t use vi-mode for more than jumping to the beginning or end of a line, which I like a lot.

You mean, like the “home” and “end” buttons?
Post reply on HN