Live data from Hacker News

Bash Shortcuts For Maximum Productivity

skorks.com

41–50 of 58 posts

Re: Bash Shortcuts For Maximum Productivity

#41

I am a huge fan of maximizing productivity in the shell. I wrote these three articles a while ago: Bash emacs-like keyboard shortcuts: http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s... Bash vi-like keyboard shortcuts: http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-shee... Definitive bash guide to command line history: http://www.catonmat.net/blog/the-definitive-guide-to-bash-co... And they all…

Great articles. I'm just starting to get into the hang of vi. I'm giving vi-mode in bash a go (with "set -o vi") but there doesn't seem to be any indication of when I'm in command/insert mode. Is there any way to see this?

Re: Bash Shortcuts For Maximum Productivity

#42

A note to Mac users: Instead of Alt, you must press escape key. For example, Esc+b moves the cursor backward one word in bash, but you'll probably want to use option instead, so check 'Use option as meta key' in Terminal's settings (under keyboard tab). But if it's not very handy, you can set 'option+left arrow' to move cursor one word backward. To do that, open Terminal's settings, go to keyboard and add a shortcut…

I am iTerm user so for those folks here is the setup you need to make "option" key the 'meta' key in iTerm

http://stackoverflow.com/questions/196357/making-iterm-to-tr...

I still don't like it since I am so used to hitting the Apple key in emacs, but it beats having to use Esc+

Re: Bash Shortcuts For Maximum Productivity

#43

I am a huge fan of maximizing productivity in the shell. I wrote these three articles a while ago: Bash emacs-like keyboard shortcuts: http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s... Bash vi-like keyboard shortcuts: http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-shee... Definitive bash guide to command line history: http://www.catonmat.net/blog/the-definitive-guide-to-bash-co... And they all…

Great articles. I'm just starting to get into the hang of vi. I'm giving vi-mode in bash a go (with "set -o vi") but there doesn't seem to be any indication of when I'm in command/insert mode. Is there any way to see this?

I don't know of a way to do it.

Re: Bash Shortcuts For Maximum Productivity

#44
post #24

I use `..` to go upper directory, `...` to go up two levels, I added this to bashrc: str='..' level='./../' for i in `seq 1 10`; do eval "alias '$str=cd $level'" level=$level'../' str=$str'.' done Note, seq is not available in Mac, should use jot instead.

There's no need for seq or jot. In bash you can replace `seq 1 10` with {1..10}. Or {01..10} if you want zero padding when using $i to label files. I use an function called "up" that takes an optional integer argument to go up a certain number of levels. It won't necessarily be faster, but somehow I prefer it to typing lots of dots in a row: function up () { if test $# = 1 ; then s=$( printf "%$1s" ); s=${s// /..\/};…

Thanks for pointing out that

Re: Bash Shortcuts For Maximum Productivity

#45

I am a huge fan of maximizing productivity in the shell. I wrote these three articles a while ago: Bash emacs-like keyboard shortcuts: http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s... Bash vi-like keyboard shortcuts: http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-shee... Definitive bash guide to command line history: http://www.catonmat.net/blog/the-definitive-guide-to-bash-co... And they all…

Great articles. I'm just starting to get into the hang of vi. I'm giving vi-mode in bash a go (with "set -o vi") but there doesn't seem to be any indication of when I'm in command/insert mode. Is there any way to see this?

There is a workaround in zsh http://superuser.com/questions/151803/how-do-i-customize-zsh...

Re: Bash Shortcuts For Maximum Productivity

#46

Earlier quoted context omitted.

Comment it out (put a # at the front), unless your shell is set to ignore commented lines.

This works great! There is even a shortcut: M-#

You said copy-paste - are you using the OS copy-paste or readline's kill ring? C-a C-k is pretty fast, and then can be retrieved with C-y.

Re: Bash Shortcuts For Maximum Productivity

#47
Most of the commands there can be replaced with vi keybindings.

That is, set -o vi

You can type that directly into your terminal for use just in one session or in your .bashrc

Type or just like in vim to escape into "command" mode. Most command mode commands work. E.g. '^' goes to the beginning of the line '$' goes to the end. 'i' sets bash back into insert mode.

Re: Bash Shortcuts For Maximum Productivity

#48

Earlier quoted context omitted.

This works great! There is even a shortcut: M-#

You said copy-paste - are you using the OS copy-paste or readline's kill ring? C-a C-k is pretty fast, and then can be retrieved with C-y.

This is another great solution. As a vim user I haven't much looked into the emacs keybindings in readline. I'll have to read up. Also the terminology was a little confusing. I didn't realize that killing a line was the same as "cutting".

Re: Bash Shortcuts For Maximum Productivity

#50
post #22

I'm a zsh user, but here's a couple of things I find pretty invaluable:- bindkey '^Q' push-line The 'push-line' widget allows you to quickly type another command and will restore the previous one once you've entered it. # re-run the previous command with sudo rerun-with-sudo () { LBUFFER="sudo !!" zle accept-line } zle -N rerun-with-sudo bindkey '^Xx' rerun-with-sudo Re-run the previous command prefixed with sudo by…

I'm also a big zsh user, one of the biggest timesavers for me was to get autocompletion of the arguments from the last command working. I use meta-. for the last argument, but !:# syntax is awkward and I don't often remember exactly what number parameter something was. Took a bit of screwing around, but I eventually figured it out and the details are on the unix/linux stack exchange site: http://unix.stackexchange.com/questions/5229/add-arguments-f...
Post reply on HN