hstr/CONFIGURATION.md

198 lines
4.4 KiB
Markdown
Raw Normal View History

2018-08-11 14:48:25 +08:00
Configuration
=============
Get most of HSTR by configuring it with:
```bash
hh --show-configuration >> ~/.bashrc
```
Run `hh --show-configuration` to determine what will be appended to your Bash profile.
For more configuration options details please refer to:
2018-08-11 14:37:17 +08:00
* bind `hh` command to a [keyboard shortcut](#binding-hh-to-keyboard-shortcut)
* get more [colors](#colors)
* choose [default history view](#history-view)
2015-05-28 13:08:15 +08:00
* [command blacklist](#blacklist)
2018-02-08 20:10:45 +08:00
* disable [confirm on delete](#confirm-on-delete)
* [verbosity](#verbosity)
* [Bash history settings](#bash-history-settings)
* [zsh history settings](#zsh-history-settings)
Check also configuration [examples](#examples).
2018-08-11 14:48:25 +08:00
Binding HSTR to Keyboard Shortcut
---------------------------------
Bash uses *Emacs* style keyboard shortcuts by default. There is
also *Vi* mode. Find out how to bind HSTR to a keyboard shortcut
based on the style you prefer below.
Check your active Bash keymap with:
```bash
bind -v | grep editing-mode
bind -v | grep keymap
```
To determine character sequence emitted by a pressed key in
terminal, type <kbd>Ctrl-v</kbd> and then press the key. Check your
current bindings using:
```bash
bind -S
```
2018-08-11 14:48:25 +08:00
Bash Emacs Keymap (default)
---------------------------
Bind `hh` to a Bash key e.g. to <kbd>Ctrl-r</kbd>:
```bash
bind '"\C-r": "\C-ahh -- \C-j"'
```
or <kbd>Ctrl-Alt-r</kbd>:
```bash
bind '"\e\C-r":"\C-ahh -- \C-j"'
```
or <kbd>Ctrl-F12</kbd>:
```bash
bind '"\e[24;5~":"\C-ahh -- \C-j"'
```
Bind `hh` to <kbd>Ctrl-r</kbd> only if it is interactive shell:
```bash
if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hh -- \C-j"'; fi
```
2018-02-21 16:06:00 +08:00
You can bind also other `hh` commands like `-kill-last-command`:
```bash
if [[ $- =~ .*i.* ]]; then bind '"\C-xk": "\C-a hh -k \C-j"'; fi
```
2018-08-11 14:48:25 +08:00
Bash Vim Keymap
---------------
Bind `hh` to a Bash key e.g. to <kbd>Ctrl-r</kbd>:
```bash
2018-07-29 11:23:14 +08:00
bind '"\C-r": "\e0ihh -- \C-j"'
```
2018-08-11 14:48:25 +08:00
Zsh Emacs Keymap (default)
--------------------------
Bind `hh` to a Zsh key e.g. to <kbd>Ctrl-r</kbd>:
```bash
bindkey -s "\C-r" "\eqhh --\n"
```
2018-08-11 14:48:25 +08:00
Colors
------
Get `hh` in more colors:
```bash
export HH_CONFIG=hicolor
```
2015-01-08 06:44:07 +08:00
or ensure black and white mode:
```bash
export HH_CONFIG=monochromatic
```
2018-08-11 14:48:25 +08:00
History View
------------
Show normal history by default (instead of metrics-based view):
```bash
export HH_CONFIG=rawhistory
```
2015-01-08 06:44:07 +08:00
Show favorite commands by default (instead of metrics-based view):
```bash
export HH_CONFIG=favorites
```
2018-08-11 14:48:25 +08:00
Filtering
---------
2015-01-08 06:44:07 +08:00
Make search case sensitive (insensitive by default):
```bash
export HH_CONFIG=casesensitive
```
Keep duplicates in `rawhistory` view (duplicates discarded by default):
```bash
export HH_CONFIG=duplicates
```
2018-08-11 14:48:25 +08:00
Blacklist
2015-05-28 13:08:15 +08:00
---------
Skip commands when processing history i.e. make sure that these commands
will *not* be shown in any view:
```bash
export HH_CONFIG=blacklist
```
Commands to be stored in `~/.hh_blacklist` file with trailing empty line. For instance:
```
cd
my-private-command
ls
ll
```
2018-08-11 14:48:25 +08:00
Confirm on Delete
2018-08-11 14:37:17 +08:00
-----------------
2018-02-08 20:10:45 +08:00
Do not prompt for confirmation when deleting history items:
```bash
export HH_CONFIG=noconfirm
```
2018-08-11 14:48:25 +08:00
Verbosity
2015-05-28 13:08:15 +08:00
---------
2018-02-21 16:06:00 +08:00
Show a message when deleting the last command from history:
```bash
export HH_CONFIG=verbose-kill
```
2015-01-08 06:44:07 +08:00
Show warnings:
```bash
export HH_CONFIG=warning
```
2015-01-08 06:44:07 +08:00
Show debug messages:
```bash
export HH_CONFIG=debug
```
2018-08-11 14:48:25 +08:00
Bash History Settings
---------------------
Use the following BASH settings to get most out of `hh`.
Increase the size of history maintained by BASH - variables defined below increase the
2015-01-08 06:44:07 +08:00
number of history items and history file size (default value is 500):
```bash
export HISTFILESIZE=10000
export HISTSIZE=${HISTFILESIZE}
```
Ensure syncing (flushing and reloading) of `.bash_history` with in-memory
history:
```bash
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
```
Force appending of in-memory history to `.bash_history`
(instead of overwriting):
```bash
shopt -s histappend
```
Use leading space to hide commands from history:
```bash
export HISTCONTROL=ignorespace
```
Suitable for a sensitive information like passwords.
2018-08-11 14:48:25 +08:00
Zsh History Settings
--------------------
2015-01-14 05:59:12 +08:00
If you use `zsh`, set HISTFILE environment variable in ~/.zshrc:
```
export HISTFILE=~/.zsh_history
```
2018-08-11 14:48:25 +08:00
Examples
--------
More colors with case sensitive search of history:
```bash
export HH_CONFIG=hicolor,casesensitive
```
Favorite commands view in black and white:
```bash
export HH_CONFIG=favorites,monochromatic
```
Keywords based search in colors with debug mode verbosity:
```bash
export HH_CONFIG=keywords,hicolor,debug
```