Live data from Hacker News

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

blog.hofstede.it

141–150 of 287 posts

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

#141
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...

I've installed "More Better Ctrl-W" for Chromium, and mapped Ctrl-W to do nothing, and Ctrl-D to close the current tab

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

#142
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.

export EDITOR=vi and then hitting Esc puts you into vi mode; k, j to move up/down through history or pressing / to search etc including using regex is all available.

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

#143
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...

...which is why I recently went to about:keyboard and removed that hotkey. I love that page.

That, and Ctrl-N. No more forest of blank browser windows when using a terminal emulator in a web page!

(Firefox only)

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

#144
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?

We're basically playing a game: if you have to leave homerow hand position, you've lost

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

#145
post #87

Earlier quoted context omitted.

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

I'm familiar with ctrl-r, but I still very much like the up-arrow behavior described by that commenter.

Looking at it from a "law of least surprise" angle, it's exactly how it should behave.

"I typed 'cd di↑' and you're giving me 'pwd'??"

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

#146
post #121
post #111

Earlier quoted context omitted.

> This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think it's a question of context and familiarity. To a vim user, like me and, I assume, ahmedfromtunis, their examples do indeed seem simple and natural. Presumably, to an emacs user, the example you quote (if it's quoted literally—I don't use emacs and can't even tell) is just as natural, and assuming som…

> assuming some comfort with emacs is presumably OK in a manual for the software! How do you get familiar with the software, if the manual expects you to be an expert in it already?

I got familiar with vi by reading a book that had the main vi commands listed out. First learnt how to quit without saving changes, the rest was just practice.

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

#147
Here's my favorite tip: If you use bash, you can write bash on your prompt (duh). But this is one of the biggest reasons I stick with bash everywhere, as I am quite comfortable and experienced in bash and sometimes it's just easier to write things like `for i in *.mp3; do ffmpeg -i $i ...` etc. If it's re-usable, I write it to a bash script later.

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

#148

set -o vi puts you into vi mode at the cli prompt with all the semantics of the editor. These carpal tunnel riddled hands can’t be bothered to reach for ctrl or alt let alone arrow keys.

If you aren't aware already, you can put 'setxkbmap -option ctrl:swapcaps' in one of your startup config files, like .bashrc or somesuch. That flips left CTRL and CAPS LOCK.

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

#149
post #75

I've been using a lot of key combinations and I wasn't aware of these two, and I really think these are awesome additions to handling the console. Thank you for showing me. I've only been using it for 22 years, but I haven't come across these :D `CTRL + U and CTRL + K CTRL + W` What I like about these key combinations is that they are kind of universal. A lot of programs on Linux and Mac support all these key combina…

Yes, those are shortcuts used in the GNU readline library, which many programs use whenever they need to read lines of text interactively from their operators. Notable examples are (most) shells, (most) interpreters, and tools like ftp, fzf, etc.

Notably, these keybindings are it's default map, which comes from the GNU's project editor Emacs. But, there is also the POSIX-compliant, but not-default, editing mode based on Bill Joy's visual editor (vi).

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

#150
post #138
post #22

Earlier quoted context omitted.

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.

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

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).
Post reply on HN