Live data from Hacker News

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

blog.hofstede.it

51–60 of 287 posts

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

#51

There's one thing you need to only think about once, and has the potential to save you a ton of time: profile your ZSH startup time! Stuff like NVM or Oh My ZSH will add a few seconds to your shell startup time.

I can recommend powerlevel10k with instant prompt enabled.

https://github.com/romkatv/powerlevel10k

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

#52
> We’ve all been there.

Close tab.

I ought to migrate away from shell scripting and just keep the shell for interactive use. Unfortunately I have cursed myself by getting competent-ish with P. shell and Bash scripting. Meaning I end up creating maintenance headaches for my future self.

(Echoes of future self: ... so I asked an LLM to migrate my shell scripts to Rust and)

Anyway with the interactive shell stuff. Yeah the I guess Readline features are great. And beyond that I can use the shortcut to open the current line in an editor and get that last mile of interactivity when I want it. I don’t really think I need more than that?

I tried Vim mode in Bash but there didn’t seem to be a mode indicator anywhere. So dropped that.

Edit: I just tested in my Starship.rs terminal: `set -o vi`. Then I got mode indicators. Just with a little lag.

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

#54
post #31
post #8

CTRL + W usually deletes everything until the previous whitespace, so it would delete the whole '/var/log/nginx/' string in OP's example. Alt + backspace usually deletes until it encounters a non-alphanumeric character. Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...

Set $WORDCHARS accordingly. In your case, remove / from $WORDCHARS. https://unix.stackexchange.com/a/726014

For the bash people

  stty werase undef
  bind '"\C-w": backward-kill-word'

source: https://superuser.com/questions/212446/binding-backward-kill...

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

#55

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.

More generally, it's alt-#. On an ISO (e.g. UK) keyboard layout, shift-3 isn't a hash.

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

#56
post #49

Earlier quoted context omitted.

3bcw What is your keyboard layout? This looks like a crime against humanity on a regular qwerty kb.

Instead of esc, type ctrl [

Does it help a lot? You've still got a three to type which is a crime, plus some letters, only to move 3 words. My typing skills are not great, but that sounds like an awful lot of work(?)

If I hit CTRL + ARROW_LEFT 3 times, I am done a lot faster I guess. But I am open to learn, do people really use that and achieve the goal significantly faster?

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

#58

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…

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.

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

#59
post #49

Earlier quoted context omitted.

Instead of esc, type ctrl [

Does it help a lot? You've still got a three to type which is a crime, plus some letters, only to move 3 words. My typing skills are not great, but that sounds like an awful lot of work(?) If I hit CTRL + ARROW_LEFT 3 times, I am done a lot faster I guess. But I am open to learn, do people really use that and achieve the goal significantly faster?

I don’t love vi-mode, but I’ll address your comment.

Many people these days, including yours truly, have caps-lock mapped to ctrl if held or esc if tapped. That’s good ergonomics and worth considering for any tech-savvy person.

Instead of the 3b I would type bbb (because I agree with you that typing numerals is a pain).

So (caps lock)bbbcw isn’t bad. It’s better than it looks, because if you’re a vim user then it’s just so automatic. “cw” feels like one atomic thing, not two keypresses.

And importantly, it doesn’t involve any chords.

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

#60

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.

Post reply on HN