WLOG - notes something different

bash

Here are a few less-known tricks to make in infinitely more useful.

infinite history

Keep your history! Search through your old commands instead of looking for them again and again.

notes

Settings to be put in .bashrc.

Set comment out HISTSIZE and HISTFILESIZE and export them with an empty string (or -1 if you have bash 4.3 or newer), to set unlimited history in memory and unlimited saved lines.

Export HISTFILE and set it to an alternative history file.

Make sure you have bash set up to append new commands and save them after every command.

All this will make sure commands from your current session are written to the history file and eliminate the chance of the history file being emptied or truncated by bugs or external programs.

# Unlimited history ...
# Don't put duplicate lines or lines starting with space in the history. 
# See bash(1) for more options
HISTCONTROL=ignoreboth
#HISTCONTROL=ignoreboth:erasedups
# Append to the history file, don't overwrite it
shopt -s histappend
# For setting history length see HISTSIZE and HISTFILESIZE in bash(1)
#HISTSIZE=1000
#HISTFILESIZE=2000
export HISTSIZE=
export HISTFILESIZE=
export HISTFILE=~/.bash_history_infinite
# Save after every executed command
#PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"

quick up/down search

while Ctrl-r if fine, sometimes you want to start typing the beginning of a long command and have the rest of it being pulled from history.

Bind history search to the arrow keys.

# Bind history search to "up" and "down" keys
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

note

search trough history (hstr)

While Ctrl-r if fine, sometimes you want more out of a search.

A fantastic plugin for your shell hstr!

notes