input

Prompt for input with readline-like key bindings

git clone https://git.8pit.net/input.git

 1.Dd $Mdocdate: April 04 2020 $
 2.Dt INPUT 1
 3.Os
 4.Sh NAME
 5.Nm input
 6.Nd interactively prompt for user input
 7.Sh SYNOPSIS
 8.Nm input
 9.Op Fl 1
10.Op Fl w
11.Op Fl c Ar command
12.Op Fl p Ar prompt
13.Op Fl h Pa file
14.Op Fl s Ar size
15.Sh DESCRIPTION
16The
17.Nm
18utility interactively prompts for input lines, writing received input to
19standard output.
20In demarcation to
21.Xr read 1
22it provides
23.Xr readline 3
24like line editing and an optional persistent history.
25Besides, it continuously prompts for input instead of waiting for a
26single input line.
27.Pp
28The options are as follows:
29.Bl -tag -width Ds
30.It Fl 1
31Read a single line from standard input and exit.
32.It Fl w
33Complete the last word instead of the entire line.
34.It Fl c Ar command
35Invoke
36.Ar command
37to retrieve a list of available completion items.
38This command is invoked each time the user presses the tab character.
39Items must be written to standard output and separated by a newline character.
40.It Fl p Ar prompt
41Change the default prompt string
42.Qq "> "
43to
44.Ar prompt .
45.It Fl h Pa file
46Store the editing history in
47.Pa file .
48By default no editing history is kept.
49.It Fl s Ar size
50Specify the maximum editing history size.
51By default 256 entries are kept.
52.El
53.Sh EXAMPLES
54To write all input entered by the user to a file using a shell script:
55.Bd -literal -offset indent
56input | while read line; do
57  echo "${input}" >> somefile.txt
58done
59.Ed
60.Pp
61To use
62.Nm
63as an alternative to
64.Xr read 1 :
65.Bd -literal -offset indent
66name=$(input -1 -p "Enter your name: ")
67printf "Hello %s!\n" "$name"
68.Ed
69.Sh SEE ALSO
70.Xr rlwrap 1 ,
71.Xr readline 3
72.Sh AUTHORS
73.An Sören Tempel Aq Mt soeren@soeren-tempel.net