Bash Shortcuts For Maximum Productivity
skorks.com
Bash Shortcuts For Maximum Productivity
1–10 of 58 posts
Re: Bash Shortcuts For Maximum Productivity
#2But 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 for left arrow (with 'option' as modifier), and leave the action to 'send string to shell'. Then click on the textbox below that and press esc (which should print '\033') and then 'b', or simply type '\033b' in the textbox.
Just this simple shortcut makes Mac's Terminal 1000 times better.
Re: Bash Shortcuts For Maximum Productivity
#3Re: Bash Shortcuts For Maximum Productivity
#4A 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 also have 'option+right arrow' mapped to move cursor one word forward (use the same instructions as above, substituting 'f' for 'b').
Re: Bash Shortcuts For Maximum Productivity
#5[1] http://jan.tomka.name/sites/default/files/readline-commands....
Re: Bash Shortcuts For Maximum Productivity
#6http://hints.macworld.com/article.php?story=2003102617423686...
So if you've typed `verylongcommand` some indeterminate time in the past, you can probably just type "ver", and you'll have it. Very convenient.
Re: Bash Shortcuts For Maximum Productivity
#7Re: Bash Shortcuts For Maximum Productivity
#8I use them all the time, and anyone watching over my shoulder always asks what that was. Learn !!, !$, and a few modifiers. You'll be glad you did. Personally, I use !$ constantly (and variations like !-2$, which gets you the last arg from 2 commands ago). The "h" modifier is handy, too. It's like dirname for the word. Consider this example, where you copy a file to some deep path, and then cd to that dir to continue working with the copy:
$ cp foo.txt /some/really/long/destination/bar.txt
$ cd !$:h
$ # (do more with ./bar.txt)
The substitution (:s) and global substitution (:gs) modifiers are also useful: $ echo some args
some args
$ !!:s/some/more
more args
(Also, note that his explanation of !* is actually incorrect. He says it leaves off the last arg, but actually leaves out $0 (the command name). !* is all of the previous command's arguments.)Finally, one really useful thing he doesn't mention at all is brace expansion. For example, these are equivalent:
$ cp foo.conf foo.conf.bak
$ cp foo.conf{,.bak}
http://www.gnu.org/s/bash/manual/html_node/Brace-Expansion.h...Re: Bash Shortcuts For Maximum Productivity
#9I'm not an Emacs user, but aren't a lot of the text-editing shortcuts straight from Emacs?
Re: Bash Shortcuts For Maximum Productivity
#10 $ /etc/init.d/rabbitmq-server restart
Failed, need root access
$ sudo !!
Success
cd - is also quite cool, it takes you to the previous working directory. $ pwd
/some/really/long/path/goes/here
$ cd /var/log/app
Work in this directory for a while, then go to previous dir
$ cd -
$ pwd
/some/really/long/path/goes/here