Bash: how-to improve history manipulation

By default, up and down keys allow you to navigate your bash history. Another option is the history built-in command and bash expansions (ex.: !2 runs the second command, oldest to newest, from your bash history).

There are also tools, like bash-it, that allow for better history manipulation, but this also adds a lot of other stuff, so it might make your .bashrc load slower. It will make your bash look good as hell too.

Another option for an awesome way to access your bash history is the following snippet, based on bash-it‘s history plugin:

if [ -t 1 ]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi

With this, you only need to write part of a command, press the up arrow and it will complete it with the commands in bash history file that match to what you’ve written.

I’ve add it to the end of my .bashrc. Together with bash completion, it improves my workflow by a lot.

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *

Este site utiliza o Akismet para reduzir spam. Fica a saber como são processados os dados dos comentários.