Added a man page - iomenu - interactive terminal-based selection menu HTML git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 04f14a2a3fbe38525721285139ebf8af4350876f DIR parent 2c6e76a07ce8fd008e28001c8ab4afcb6acd2b6e HTML Author: Josuah Demangeon⠠⠵ <mail@josuah.net> Date: Sun, 19 Mar 2017 22:29:08 +0100 Added a man page Diffstat: M Makefile | 2 +- M README | 108 ++++++++++++++----------------- A iomenu.1 | 128 +++++++++++++++++++++++++++++++ M iomenu.c | 10 ++-------- 4 files changed, 180 insertions(+), 68 deletions(-) --- DIR diff --git a/Makefile b/Makefile @@ -8,5 +8,5 @@ clean: install: iomenu mkdir -p $(PREFIX)/bin $(PREFIX)/man/man1 - # cp *.1 $(PREFIX)/man/man1/ + cp *.1 $(PREFIX)/man/man1/ cp iomenu $(PREFIX)/bin/ DIR diff --git a/README b/README @@ -1,90 +1,80 @@ -iomenu - Filter lines from stdin with an interactive menu +IOMENU(1) General Commands Manual IOMENU(1) - . _ __ _ __ - | (_) ||| (/_ | | |_| +NAME + iomenu – interactive selection menu -________________________________________________________________________________ +SYNOPSIS + iomenu [-l lines] - iomenu is a terminal tool to interactively select lines from stdin, and - print them out to the standard output. +DESCRIPTION + iomenu is an interactive filtering and selection tool for the terminal. - You can use scripts made for dmenu [1], as iomenu mostly the same way. + It reads lines from standard input, and prompt for a selection. The + selected line(s) is(are) printed to standard output. - Thanks to the authors of dmenu [1], sandy [2], vis-menu[3], pep[4], ... - that taught me C by writing some. + -l lines If lines is 0 or if -l is not set, the items are + displayed in an horizontal list. Otherwise, in a + vertical list of at most lines lines. + Selection control + An active selection is highlighted, and can be controlled with + keybindings. -Getting started -________________________________________________________________________________ + ^P, ^N Move selection to the previous/next item. - You can install iomenu by running: - - """ - make install - """ - - You can optionnaly set a "PREFIX" variable to set the path to - install to: - - """ - make PREFIX="$HOME/bin" install - """ + ^M, ^J, Enter Print the selection to the standard output, and exit 0. - All you need to build it is a C compiler: It is plain C89 source - code without external dependencies. + ^Y Print the selection to the standard output but continue + running. - All usage details are written in the man page, "iomenu.1". + Input handling + As printable keys are entered, the selection is filtered to match every + word from the input. + ^H, Bakcspace Remove last character from current input. -Examples -________________________________________________________________________________ + ^W Remove last word from current input. + ^U Remove the whole input string. -Open a bookmark from a list in a text file + ^I, Tab Fill the input with current selection. - """ - iomenu < bookmarks-urls.txt | xargs firefox - """ +EXIT STATUS + The iomenu utility exits 0 on success, and >0 if an error occurs. +EXAMPLES + Open a bookmark from a list in a text file: -Go to a subdirectory + iomenu < bookmarks-urls.txt | xargs firefox - """ - cd "$(find . -type d | iomenu)" - """ + Go to a subdirectory: + cd "$(find . -type d | iomenu)" -Edit a file located in ~ + Edit a file located in HOME: - """ - $EDITOR "$(find -type f | iomenu)" - """ + EDITOR "$(find "$HOME" -type f | iomenu -l 255)" + Play an audio file: -Play an audio file + mplayer "$(find ~/Music | iomenu)" - """ - mplayer "$(find ~/Music | iomenu)" - """ + Select a background job to attach to: + fg "%$(jobs | iomenu | cut -c 2)" -Select a background job to attach to + Filter "ps" output and print a process ID - """ - fg "%$(jobs | iomenu | cut -c 2)" - """ + ps ax | tail -n +2 | iomenu -l 255 | sed -r 's/ *([0-9]*).*/1/' +SEE ALSO + dmenu(1), slmenu(1), vis-menu(1) -Filter "ps" output and print a process ID +BUGS + iomenu currently only support ASCII characters. - """ - { printf '#'; ps ax; } | iomenu -s '#' | sed -r 's/ *([0-9]*).*/\1/' - """ +AUTORS + iomenu was written from scratch by Josuah Demangeon <mail@josuah.net> + with the help of dmenu(1) and vis-menu(1) as models. - -________________________________________________________________________________ - -1 http://git.suckless.org/dmenu/tree/dmenu.c -2 http://git.suckless.org/sandy/tree/sandy.c -3 http://github.com/martanne/vis/blob/master/vis-menu.c -4 http://github.com/charles-l/pep/blob/master/pep.c +Linux 4.9.11-1-ARCH March 19, 2017 Linux 4.9.11-1-ARCH DIR diff --git a/iomenu.1 b/iomenu.1 @@ -0,0 +1,128 @@ +.Dd mar 19, 2017 +.Dt IOMENU 1 +.Os +. +.Sh NAME +. +.Nm iomenu +.Nd interactive selection menu +. +.Sh SYNOPSIS +. +.Nm +.Op Fl l Ar lines +. +.Sh DESCRIPTION +. +.Nm +is an interactive filtering and selection tool for the terminal. +.Pp +It reads lines from standard input, and prompt for a selection. +The selected line(s) is(are) printed to standard output. +.Bl -tag -width XXXXXXXXXXXXXXXX +. +.It Fl l Ar lines +If +.Ar lines +is 0 or if +.Fl l +is not set, +the items are displayed in an horizontal list. +Otherwise, in a vertical list of at most +.Ar lines +lines. +.El +. +.Ss Selection control +. +An active selection is highlighted, and can be controlled with keybindings. +.Bl -tag -width XXXXXXXXXXXXXXX +. +.It Ic ^P Ns , Ic ^N +Move selection to the previous/next item. +. +.It Ic ^M Ns , Ic ^J Ns , Ic Enter +Print the selection to the standard output, and exit 0. +. +.It Ic ^Y +Print the selection to the standard output but +.Sy continue running . +.El +. +.Ss Input handling +. +As printable keys are entered, the selection is filtered to match every +word from the input. +.Bl -tag -width XXXXXXXXXXXXXXX +. +.It Ic ^H Ns , Ic Bakcspace +Remove last character from current input. +. +.It Ic ^W +Remove last word from current input. +. +.It Ic ^U +Remove the whole input string. +. +.It Ic ^I Ns , Ic Tab +Fill the input with current selection. +.El +. +.Sh EXIT STATUS +. +.Ex -std +. +.Sh EXAMPLES +. +Open a bookmark from a list in a text file: +.Bd -literal -offset XX +iomenu < bookmarks-urls.txt | xargs firefox +.Ed +.Pp +Go to a subdirectory: +.Bd -literal -offset XX +cd "$(find . -type d | iomenu)" +.Ed +.Pp +Edit a file located in +.Ev HOME : +.Bd -literal -offset XX +EDITOR "$(find "$HOME" -type f | iomenu -l 255)" +.Ed +.Pp +Play an audio file: +.Bd -literal -offset XX +mplayer "$(find ~/Music | iomenu)" +.Ed +.Pp +Select a background job to attach to: +.Bd -literal -offset XX +fg "%$(jobs | iomenu | cut -c 2)" +.Ed +.Pp +Filter "ps" output and print a process ID +.Bd -literal -offset XX +ps ax | tail -n +2 | iomenu -l 255 | sed -r 's/ *([0-9]*).*/\1/' +.Ed +. +.Sh SEE ALSO +. +.Xr dmenu 1 , +.Xr slmenu 1 , +.Xr vis-menu 1 +. +.Sh BUGS +. +.Nm +currently only support ASCII characters. +. +.Sh AUTORS +. +.Nm +was written from scratch by +.An Josuah Demangeon Aq Mt mail@josuah.net +with the help of +.Xr dmenu 1 +and +.Xr vis-menu 1 +as models. DIR diff --git a/iomenu.c b/iomenu.c @@ -26,7 +26,6 @@ static char input[BUFSIZ], formatted[BUFSIZ * 8]; static int current = 0, offset = 0, prev = 0, next = 0; static int linec = 0, matchc = 0; static char **linev = NULL, **matchv = NULL; -static char *opt_p = ""; static int opt_l = 0; @@ -243,7 +242,7 @@ print_screen(void) } format(input, opt_l || matchc == 0 ? ws.ws_col : OFFSET - 3); - fprintf(stderr, "\r%s %s", opt_p, formatted); + fprintf(stderr, "\r %s", formatted); } @@ -409,7 +408,7 @@ input_get(void) static void usage(void) { - fputs("usage: iomenu [-l lines] [-p prompt]\n", stderr); + fputs("usage: iomenu [-l lines]\n", stderr); exit(EXIT_FAILURE); } @@ -429,11 +428,6 @@ main(int argc, char *argv[]) if (++i >= argc || sscanf(argv[i], "%d", &opt_l) <= 0) usage(); break; - case 'p': - if (++i >= argc) - usage(); - opt_p = argv[i]; - break; default: usage(); }