Live data from Hacker News

Bash Shortcuts For Maximum Productivity

skorks.com

51–58 of 58 posts

Re: Bash Shortcuts For Maximum Productivity

#51

Earlier quoted context omitted.

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".

Yeah, and of course this does mean you have to be a little careful with M-backspace (backward-kill-word in Emacs), since it will change your kill ring.

But on other hand M-backspace can be useful too if you want to get just part of a line, you can move the cursor to where you want, then M-backspace through words to grab it - if you do M-backspace repeatedly the entire string is pulled into the kill ring until you stop pressing M-BS.

Re: Bash Shortcuts For Maximum Productivity

#53
post #28
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…

If I have a URL in my clipboard and want to prefix it I use: git clone `xclip -o` Much simpler and no customization needed.

uh, why wouldn't you just actually paste the url into your terminal at that point instead of typing `xclip -o`?

and yeah, typing the actual command into the terminal is always going to be 'simpler'

Re: Bash Shortcuts For Maximum Productivity

#54
post #8

The things he calls "bang commands" are actually "event designators" (!!, !blah), "word designators" ($) and "word modifiers" (:p). There are links to docs for each at the bottom of this page: http://www.gnu.org/s/bash/manual/html_node/History-Interacti... I 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 u…

A small change that made it much easier for me to use ! commands was enabling magic space, which expands the ! macros out when you press space. This made an enormous difference to me, since I could now be sure I wasn't accidentally completing the wrong command or arguments.

To enable it, edit your .inputrc (this is part of readline) and add this:

  $if Bash
    Space: magic-space
  $endif

Re: Bash Shortcuts For Maximum Productivity

#55
post #8

The things he calls "bang commands" are actually "event designators" (!!, !blah), "word designators" ($) and "word modifiers" (:p). There are links to docs for each at the bottom of this page: http://www.gnu.org/s/bash/manual/html_node/History-Interacti... I 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 u…

I am using follow function for cd which does basically the same though i can iterate through the last arguments with alt+.

    cd () {
	if [[ -f $1 ]]
 	then
		builtin cd $1:h
    	else
    		builtin cd "$@"
    	fi
    }

Re: Bash Shortcuts For Maximum Productivity

#56
post #27

Earlier quoted context omitted.

Nice little timesaver for such a common task, I'd just been doing the following (with vi editing on) but yours is much easier: esc-0-i-sudo

It may not be less keystrokes, but for what it's worth, I find using shift+i is easier than 0-i

Didn't know about that one, thanks!

Re: Bash Shortcuts For Maximum Productivity

#57

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?

The vi-mode is actually provided by readline, so bash has no knowledge of it. So, no.

Re: Bash Shortcuts For Maximum Productivity

#58
post #40
post #8

The things he calls "bang commands" are actually "event designators" (!!, !blah), "word designators" ($) and "word modifiers" (:p). There are links to docs for each at the bottom of this page: http://www.gnu.org/s/bash/manual/html_node/History-Interacti... I 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 u…

!! and !$ are alright, but I really dislike !blah, which is blindly executing the latest command starting with blah, whatever it is. The author of the article should remove this "tip", it is bad advice, or at least make a note that the !blah:p is highly preferable.

I prefer using Ctrl-r , which searches your history for 'blah' and puts it on the command line. The preferable part is that you can keep hitting Ctrl-r to see previous matches, which is often helpful since you don't want the last match, but the second or third match.
Post reply on HN