Live data from Hacker News

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

blog.hofstede.it

171–180 of 287 posts

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

#171
post #2

Not a fan of the LLM-flavoured headings, and the tips seem like a real mixed bag (and it'd be nice to give credit specifically to the readline library where appropriate as opposed to the shell), but there are definitely a few things in here I'll have to play around with. One thing I dislike about brace expansions is that they don't play nicely with tab completion. I'd rather have easy ways to e.g. duplicate the last…

Readline is close enough to being part of bash that it’s not really inaccurate to call these all shell features imo.

Except not everyone uses bash shell - so it's not really accurate.

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

#172
post #87

Earlier quoted context omitted.

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

There is a difference, I believe. Doesn't Ctrl+r do a substring search instead?

Yes it's different: it will match anywhere in the previous command lines.

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

#173

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 do something similar. I leave up and down arrows alone, but have ctrl+p and ctrl+n behave as you describe.

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

#174

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 ```

Wow I hate* that. I use bracket comments. They're cool cause they are bracket comments, so I use it in scripts to document pipelines. They are annoying cause they are bracket comments, in an interactive shell I have to type more and in TWO places. It's fun to reason-out how it works ;)

  $ echo foo | tr fo FO | sed 's/FOO/BAR/'
  BAR
  $ echo foo | ${IFS# tr fo FO | } sed 's/FOO/BAR/'
  foo
It's nice to have a way to both /* ... */ and // ... in shell scripts though:

  foo \
  | bar ${IFS Do the bar. Do it. } \
  | baz
* in the best possible way, like it's awful - I hate I didn't think of that

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

#175
post #139

Earlier quoted context omitted.

It’s strange. I have heard this from lots of others too. I think I am an anomaly here. I can’t live without shell vi mode

You're not alone, I heavily rely on vi mode and often struggle if I'm on someone else's machine and can't use it. I always wonder how you're supposed to work without it but I never dare to ask

`set -o vi` is quickly typed in anger...

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

#176

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.

I used to hate it because I'd sometimes change modes without realizing it, but I began to appreciate it a lot more when I added a mode indicator -- a red 'N' on the rightmost side of the input line.

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

#178

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 think the keybinding suggestions are really nice. My shell is configured by default such that Alt+Left and Alt+Right move by a word, but having things that work out of the box, basically always, is really useful whenever I need to do things inside a docker container

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

#179

Earlier quoted context omitted.

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 think it’s a difference in how people think. I can’t remember hotkeys. It just doesn’t compute. But with vim style bindings it’s much closer to writing a sentence. `3`, number of times, `b`, beginning of word, `c`, change, `w`, word. Yea it’s a lot. I cannot explain why it’s simpler for me to learn that than emacs style bindings but it is.

Obligatory:

Your Problem with vim is you don't grok vi

https://stackoverflow.com/questions/1218390/what-is-your-mos...

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

#180
post #26

What confuses me is that Ctrl+Y "yank" means the opposite of what it means in Vim. Certainly does not help with keeping my sanity.

That is because the terminology (and the keybindings) come from the Emacs tradition, not vim. Most shells come with “vim mode” as well, but at least in my experience, the dual mode editing paradigm of does not feel like a good fit for the shell.
Post reply on HN