ISELECT(1) | General Commands Manual | ISELECT(1) |
iSelect
—
Interactive Selection Tool
iselect |
[-d
beg, end]
[-cfae ] [-p
linenum] [-k
key[: okey]]
[-m ] [-n
name] [-t
title] [-SKP ]
[-Q fallback]
line… |
iselect |
[-d
beg, end]
[-cfae ] [-p
linenum] [-k
key[: okey]]
[-m ] [-n
name] [-t
title] [-SKP ]
[-Q fallback]
< lines |
iselect |
-V |-h |
iSelect
is an interactive line selection
tool, operating via a full-screen Curses-based terminal session. It can be
used either as a user interface frontend controlled by the shell, Perl, or
another type of script backend as its wrapper, or in batch as a pipe filter
(usually between grep
and the final executing
command). In other words: iSelect
was designed to be
used for any type of interactive line-based selection.
If no arguments are given, lines are read from the standard input stream. Otherwise, lines are used directly.
Each selectable line is fully bold; parts of other lines may be
set in bold by wrapping them in
‘<b>...</b>
’.
By default, a single line may be chosen; with
-m
multiple lines can be selected. By default, only
lines containing the tag ‘<s>
’
(or with different delimiters set with -d
) may be
selected. -a
allows selecting all lines, but the tag
is always removed. Selected lines are written to the standard output
stream
The tag has a variant that looks like
‘<s:result text>
’, which,
instead of writing the line itself, writes
result text. Every format specifier in the form
‘%[prompt string]s
’ or
‘%[prompt string]S
’ in the
output is replaced by a line entered in an interactive prompt. The
s variant allows empty
responses; S doesn't.
-d
beg,
end,
--delimiter
=beg,
end<s>
’ and
‘<s:result text>
’.-c
,
--strip-comments
#
’.-f
,
--force-browse
%[prompt]s
’ needs to be
substituted.-a
,
--all-select
<s>
’ tags are still
removed.-e
,
--exit-no-select
-p
,
--position
=linenum-k
,
--key
=key:
okey-k
,
--key
=key-k
key:
RETURN
.
For example, -k
f allows
using ‘f
’ to confirm the
selection.-m
,
--multi-line
-n
,
--name
=name-t
,
--title
=title-S
,
--strip-result
-K
,
--key-result
-k
, this is the (unmapped)
key; thus, with -k
f, selecting line Foo Bar
by
pressing ‘f
’ yields
‘f:Foo Bar
’. A Space is
rendered as a literal space, not as
"SPACE".-P
,
--position-result
-Q
,
--quit-result
=
fallbackUse these to browse through the selection list:
CURSOR-UP ..... Move cursor one line up CURSOR-DOWN ... Move cursor one line down PAGE-UP ....... Move cursor one page up PAGE-DOWN ..... Move cursor one page down g ............. Goto first line G ............. Goto last line
Use these to select one line and exit in standard mode, or one or more lines in multi-line mode:
RETURN ........ Select line and exit CURSOR-RIGHT .. Select line and exit SPACE ......... Select line and stay (multi-line mode only) C ............. Clear current marks (multi-line mode only)
Use these to quit iSelect
or to show the
help or version pages:
q ............. Quit (exit without selection) CURSOR-LEFT ... Quit (exit without selection) h ............. Help Page v ............. Version Page
The Curses session is always opened on /dev/tty, because the standard I/O streams are usually tied to pipes.
As an example we present a real-life situation where
iSelect
can enhance existing functionality. We
define two shell functions (for your $HOME/.bashrc
file) which enhance the shell's cd
built-in.
# database scan cds () { find "$HOME" -type d | sort > ~/.dirs & } # enhanced cd command cd () { if [ -d "$1" ]; then builtin cd "$1" else builtin cd "$(grep -E "/$1[^/]*$" ~/.dirs | iselect -a -Q "$1" -n "chdir" \ -t "Change Directory to...")" fi }
This cd
() is compatible with the built-in
in the case where the specified directory actually exists. When it doesn't,
the original cd
would immediately give an error
(assuming CDPATH
is not set). This version tries
harder by searching for such a directory in a previously-built (via
cds
()) ($HOME/.dirs) file. When no match is found,
iSelect
just returns the given directory as the
default result and cd
fails as usual. When only one
directory was found, iSelect
gives it to
cd
silently. Only when more then one directory was
found, iSelect
shows a menu to pick between matches
interactively. The chosen directory is then given to
cd
.
For more useful examples on how to use
iSelect
, see
/usr/share/doc/iselect/examples.
Ralf S. Engelschall ⟨rse@engelschall.com⟩ (http://www.engelschall.com)
November 17, 2024 | ossp-iselect 1.4.2 |