1 |
## our_shell: ysh
|
2 |
|
3 |
|
4 |
|
5 |
# Special ysh prefix if PS1 is set
|
6 |
PS1='\$ ' $SH -i -c 'echo "[$PS1]"'
|
7 |
|
8 |
# No prefix if it's not set, since we already have \s for YSH
|
9 |
$SH -i -c 'echo "[$PS1]"'
|
10 |
|
11 |
## STDOUT:
|
12 |
[ysh \$ ]
|
13 |
[\s-\v\$ ]
|
14 |
## END
|
15 |
|
16 |
|
17 |
|
18 |
shopt -s ysh:upgrade
|
19 |
|
20 |
var x = io.promptVal('$')
|
21 |
|
22 |
# We're not root, so it should be $
|
23 |
echo x=$x
|
24 |
|
25 |
var x = io.promptVal('w')
|
26 |
if (x === PWD) {
|
27 |
echo pass
|
28 |
} else {
|
29 |
echo fail
|
30 |
}
|
31 |
|
32 |
## STDOUT:
|
33 |
x=$
|
34 |
pass
|
35 |
## END
|
36 |
|
37 |
|
38 |
|
39 |
# \D{} will be supported with date and time functions
|
40 |
var x = io.promptVal('D')
|
41 |
echo x=$x
|
42 |
|
43 |
# something else
|
44 |
var x = io.promptVal('/')
|
45 |
echo x=$x
|
46 |
|
47 |
var x = io.promptVal('ZZ')
|
48 |
echo x=$x
|
49 |
|
50 |
## status: 3
|
51 |
## STDOUT:
|
52 |
x=<Error: \D{} not in promptVal()>
|
53 |
x=<Error: \/ is invalid or unimplemented in $PS1>
|
54 |
## END
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
export PS1='myprompt\$ '
|
60 |
echo 'echo hi' | $SH -i
|
61 |
|
62 |
## STDOUT:
|
63 |
hi
|
64 |
^D
|
65 |
## END
|
66 |
## stderr-json: "ysh myprompt$ ysh myprompt$ "
|
67 |
|
68 |
|
69 |
|
70 |
export PS1='myprompt\$ '
|
71 |
|
72 |
cat >yshrc <<'EOF'
|
73 |
func renderPrompt(io) {
|
74 |
var parts = []
|
75 |
call parts->append('hi')
|
76 |
call parts->append(io.promptVal('$'))
|
77 |
call parts->append(' ')
|
78 |
return (join(parts))
|
79 |
}
|
80 |
EOF
|
81 |
|
82 |
echo 'echo hi' | $SH -i --rcfile yshrc
|
83 |
|
84 |
## STDOUT:
|
85 |
hi
|
86 |
^D
|
87 |
## END
|
88 |
## stderr-json: "hi$ hi$ "
|
89 |
|
90 |
|
91 |
|
92 |
export PS1='myprompt\$ '
|
93 |
|
94 |
cat >yshrc <<'EOF'
|
95 |
func renderPrompt(io) {
|
96 |
return ([42, 43])
|
97 |
}
|
98 |
EOF
|
99 |
|
100 |
echo 'echo hi' | $SH -i --rcfile yshrc
|
101 |
|
102 |
## STDOUT:
|
103 |
hi
|
104 |
^D
|
105 |
## END
|
106 |
## stderr-json: "<Error: renderPrompt() should return Str, got List> <Error: renderPrompt() should return Str, got List> "
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
export PS1='myprompt\$ '
|
112 |
|
113 |
cat >yshrc <<'EOF'
|
114 |
func renderPrompt(io) {
|
115 |
error 'oops'
|
116 |
}
|
117 |
EOF
|
118 |
|
119 |
echo 'echo hi' | $SH -i --rcfile yshrc
|
120 |
|
121 |
## STDOUT:
|
122 |
hi
|
123 |
^D
|
124 |
## END
|
125 |
## stderr-json: "<Runtime error: oops><Runtime error: oops>"
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
export PS1='myprompt\$ '
|
131 |
|
132 |
cat >yshrc <<'EOF'
|
133 |
func renderPrompt() {
|
134 |
error 'oops'
|
135 |
}
|
136 |
EOF
|
137 |
|
138 |
echo 'echo hi' | $SH -i --rcfile yshrc
|
139 |
|
140 |
## STDOUT:
|
141 |
hi
|
142 |
^D
|
143 |
## END
|
144 |
## stderr-json: "<Runtime error: Func 'renderPrompt' takes no positional args, but got 1><Runtime error: Func 'renderPrompt' takes no positional args, but got 1>"
|
145 |
|