xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit f14091ed4405cd2e0460ec9751840b8aaf810d77

Moving curses code to a separate module to make main cleaner.
Author: Martin Dvorak
Author date (UTC): 2014-01-25 12:38
Committer name: Martin Dvorak
Committer date (UTC): 2014-01-25 12:38
Parent(s): 9b1de77d8c0091da70c38c4f75fbaf78152614c4
Signing key:
Tree: 654b2388013fb3ebee04458463ba35294d1d718c
File Lines added Lines deleted
configure.ac 4 3
src/Makefile.am 5 4
src/hstr.c 4 17
File configure.ac changed (mode: 100644) (index 0d3261f..ea00353)
... ... AC_CONFIG_SRCDIR([src/hstr.c])
17 17 AC_PROG_CC AC_PROG_CC
18 18
19 19 # Checks for libraries. # Checks for libraries.
20 AC_CHECK_LIB(ncurses, initscr)
21 AC_CHECK_LIB(m,cos)
22 AC_CHECK_LIB(readline, using_history)
20 AC_CHECK_LIB(ncurses, initscr, [], [AC_MSG_ERROR([Could not find Curses library])])
21 AC_CHECK_LIB(m, cos, [], [AC_MSG_ERROR([Could not find Math library])])
22 AC_CHECK_LIB(readline, using_history, [], [AC_MSG_ERROR([Could not find Readline library])])
23 23
24 24 # Checks for header files. # Checks for header files.
25 25 AC_CHECK_HEADER(assert.h) AC_CHECK_HEADER(assert.h)
26 AC_CHECK_HEADER(ctype.h)
26 27 AC_CHECK_HEADER(curses.h) AC_CHECK_HEADER(curses.h)
27 28 AC_CHECK_HEADER(fcntl.h) AC_CHECK_HEADER(fcntl.h)
28 29 AC_CHECK_HEADER(math.h) AC_CHECK_HEADER(math.h)
File src/Makefile.am changed (mode: 100644) (index 594f9e6..e5ea109)
... ... AM_LDFLAGS =
5 5 # bin_ installs to bin; hh_ is the binary name # bin_ installs to bin; hh_ is the binary name
6 6 bin_PROGRAMS = hh bin_PROGRAMS = hh
7 7
8 hh_SOURCES = \
9 hashset.c include/hashset.h \
10 radixsort.c include/radixsort.h \
8 hh_SOURCES = \
9 hashset.c include/hashset.h \
10 hstr_curses.c include/hstr_curses.h \
11 11 hstr_history.c include/hstr_history.h \ hstr_history.c include/hstr_history.h \
12 hstr_utils.c include/hstr_utils.h \
12 hstr_utils.c include/hstr_utils.h \
13 radixsort.c include/radixsort.h \
13 14 hstr.c hstr.c
File src/hstr.c changed (mode: 100644) (index 05691c4..f1766aa)
21 21 #include <readline/chardefs.h> #include <readline/chardefs.h>
22 22
23 23 #include "include/hashset.h" #include "include/hashset.h"
24 #include "include/hstr_utils.h"
24 #include "include/hstr_curses.h"
25 25 #include "include/hstr_history.h" #include "include/hstr_history.h"
26 #include "include/hstr_utils.h"
26 27
27 #define FILE_BASHRC ".bashrc"
28 28 #define SELECTION_CURSOR_IN_PROMPT -1 #define SELECTION_CURSOR_IN_PROMPT -1
29 29 #define SELECTION_PREFIX_MAX_LNG 500 #define SELECTION_PREFIX_MAX_LNG 500
30 30 #define CMDLINE_LNG 250 #define CMDLINE_LNG 250
 
53 53 #define K_BACKSPACE 127 #define K_BACKSPACE 127
54 54 #define K_ENTER 10 #define K_ENTER 10
55 55
56 #define color_attr_on(C) if(terminalHasColors) { attron(C); }
57 #define color_attr_off(C) if(terminalHasColors) { attroff(C); }
58 #define color_init_pair(X, Y, Z) if(terminalHasColors) { init_pair(X, Y, Z); }
59
60 56 #ifdef DEBUG_KEYS #ifdef DEBUG_KEYS
61 57 #define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol() #define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol()
62 58 #else #else
 
... ... static const char *LABEL_HELP=
84 80
85 81 static char **selection=NULL; static char **selection=NULL;
86 82 static unsigned selectionSize=0; static unsigned selectionSize=0;
87 static bool terminalHasColors=FALSE;
88 83 static bool caseSensitive=FALSE; static bool caseSensitive=FALSE;
89 84 static bool defaultOrder=FALSE; static bool defaultOrder=FALSE;
90 85 static char screenLine[1000]; static char screenLine[1000];
 
... ... void print_cmd_deleted_label(char *cmd, int occurences)
117 112 refresh(); refresh();
118 113 } }
119 114
120 // make this status row
121 115 void print_history_label(HistoryItems *history) void print_history_label(HistoryItems *history)
122 116 { {
123 117 sprintf(screenLine, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ", sprintf(screenLine, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ",
 
... ... void print_selection_row(char *text, int y, int width, char *prefix) {
232 226 } }
233 227 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
234 228 } }
235
236 229 } }
237 230
238 231 void print_highlighted_selection_row(char *text, int y, int width) { void print_highlighted_selection_row(char *text, int y, int width) {
239 232 color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
240 233 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
241 snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminalHasColors?" ":">"), text);
234 snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminal_has_colors()?" ":">"), text);
242 235 mvprintw(y, 0, "%s", screenLine); mvprintw(y, 0, "%s", screenLine);
243 236 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
244 237 color_attr_off(A_REVERSE); color_attr_off(A_REVERSE);
 
... ... void highlight_selection(int selectionCursorPosition, int previousSelectionCurso
289 282 } }
290 283 } }
291 284
292 void color_start()
293 {
294 terminalHasColors=has_colors();
295 if(terminalHasColors) {
296 start_color();
297 }
298 }
299 285
300 286 void selection_remove(char *cmd, HistoryItems *history) void selection_remove(char *cmd, HistoryItems *history)
301 287 { {
 
... ... int main(int argc, char *argv[])
548 534 if(argc>0) { if(argc>0) {
549 535 if(argc==2 && strstr(argv[1], "--show-configuration")) { if(argc==2 && strstr(argv[1], "--show-configuration")) {
550 536 install_show(); install_show();
537 // TODO --help (tr --help)
551 538 } else { } else {
552 539 assemble_cmdline(argc, argv); assemble_cmdline(argc, argv);
553 540 hstr(); hstr();
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master