From 25988d02ea81f451a9234e2a3dc745738a57d6d7 Mon Sep 17 00:00:00 2001 From: Martin Dvorak Date: Fri, 31 Jan 2014 21:35:16 +0100 Subject: [PATCH] Adding non-interactive shell detection. --- README.md | 13 +++++++++---- man/hh.1 | 3 ++- src/hstr.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e102c00..7aedc02 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ CONFIGURATION EXPLANATION hh --show-configuration >> ~/.bashrc ``` -* bind `hh` to a BASH key e.g. to `Ctrl-R`: +* bind `hh` to a BASH key e.g. to `Ctrl-r`: ```bash bind '"\C-r": "\C-ahh \C-j"' ``` @@ -84,6 +84,11 @@ or `Ctrl-F12`: ```bash bind '"\e[24;5~":"\C-ahh \C-j"' ``` +bind `hh` to `Ctrl-r` only if this is interactive shell: +```bash +if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hh \C-j"'; fi +``` + To determine the character sequence emitted by a pressed key in terminal, type `Ctrl-v` and then press the key. Check your current bindings using: ```bash @@ -94,15 +99,15 @@ bind -S ```bash export HH_CONFIG=hicolor ``` -Show normal history by default (instead of metrics-based view): +show normal history by default (instead of metrics-based view): ```bash export HH_CONFIG=rawhistory ``` -Make search case sensitive (insensitive by default): +make search case sensitive (insensitive by default): ```bash export HH_CONFIG=casesensitive ``` -More colors and case sensitive search: +more colors and case sensitive search: ```bash export HH_CONFIG=hicolor,casesensitive ``` diff --git a/man/hh.1 b/man/hh.1 index c62b016..42e97be 100644 --- a/man/hh.1 +++ b/man/hh.1 @@ -83,7 +83,8 @@ export HISTCONTROL=ignorespace # leading space hides commands from history export HISTFILESIZE=10000 # increase history file size (default is 500) export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500) export PROMPT_COMMAND="history \-a; history \-n; ${PROMPT_COMMAND}" -bind '"\eC\-r": "\eC\-a hh \eC-j"' # bind hh to Ctrl-r +# if this is interactive shell, then bind hh to Ctrl-r +if [[ $\- =~ .*i.* ]]; then bind '"\eC\-r": "\eC\-a hh \eC-j"'; fi .sp .fi The prompt command ensures synchronization of the history between BASH memory diff --git a/src/hstr.c b/src/hstr.c index 51a8314..5a919b1 100644 --- a/src/hstr.c +++ b/src/hstr.c @@ -85,7 +85,8 @@ static const char *INSTALL_STRING= "\nexport HISTFILESIZE=10000 # increase history file size (default is 500)" "\nexport HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)" "\nexport PROMPT_COMMAND=\"history -a; history -n; ${PROMPT_COMMAND}\" # mem/file sync" - "\nbind '\"\\C-r\": \"\\C-a hh \\C-j\"' # bind hh to Ctrl-r" + "\n# if this is interactive shell, then bind hh to Ctrl-r" + "\nif [[ $- =~ .*i.* ]]; then bind '\"\\C-r\": \"\\C-a hh \\C-j\"'; fi" "\n\n"; static const char *HELP_STRING=