1 .TH "SELECTOR" 1 "July 2009" "Francois Fleuret" "User Commands"
3 \" This man page was written by Francois Fleuret <francois@fleuret.org>
4 \" and is distributed under a Creative Commons Attribution-Share Alike
9 selector \- A simple command line utility for dynamic pattern selection
13 \fBselector\fP [\fIoptions\fR] [\fI<filename1>\fR [\fI<filename2>\fR ...]]
17 \fBselector\fP is a command line utility for interactive real-time
18 pattern matching. It reads the content of the specified files, and as
19 the user types a list of strings separated by ";" (or a regexp), the
20 display is updated in real time to show only the lines containing all
21 the said strings (or matching the regexp).
23 This command was mainly designed as a way to search efficiently in the
24 shell history, for which it is substantially better than the standard
25 readline ^R binding. With the -v option, it injects the selected line
26 into the tty input buffer, hence allowing the user to edit the line
27 and execute it as a standard command.
29 Selector is also a handy tool to test regexps, or to display menus
30 with many possible choices. For the latter, the -x option allows to
31 specify a label delimiter: the part of each line before that character
32 will appear during the selection, but only the part after that
33 character will be returned.
35 Note that because this is an interactive command, the standard input
36 can not be used as one of the input files.
40 Keys corresponding to ASCII codes between " " and "~" add a character
41 to the pattern string. The Backspace key, "^H" and "^?" delete the
42 character immediately on the left of the cursor, while the Delete key
43 and "^D" delete the character at cursor location.
45 The Left and Right cursor keys move the editing cursor
46 accordingly. The Up and Down cursor keys move the selected line one
47 entry at a time, and PageUp and PageDown move it by ten entries. The
48 Home and End key move to the top and the bottom of the list
49 respectively. The return key selects the current line and exits.
51 The keys "^A", "^E", "^U", and "^K" do somehow what they do in
52 readline, and you can exit selector without doing anything by either
53 interrupting the command with "^C" or by typing "^G" or the Escape
56 The key "^R" switches between the multi-substring and the regexp
57 selection mode, and "^I" between the case-sensitive and
58 case-insensitive modes.
62 \fB-h\fR, \fB--help\fR
65 \fB-m\fR, \fB--monochrome\fR
66 force the monochrome mode
68 \fB-i\fR, \fB--revert-order\fR
69 revert the order of the lines
71 \fB-b\fR, \fB--remove-bash-prefix\fR
72 remove the numeric prefix from bash history
74 \fB-z\fR, \fB--remove-zsh-prefix\fR
75 remove the time prefix from zsh history
77 \fB-d\fR, \fB--remove-duplicates\fR
78 remove duplicated lines (note that you can have two different lines
79 with the same visible part if you use the -x option)
81 \fB-e\fR, \fB--regexp\fR
84 \fB-a\fR, \fB--case-sensitive\fR
85 start in case sensitive mode
87 \fB-q\fR, \fB--no-beep\fR
88 make a flash instead of a beep when there is an edition error
90 \fB--\fR, \fB--rest-are-files\fR
91 state that all following arguments are filenames
93 \fB-t \fI<title>\fR, \fB--title \fI<title>\fR
94 add a title in the modeline
96 \fB-c \fI<fg_modeline>,<bg_modeline>,<fg_highlight>,<bg_highlight>\fR,
97 \fB--colors \fI<fg_modeline>,<bg_modeline>,<fg_highlight>,<bg_highlight>\fR
98 select the modeline and highlight color numbers
100 \fB-v\fR, \fB--inject-in-tty\fR
101 inject the selected line into the tty input buffer
103 \fB-w\fR, \fB--add-control-qs\fR
104 add ^Q between characters during tty injection to quote control characters
106 \fB-o \fI<output_filename>\fR, \fB--output-file \fI<output_filename>\fR
107 write the selected line into the specified file
109 \fB-s \fI<pattern_separator>\fR, \fB--pattern-separator \fI<pattern_separator>\fR
110 specify the symbol to separate the substrings in the search pattern
112 \fB-x \fI<label_separator>\fR, \fB--label-separator \fI<label_separator>\fR
113 specify the symbol to separate what to show to the user during the
114 selection from the line to return
116 \fB-l \fI<max_number_of_lines>\fR, \fB--number-of-lines \fI<max_number_of_lines>\fR
117 specify the maximum number of lines to take into account
119 \fB-f \fI<input_filename>\fR, \fB--input-file \fI<input_filename>\fR
120 specify a file to search into (option kept for compatibility reasons)
124 To use selector to search into your bash history
126 .B selector -q -b -i -d -v -w -l ${HISTSIZE} <(history)
128 To show a list of directories and insert a cd command to the selected
129 one (using @ as a separator)
131 .B selector -v -x @ <(find . -type d | awk \(aq{print $0\(dq@cd \(dq$0}\(aq)
133 To select a line in a long text and returns the line number (this
134 command uses ^A as a separator, hence there will be problems if the
137 .B selector -v -x ^A <(awk < something.txt \(aq{ print $0\(dq^A\(dqNR }\(aq)
139 .SH "KEYBINDING IN BASH"
141 You can associate selector to a single key in bash by using the
142 command 'bind' in your bash initialization file. For instance, to
143 associate it to M-r (that is, the "Alt" and "r" key pressed together),
144 just add something like
146 bind \(aq\(dq\\C-[r\(dq:\(dq\\C-a\\C-kselector -q -b -i -d -v -w -l ${HISTSIZE} <(history)\\C-m\(dq\(aq
151 This bindings uses the control character ^A to put the cursor to the
152 mostleft location and ^K to erase the current content of the readline
153 buffer, and it simulates the enter key with ^M.
155 Note that depending on the configuration of your system, the sequence
156 associated to the M-r key, which is here "C-[r", may differ. To figure
157 it out, simply press C-q followed by M-r in the console.
161 There are modeline display problems if the pattern is too long. This
162 program does not handle multibyte characters.
166 Written by Francois Fleuret <francois@fleuret.org> and distributed
167 under the terms of the GNU General Public License version 3 as
168 published by the Free Software Foundation. This is free software: you
169 are free to change and redistribute it. There is NO WARRANTY, to the
170 extent permitted by law.