Live data from Hacker News

Level Up Your Shell Game

viget.com

31–40 of 50 posts

Re: Level Up Your Shell Game

#31
post #21
post #2

I didn't see Ctrl-r, but I've found that to be the most insanely useful shortcut. Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it'll find the most recent executed command with that substring in it. Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.

A complementary tip for Ctr+R is to tag long reusable commands with a comment in the end, e.g., find . -name "*.png" -print0 | xargs -0 -P8 pngquant --ext .png --force 256 #optimizepng (if you’re using zsh, you have to enable INTERACTIVE_COMMENTS option first; just run set -k)

Cool tip, did not know that, though I prefer to put long reusable commands in script files, in part so I can comment them to better remember what everything is doing.

Re: Level Up Your Shell Game

#32
post #2

I didn't see Ctrl-r, but I've found that to be the most insanely useful shortcut. Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it'll find the most recent executed command with that substring in it. Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.

Since I've switched to zshell, I've found that I haven't used Ctrl-r much at all. The intelligent history feature does it for me. For example: If earlier I had a long command like `mvn clean test && mvn deploy -P release`, I can just type `mvn v` and press up on the arrows. zsh will present only history entries that start with what I've typed. Insanely useful!

The same thing can be done in bash:

## arrow up

"\e[A":history-search-backward

## arrow down

"\e[B":history-search-forward

(in .inputrc)

Re: Level Up Your Shell Game

#34
post #26

They should really mention which shell and terminal emulator they are using. Not everyone is using the same "Unix command line".

Fair point. FWIW, we're all on OS X, running bash, zsh, or fish on either Terminal.app or iTerm2.

Control-Left and Right switch workspaces for me. A giant pain in the ass, because the normal word-jump shortcut, Option-Left/Right, just drops a [C/[D into the shell on iTerm. The stupid thing is, if I shell into an Ubuntu machine, it works fine.

Re: Level Up Your Shell Game

#36
When you execute a command that takes a long time to run and you want to send it to the background you can do:

ctrl + z

then, to send it to the background:

bg

and, to get it back from the background:

fg

Also, I really like to use "for", like:

// get the size of each file or directory in the current directory

for i in `ls -1`; do du -hs $i; done;

Re: Level Up Your Shell Game

#38

Here is a rule for how to level up your shell/editing game. If you ever touch your arrow keys, you are doing something wrong. > ctrl + left arrow Moves the cursor to the left by one word > ctrl + right arrow Moves the cursor to the right by one word Alt + b and Alt + f are also aliases for the same action.

uhh.... So what's wrong with doing the exact same thing with arrow keys? isn't that more natural and convenient?

Re: Level Up Your Shell Game

#39

Earlier quoted context omitted.

Since I've switched to zshell, I've found that I haven't used Ctrl-r much at all. The intelligent history feature does it for me. For example: If earlier I had a long command like `mvn clean test && mvn deploy -P release`, I can just type `mvn v` and press up on the arrows. zsh will present only history entries that start with what I've typed. Insanely useful!

The same thing can be done in bash: ## arrow up "\e[A":history-search-backward ## arrow down "\e[B":history-search-forward (in .inputrc)

I prefer mapping those to page up and page down.

Re: Level Up Your Shell Game

#40
post #26

Earlier quoted context omitted.

Fair point. FWIW, we're all on OS X, running bash, zsh, or fish on either Terminal.app or iTerm2.

Control-Left and Right switch workspaces for me. A giant pain in the ass, because the normal word-jump shortcut, Option-Left/Right, just drops a [C/[D into the shell on iTerm. The stupid thing is, if I shell into an Ubuntu machine, it works fine.

You can probably set that up in .inputrc. Pressing Ctrl-V in a terminal before pressing your ctrl+left or ctrl+right arrow will type the initial escape character literally so you can see what the key sequence is (e.g. something like \e[1;5D).

Alternatively, you could change your workspace bindings to Control+[some other modifier].

Post reply on HN