News for hackers. Stuff that matters.
Re:Advancing in the Bash Shell by pmoriarty on Tuesday September 13, 2016 @01:40AM (#12485849)
I virtually never use !! any more. Instead I just type control-r followed by a portion of the command in my history that I'm interested in.

That's a much more interactive way of getting to the command I want, and if the first match isn't what I want I can either keep typing more of the command or type control-r for the next match. I can also type control-s to go to the previous match. For that last trick to work, you need to do something like this first: stty stop ""

Granted, I use zsh, but I think it works pretty much the same in bash.

Another trick I really like, which I've only used in zsh, but which might exist in bash too (since bash and zsh have so much feature parity these days) is to bind a keystroke to "insert-last-word". When this keystroke is hit, it appends the last argument of the previous command to the end of the current line, further typing of this same keystroke will remove the appended argument and instead append the last argument of the previous command, and so on. I use this all the time and therefore never have to type !$

And my favorite shell trick of all time: set -o vi

Re:Advancing in the Bash Shell by Myrmornis on Tuesday September 13, 2016 @01:55AM (#12485901)
Agreed, but even nicer than control-r are the readline functions `history-search-backward` and `history-search-forward`.

Personally I bind them to up/down which on OS X at least involves:

  # Put this in some file like ~/.readline-bindings
  "\e[A": history-search-backward
  "\e[B": history-search-forward

  # And this in your ~/.bashrc or ~/.zshrc
  bind -f ~/.readline-bindings
That way if you haven't typed any input it behaves like normal up (previous command), but if you've typed some characters it only retrieves matching commands.

http://codeinthehole.com/writing/the-most-important-command-...

Re:Advancing in the Bash Shell by devnonymous on Tuesday September 13, 2016 @12:02PM (#12489516)
Just curious since I don't use a mac, doesn't writing the mappings to .inputrc work? IIRC, putting your readline bindings there makes it available for all readline enabled prompts, not just bash ie: Python, pgsql, mysql,.. Etc
Re:Advancing in the Bash Shell by Myrmornis on Tuesday September 13, 2016 @03:04PM (#12491260)
Yes I think that's a better approach, thanks. I don't know why I started using `bind` in my shell config.
Re:Advancing in the Bash Shell by lolive on Tuesday September 13, 2016 @04:52AM (#12486511)
Mapping these to Up/Down arrows (instead of PgUp-PdDn) is the best idea EVER !!!
Re:Advancing in the Bash Shell by musicmatze on Sunday September 18, 2016 @04:04AM (#12524382)
Is there a way to make this work with `set -o vi`? So I can use j/k to browse the history this way?
Re:Advancing in the Bash Shell by Jerry2 on Tuesday September 13, 2016 @02:08AM (#12485945)
>Granted, I use zsh, but I think it works pretty much the same in bash.

I also use zsh and I don't even use ctrl+r anymore. I just type a portion of the command I remember and hit the up arrow key. Almost always the command I want is only one to three arrow keys away. zsh matches partial commands really well.

Re:Advancing in the Bash Shell by JoshTriplett on Tuesday September 13, 2016 @02:39AM (#12486042)
Bash has similar commands available to move up and down by matching commands. However, I find such modal behavior of up/down confusing; I prefer to have up and down always move by one command, and use C-r for reverse isearch.
Re:Advancing in the Bash Shell by distrill on Tuesday September 13, 2016 @03:14AM (#12486157)
Agreed, but this only works if you know you are right about the beginning of the command. Ctrl-R is still the best way I know to search for a command that I may not be sure about the first letters of.
Re:Advancing in the Bash Shell by pmoriarty on Tuesday September 13, 2016 @02:17AM (#12485964)
I like the incremental searching that using control-r lets you do. That can come in really handy when I don't remember precisely what the command I want is.

I can start typing and then type more once I see some results to hone in more precisely to what I want, or even backspace over some of what I've typed and type some more without having to start all over again.

Also, using control-r instead of the arrow keys doesn't force me to move my wrists and lets me keep my fingers mostly on the home row. I try to use the arrow keys as little as possible.

Re:Advancing in the Bash Shell by Jerry2 on Tuesday September 13, 2016 @02:32AM (#12486015)
Not moving your hand away from the home row is a good point!

Now I gotta retrain my muscle memory :)

Re:Advancing in the Bash Shell by felixschl on Tuesday September 13, 2016 @04:36AM (#12486461)
You should be able to use ctrl-p/n for arrow up/down. That keeps your hand on the homerow. Forget about arrow keys (especially on a typical mac keyboard).
Re:Advancing in the Bash Shell by rhinoceraptor on Tuesday September 13, 2016 @07:24AM (#12487060)
Ctrl-p/n are a quicker way to go up and down the history.
Re:Advancing in the Bash Shell by vbernat on Tuesday September 13, 2016 @02:24AM (#12485990)
An interesting "extension" of C-r with zsh is to add pattern search:

bindkey '^r' history-incremental-pattern-search-backward

When you remember parts of the commands, you can do "C-r" then "echo*something".

Re:Advancing in the Bash Shell by igg on Tuesday September 13, 2016 @01:47AM (#12485876)
fzf [0] works pretty well for this.

[0] https://github.com/junegunn/fzf

Re:Advancing in the Bash Shell by pmoriarty on Tuesday September 13, 2016 @02:24AM (#12485991)
Is there any way to force the installer to compile from source rather than downloading a binary?

I'm a little wary of precompiled binaries.

Re:Advancing in the Bash Shell by icebraining on Tuesday September 13, 2016 @03:46AM (#12486284)
There's a Makefile in the src directory, seems like you can run "make release" to compile from source.
Re:Advancing in the Bash Shell by pjmlp on Tuesday September 13, 2016 @03:52AM (#12486305)
Do you also validate the whole source code, including running it through static analysis, before compiling it?
Re:Advancing in the Bash Shell by nicops on Tuesday September 13, 2016 @02:28PM (#12490979)
Agreed. I guess everything is subjective, but when I read the article state:

> While the [ctrl-r] method is more powerful, when doing some redundant task, it’s much easier to remember !22 than it is to muck with ctrl-r type searches or even the arrow keys.

how?!

Re:Advancing in the Bash Shell by marklgr on Tuesday September 13, 2016 @01:54AM (#12485897)
> When this keystroke is hit, it appends the last argument of the previous command to the end of the current line

There's `Meta-_` to insert the previous last word, but you cannot cycle with the previous words--it inserts the last word of the previous commands. You can give it a count, though (with Meta+nums).