xref: /plan9/rc/bin/pc/defs (revision 223a736ebd2849388a6a0145cd1e22a96bd28460)
1nl='
2'
3tab='	'
4
5fn prompt {
6	def=()
7	what=()
8	if(~ $1 -d && ! ~ $#* 1){
9		def=$2
10		shift
11		shift
12	}
13
14	optstr=()
15	if(~ $1 -w && ! ~ $#* 1){
16		optstr=$2
17		shift
18		shift
19	}
20
21	pr=$1
22	shift
23
24	opts=($*)
25	if(~ $#opts 0) {
26		suf=' '
27	}
28	if not if(! ~ $#optstr 0) {
29		if(~ $optstr '')
30			suf=' '
31		if not {
32			pr=$pr^' ('^$"optstr^')'
33			suf=''
34		}
35	}
36	if not {
37		pr=$pr^' ('^$1
38		shift
39		for(i)
40			pr=$pr^', '^$i
41		pr=$pr^')'
42		suf=''
43	}
44
45	if(~ $#def 1)
46		pr=$pr^$suf^'['^$def^']'
47	pr=$pr^': '
48
49
50	okay=no
51	while(~ $okay no) {
52# whatis opts
53		echo -n $pr >[1=2]
54		ifs='' {rd=`{read}}
55		if(~ $#rd 0)
56			exit notdone
57		rd=`{echo $rd}
58		if(~ $#rd 0 || ~ $rd '')
59			rd=$def
60
61		switch($#opts){
62		case 0
63			if(! ~ $rd '')
64				okay=yes
65		case *
66			if(~ $rd $opts)
67				okay=yes
68		}
69	}
70	echo -n $rd >/env/rd	# just in case
71}
72
73