summaryrefslogtreecommitdiffstats
path: root/smenu.1
blob: df951a7d452e51b842e513dac66acdf167ccbe49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
.TH smenu 1 "2015" "beta"
.SH NAME
smenu - filter that allows to interactively select a word from stdin
and outputs the selection to stdout.
.SH SYNOPSIS
.nf
\f(CRsmenu [\fB-h\fP|\fB-?\fP] [\fB-n\fP \fIlines\fP] [\fB-t\fP [\fIcols\fP]] \\
      [\fB-k\fP] [\fB-s\fP \fIpattern\fP] [\fB-m\fP \fImessage\fP] [\fB-w\fP] \\
      [\fB-d\fP] [\fB-M\fP] [\fB-c\fP] [\fB-l\fP] [\fB-r\fP] [\fB-b\fP] \\
      [\fB-i\fP \fIregex\fP] [\fB-e\fP \fIregex\fP] \\
      [\fB-C\fP \
[\fIa\fP|\fIA\fP|\fIs\fP|\fIS\fP|\fIr\fP|\fIR\fP|\fId\fP|\fID\fP]\
[\fIcol1\fP[-\fIcol2\fP],[\fIcol1\fP[-\fIcol2\fP]... \\
      [\fB-R\fP \
[\fIa\fP|\fIA\fP|\fIs\fP|\fIS\fP|\fIr\fP|\fIR\fP|\fId\fP|\fID\fP]\
[\fIrow1\fP[-\fIrow2\fP],[\fIrow1\fP[-\fIrow2\fP]... \\
      [\fB-S\fP \fI/regex/string/\fP[\fIg\fP][\fIv\fP][\fIs\fP][\fIi\fP]] \
[\fB-I\fP \fI/regex/string/\fP[\fIg\fP][\fIv\fP][\fIs\fP][\fIi\fP]] \\
      [\fB-E\fP \fI/regex/string/\fP[\fIg\fP][\fIv\fP][\fIs\fP][\fIi\fP]] \\
      [\fB-A\fP \fIregex\fP] [\fB-Z\fP \fIregex\fP \\
      [\fB-1\fP \fIregex\fP [\fIATTR\fP] \
[\fB-2\fP \fIregex\fP [\fIATTR\fP] ... \
[\fB-5\fP \fIregex\fP [\fIATTR\fP] \\
      [\fB-g\fP] [\fB-q\fP] [\fB-W\fP \fIbytes\fP] [\fB-L\fP \fIbytes\fP] \\
      [\fB-T\fP [\fIseperator\fP]]] [\fB-V\fP]
.fi
.SH DESCRIPTION
This small utility acts as a filter (reads from stdin and writes to
stdout). All the words taken from stdin are presented in a scrolling
window on the terminal at the current cursor position.
.P
A selection cursor is initially positioned on the first selectable word
by default.
.P
It is possible to filter the selectable words in the input stream by
using an include regular expression to match the selectable words
and an exclude regular expression to match the non-selectable words.

Notice that when some words are excluded they can no more be re-included
after.
.P
Non-selectable words are skipped when moving the selection cursor and
cannot be searched for.
.P
The \fB-W\fP option can be used to set the characters (or multibyte
sequences) which will be used to delimit the input words.
The default delimiters are: \fISPACE\fP, \fI\\t\fP and \fI\\n\fP.
.P
The \fB-L\fP has a similar meaning for lines.
.P
Special character sequences formed by a \fI\\\fP followed by one of the
characters \fIa\fP \fIb\fP \fIt\fP \fIn\fP \fIv\fP \fIf\fP \fIr\fP and
\fI\\\fP are understood and have their traditional meanings.
.P
Quotations (single and double) in the input stream enable to ignore the
word separators so that a group of words are taken as a single entity.
.P
Non printable characters in words that are not a delimiter are
converted to their traditional form (\fI\\n\fP for end-of-line,
\fI\\t\fP for tabulation...) by default.
A single dot (\fI.\fP) is also used as a placeholder otherwise.
.P
\fBWarning\fP, \fBUTF-8\fP encoded codepoints are quietly converted
into a dot (\fI.\fP) when the user locale is not \fBUTF-8\fP aware like
\fBPOSIX\fP or \fBC\fP by example.
.P
.SS "Moving among words"
The cursor can then be moved in every direction by using the
keyboard arrow keys (\fB\(<-\fP,\fB\(da\fP,\fB\(ua\fP,\fB\(->\fP)
or the \fIvi\fP direction keys (\fBh\fP, \fBj\fP, \fBk\fP and \fBl\fP).
\fBHOME\fP, \fBEND\fP, \fBPgDn\fP and \fBPgUp\fP can also be used if
available and have their traditional meanings.
.SS "Searching for a word"
The key \fB/\fP or the key combination \fB^F\fP (\fBCtrl-f\fP) can be
used to initiate a search by prefix among the words after the cursor.
.P
After that, the cursor attribute is modified and all characters
entered 7s after this change go into a search buffer with the cursor
moving immediately to the next word matching this prefix.
.P
Any character entered in the 5s after this action completes this buffer,
resets the 5s timer and advances the cursor again if another word matches
the new buffer.
.P
As soon as the timer ends, the search mode is ended and the cursor
regains its initial appearance.
.P
The search buffer is persistent as long as the cursor is on a matching
word when a new search is initialized.
.P
If the cursor is moved in this mode, the timer will expire immediately
As if \fBENTER\fP or \fBESC\fP was pressed.
.P
Pressing \fBENTER\fP or \fBESC\fP immediately exits this mode.
.P
Pressing \fBSPACE\fP or \fBn\fP repeats the last search if the search
buffer is not empty.
Nothing will happen if there is no matching word after the cursor.
.P
Note that the \fBSPACE\fP and \fBn\fP keys cannot be used when the search
mode is active because they must be available if you want to search a
word containing these characters.
.SS "Selection and Exit"
Pressing \fBq\fP gives the possibility to exit without selecting anything.
.P
By default, \fBENTER\fP writes the selected word to stdout when not in
search mode otherwise it exits from this mode and does nothing more.
If you want to be able to select a word \fIeven\fP when in search mode,
use the \fB-r\fP option to change this behavior.
.SS Help
A small help message can be displayed when hitting \fB?\fP.
This display will last for 10s or until a valid key or \fBESC\fP is
pressed.
.SS Scroll bar
A scroll bar is displayed at the right of the scrolling window.
Its appearance is meant to be classical but it has some particularities:
.IP * 2
The scroll bar is not displayed if all the input words fit on only one
line.
.IP * 2
Otherwise, the scroll bar is always displayed except when the \fB-q\fP
option is set.
This option completely disables the scroll bar display.
.IP * 2
When the scrolling window has only one line, the scroll bar has only 3
states:
.RS 2
.IP - 2
\fBv\fP when on all but the last line, indicating that you can go down
to see more.
.IP - 2
\fB^\fP when on the last line.
.IP - 2
\fB|\fP otherwise.
.RE
.IP * 2
When there is more than one line to display, \fB/\fP means that the window
displays the first line, \fB\\\fP the last line.
\fB|\fP is used to fill the gap, see below the different possible
configurations.
.TS
tab(@);
l l l l l
l l l l l
l l l l .
\\@\\@^@^@\\ @Do not remove this trailing space!
|@|@|@|@/
/@v@/@v
.TE
.P
A \fB+\fP can also appear in the scroll bar in lieu of a \fB|\fP,
giving the relative position of the cursor line in the bunch of input
words.
.SS "Terminal resizing"
The windows is redrawn if the terminal is resized.
The redrawing is actually done only 1s after the end of the resizing to
avoid artefacts on screen.
The cursor will remain on the current selected word but may be displayed
on another place in the window.
.SS Unicode support
This utility is Unicode aware and should be able to display correctly
any Unicode character (even double-width ones) as long as the current
encoding is \fBUTF-8\fP (\fBUTF-8\fP in the output of the \fIlocale\fP
command).
.SS Configuration
If a file with adequate permissions and the same name as the executable
but prefixed with a dot is present in the current directory
or in the user's home directory, then it will be parsed as a
\fIini\fP file.
The values read from the file in the home directory will be overridden by
the ones read from the local directory (if it is present).

Missing and bad keywords are silently skipped.

The values read, if valid, override the default hard-coded ones.

If a value is invalid an error message is shown and the program terminates.

Here is an example giving the syntax and the names of the keywords
allowed:
.P
.nf
\f(CR--8<------------------------------------------------------------------
[colors]
  ; The terminal must have at least 8 colors and/or have attributes like bold
  ; and reverse for this to be useful
  ; if not the following settings will be ignored.

  method=ansi             ; classic | ansi (default)

  cursor=0/2              ; cursor attributes
  cursor_on_tag=0/2,u     ; cursor on tag attributes
  shift=6,b               ; shift symbol attributes
  bar = 7/4,b             ; scroll bar attributes
  search_field = 0/6      ; search field attributes
  search_text = 7,bu      ; search text attributes
  exclude = 4/0,u         ; non-selectable color attributes
  tag = 0/5               ; tagged (selected) attributes

  special1 = 7/4,b        ; attributes for the special level 1
  special2 = bu           ; attributes for the special level 2
  special3 = /3,b         ; attributes for the special level 3

[window]
  lines = 7               ; default number of lines of the window

[limits]
  word_length = 1024      ; arbitrary max length of input words (int)
  words = 32767           ; arbitrary max number of allowed input
                          ; words (int)
  columns = 128           ; arbitrary max number of columns (int)
--8<------------------------------------------------------------------
\fP
.fi
.IP * 2
The \fBmethod\fP keyword can take the two possible values displayed
above and determines if you want to use the native method (limited to 8
colors) of the \fBansi\fP method (ISO 8613-6) if your terminal supports
more than 8 colors.

The default value corresponds to \fBansi\fP.

The attributes syntax is [fg][/bg][,toggles] where \fBfg\fP and
\fBbg\fP are numbers representing the foreground and background
color and \fBtoggles\fP is a strings which can contain the characters
\fIb\fP, \fId\fP, \fIr\fP, \fIs\fP, \fIu\fP and \fIi\fP  standing for
\fIb\fPold, \fId\fPim, \fIr\fPeverse, \fIs\fPtandout, \fIu\fPnderline
and \fIi\fPtalic.
.IP * 2
Spaces are allowed anywhere in the lines and between them, even around
the \fB=\fP.
.IP * 2
Everything following a \fB;\fP is ignored.
.IP * 2
When undefined, the default limits are:
.TS
tab(@);
l l .
words@32767
word_length@256
columns@256
.TE
.SH OPTIONS
.IP "\fB-h\fP or \fB-?\fP"
Displays a log (\fB-h\fP) or short (\fB-?\fP) help message and exits.
.IP "\fB-n\fP \fIlines\fB"
Gives the maximum number of lines in the scrolling selection window.
By default five lines at most are displayed and the other ones, if
any, need you to scroll the window.
.IP "\fB-t\fP [\fIcolumns\fP]"
This option sets the tabulation mode and, if a number is specified,
limits the number of displayed columns to that number.
In this mode, embedded line separators are ignored.
The options \fB-A\fP and \fB-Z\fP can nevertheless be used to force words
to appear in the first (respectively last) position of the displayed line.
.P
.RS
Note that in this mode each column has the same width.
.RE
.IP \fB-k\fP
By default, the spaces surrounding the output string will be deleted.
This option forces them to be retained.
Note that these spaces must have been protected to be selected.
.IP "\fB-s\fP \fIpattern\fP"
Pre-Position the cursor to the first word matching the specified pattern.

\fIpattern\fP can be:
.RS
.IP * 2
A \fB#\fP immediately followed by a \fBnumber\fP giving the initial
position of the cursor (counting from 0).
If this number if greater than the number of words, the cursor will be
set on the latest selectable position.
.IP * 2
A single \fB#\fP or the string \fB#last\fP to set the initial
cursor position to the latest selectable word position.
.IP * 2
A string starting with a \fB/\fP indicating that we want the cursor
to be set to the first word matching the given regular expression.
.IP * 2
A \fBprefix\fP string indicating that we want the cursor to be set on the
first word matching the string given (\fBCa\fP will match \fBCancel\fP
by example).
.PP
Warning, when searching for a prefix or a regular expression, smenu
only looks for them after an eventual modification, so for example,
the command:
\f(CBsmenu -I/c/x/ -s/c <<< "a b c d"\fP won't find c and put the cursor
on \fBa\fP but \f(CBsmenu -I/c/x/v -s/c <<< "a b c d"\fP will find it and
put the cursor on the \fBx\fP substituting the \fBc\fP on screen only
.RE
.IP "\fB-m\fP \fImessage\fP"
Displays a message above the window.
Beware, it will truncated if it does not fit on a terminal line.
.IP "\fB-w\fP"
When \fB-t\fP is followed by a number of columns, the default is to
compact the columns so that they use the less terminal width as
possible.
This option enlarges the columns in order to use the whole terminal width.

When in column mode, \fB-w\fP can be used to force all the columns to
have the same size (the largest one).
See option \fB-c\fP below.
.P
.RS
Note that the column's size is only calculated once when the words are
displayed for the first time.
A terminal resize will not update this value.
This choice enables a faster display.
.RE
.P
.IP \fB-d\fP
Tells the program to clean up the display before quitting by removing
the selection window after use as if it was never displayed.
.IP \fB-M\fP
Centers the display if possible.
.IP \fB-c\fP
Sets the column mode.
In this mode the lines of words do not wrap when the right border of
the terminal is reached but only when a special character is read.
Some words will not be displayed without an horizontal scrolling.

If such a scrolling is needed, some indications may appear on the left
and right edge of the window to help the user to reach the unseen words.

In this mode, the width of each column is minimal to keep the maximum
information visible on the terminal.
.IP \fB-l\fP
Sets the line mode.
This mode is the same as column mode but without any column alignment.
.IP \fB-r\fP
Enables \fBENTER\fP to validate the selection even in search mode.
.IP \fB-b\fP
Replace all non-printable characters by a blank.
.IP "\fB-i\fP \fIregex\fP"
Sets the \fBi\fPnclude filter to match the selectable words.
All the other words will become non-selectable (excluded)
.IP "\fB-e\fP \fIregex\fP"
Sets the \fBe\fPxclude filter to match the non-selectable words.

This filter has a higher priority than the include filter.
.P
The \fIregex\fP selections above are done before the possible word
alterations realized with \fB-I\fP or \fB-E\fP (see below).
.IP "\fB-C\fP [a|A|s|S|r|R|d|D][col1[-col2]],[col1[-col2]]..."
In column mode, restricts the previous selections or de-selections to
some columns.
If no selection is given via \fB-i\fP and \fB-e\fP this option gives the
possibility to select entire columns by giving their numbers (1 based).

\fBa\fP/\fBA\fP, \fBs\fP/\fBS\fP or nothing select the specified ranges
of columns. \fBr\fP/\fBR\fP or \fBd\fP/\fBD\fP select all but the
specified columns.

The words in the selected columns will be considered as included and the
others excluded.

Example of columns selection: \fI-a2,3,5-7\fP forces the cursor to only
navigate in columns \fB2\fP,\fB3\fP,\fB5\fP,\fB6\fP and \fB7\fP.
If \fBd\fP was used in place of \fBa\fP, all the columns would have been
selected \fBexcept\fP the columns \fB2\fP,\fB3\fP,\fB5\fP,\fB6\fP and
\fB7\fP.

Spaces are allowed in the selection string if they are protected.

The column mode is forced when this option is selected.
.IP "\fB-R\fP [a|A|s|S|r|R|d|D][col1[-col2]],[col1[-col2]]..."
Similar to \fB-C\fP but for the rows.

One difference though: this is the line mode which is forced by this
option NOT the column mode.
.IP "\fB-S\fP /\fIregex\fP/replacement string/[g][v][s]"
Post-processes the words by applying a regular expression based
substitution.
The argument must be formatted as in the \fBsed\fP editor.

This option can be used more than once.
Each substitution will be applied in sequence on each word.
This sequence can be stopped if a \fBstop\fP flag is encountered.

.RS
\fBflags:\fP
.IP * 2
The optional trailing \fBg\fP (for \fIg\fPlobal) means that all matched
occurrences shall be replaced and not only the first one.
.IP * 2
The optional trailing \fBv\fP (for \fIv\fPisual) means that the altered
words will only be used for display and search.
The modifications will \fInot\fP be reflected in the returned word.
.IP * 2
The optional trailing \fBs\fP (for \fIs\fPtop) means that no more
substitution will be allowed on this word even if another \fB-S\fP is
used.
.IP * 2
The optional trailing \fBi\fP (for \fIi\fPgnore case) means that the
string search operation should ignore the case for this pattern.

Small example:
\f(CBR=$(echo a b c | smenu -S /b/B/)\fP
will display \f(CR"a B c"\fP and \f(CBR\fP will contain \fIB\fP if \fI
B\fP is
selected meanwhile
\f(CBR=$(echo a b c | smenu -S /b/B/\fBv\fP)\fR
will display the same as above but \f(CBR\fP will contain the original
word \fIb\fP if \fIB\fP is selected.
In both cases, only the word \fIB\fP will be searchable and not \fIb\fP.
.RE
Notice that a substitution resulting in an empty string is equivalent
to removing the word.
.IP "\fB-I\fP /\fIregex\fP/replacement string/[g][v][s]"
Post-processes the \fBselectable\fP words by applying a regular
expression based substitution (see \fB-S\fP for details).
.IP "\fB-E\fP /\fIregex\fP/replacement string/[g][v][s]"
Post-processes the \fBexcluded\fP (or \fBnon-selectable\fP) words by
applying a regular expression based substitution (see \fB-S\fP for
details).
.P
The \fB/\fP separator that \fB-I\fP and \fB-E\fP are using above can be
substituted by any other character except \fISPACE\fP, \fI\\t\fP,
\fI\\f\fP, \fI\\n\fP, \fI\\r\fP and \fI\\v\fP.
.P
In the four previous options, \fIregex\fP is a \fBPOSIX\fP
\fBE\fPxtended \fBR\fPegular \fBE\fPxpression.
For details, please refer to the \fBregex\fP manual page.
.IP "\fB-A\fP \fIregex\fP"
In column mode, forces all words matching the given regular expression
to be the first one in the displayed line.
If you want to only rely on this method to build the lines, just specify
an empty \fBregex\fP to set the end-of-line separator with \fI-L ''\fP)
.IP "\fB-Z\fP \fIregex\fP"
Similar to \fB-A\fP but forces the word to be the latest of its line.
The same trick with \fB-L\fP can also be used.
.IP "\fB-1\fP ... \fB-5\fP \fIregex\fP [\fIATTR\fP]"
Allows to give up to 5 classes of words specified by regular expressions a
special display color.
They are called \fBspecial levels\fP.
Only selectable words will be considered.

By default, the 5 special levels have their foreground color set to
red, green, brown/yellow, purple and cyan.
All these colors also can be set or modified permanently in the
configuration files.
See the example file above for an example.

The optional second argument (\fIATTR\fP) can be used to override the
default or configured attributes of each class.
Its syntax is the same as the one used in the configuration file:
.nf
[\fIfg\fP][/\fIbg\fP][,{\fIb\fP|\fId\fP|\fIr\fP|\fIs\fP|\fIu\fP|\fIi\fP}] \
| [{\fIb\fP|\fId\fP|\fIr\fP|\fIs\fP|\fIu\fP|\fIi\fP}]
.fi

Examples of possible attributes are:
.nf
  \f(CB2/0,bu \fPgreen on black bold underline
  \f(CB/2     \fPgreen background
  \f(CB5      \fPtext in purple
  \f(CBrb     \fPreverse bold
.fi
.IP \fB-g\fP
Replaces the blank after each words in column or tabular mode by a
vertical bar \fB|\fP. Some users may find the output more readable
with it.
.IP \fB-q\fP
Prevents the scroll bar display.
Useful when all the input words can be
displayed without the need of scrolling.
By default the scroll bar is always displayed when there is more than
one line.
An absence of curs