Improved configuration and man - fixed #45.

This commit is contained in:
Martin Dvorak 2014-01-25 14:36:01 +01:00
parent fa65c1fd31
commit 7325a93a9f
2 changed files with 27 additions and 16 deletions

View file

@ -11,7 +11,7 @@ file that is filtered as you type a command substring. Commands
are not just filtered, but also ordered by a ranking algorithm are not just filtered, but also ordered by a ranking algorithm
that considers number of occurences, length and timestamp. In addition that considers number of occurences, length and timestamp. In addition
hh allows removal of commands from history - for instance with a typo or with a sensitive content. hh allows removal of commands from history - for instance with a typo or with a sensitive content.
.SH OPTIONNS .SH OPTIONS
.TP .TP
\fB--show-configuration\fR \fB--show-configuration\fR
Show configuration to be added to .bashrc Show configuration to be added to .bashrc
@ -41,6 +41,12 @@ Choose currently selected item for completion and execute it.
\fBDEL\fR \fBDEL\fR
Remove currently selected item from the shell history. Remove currently selected item from the shell history.
.TP .TP
\fBBACSKSPACE\fR, \fBCtrl\-h\fR
Delete last pattern character.
.TP
\fBCtrl\-u\fR, \fBCtrl\-w\fR
Delete pattern and search again.
.TP
\fBCtrl\-x\fR \fBCtrl\-x\fR
Write changes to shell history and exit. Write changes to shell history and exit.
.TP .TP
@ -50,15 +56,16 @@ Exit with empty prompt.
Add the following lines to ~/.bashrc: Add the following lines to ~/.bashrc:
.nf .nf
.sp .sp
shopt -s histappend shopt -s histappend # append new history items to .bash_history
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}" export PROMPT_COMMAND="history \-a; history \-n; ${PROMPT_COMMAND}"
bind '"\eC\-r": "\eC\-a hh \eC-j"' bind '"\eC\-r": "\eC\-a hh \eC-j"' # bind hh to Ctrl-r
.sp .sp
.fi .fi
The first command ensures that new history items are appended to .bash_history The prompt command ensures synchronization of the history between BASH memory
(instead of overwriting). The second command ensures synchronization of the and history file.
history between memory and file system. The third command binds hh to
Ctrl-r shortcut.
.SH AUTHOR .SH AUTHOR
Written by Martin Dvorak <martin.dvorak@mindforger.com> Written by Martin Dvorak <martin.dvorak@mindforger.com>
.SH BUGS .SH BUGS

View file

@ -66,10 +66,13 @@
#endif #endif
static const char *INSTALL_STRING= static const char *INSTALL_STRING=
"\n# Add this configuration to ~/.bashrc to let HH load and flush up to date history" "\n# add this configuration to ~/.bashrc"
"\nshopt -s histappend" "\nshopt -s histappend # append new history items to .bash_history"
"\nexport PROMPT_COMMAND=\"history -a; history -n; ${PROMPT_COMMAND}\"" "\nexport HISTCONTROL=ignorespace # leading space hides commands from history"
"\nbind '\"\\C-r\": \"\\C-a hh \\C-j\"'" "\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\n"; "\n\n";
static const char *BUILD_STRING= static const char *BUILD_STRING=
@ -383,10 +386,6 @@ void loop_to_select(HistoryItems *history)
print_history_label(history); print_history_label(history);
selectionCursorPosition=0; selectionCursorPosition=0;
break; break;
case K_CTRL_X:
result=NULL;
done=TRUE;
break;
case KEY_RESIZE: case KEY_RESIZE:
print_history_label(history); print_history_label(history);
move(y, basex+strlen(pattern)); move(y, basex+strlen(pattern));
@ -462,6 +461,10 @@ void loop_to_select(HistoryItems *history)
history_clear_dirty(); history_clear_dirty();
done=TRUE; done=TRUE;
break; break;
case K_CTRL_X:
result=NULL;
done=TRUE;
break;
default: default:
LOGKEYS(Y_OFFSET_HELP, c); LOGKEYS(Y_OFFSET_HELP, c);
LOGCURSOR(Y_OFFSET_HELP); LOGCURSOR(Y_OFFSET_HELP);
@ -495,7 +498,7 @@ void loop_to_select(HistoryItems *history)
void install_show() void install_show()
{ {
printf("# %s\n%s", BUILD_STRING, INSTALL_STRING); printf("%s", INSTALL_STRING);
} }
void assemble_cmdline(int argc, char *argv[]) { void assemble_cmdline(int argc, char *argv[]) {
@ -535,6 +538,7 @@ int main(int argc, char *argv[])
if(argc==2 && strstr(argv[1], "--show-configuration")) { if(argc==2 && strstr(argv[1], "--show-configuration")) {
install_show(); install_show();
// TODO --help (tr --help) // TODO --help (tr --help)
//printf("# %s\n%s", BUILD_STRING, INSTALL_STRING);
} else { } else {
assemble_cmdline(argc, argv); assemble_cmdline(argc, argv);
hstr(); hstr();