1 |
#!/usr/bin/env bash |
2 |
|
3 |
#### sh -i |
4 |
# This fails because OSH prompt goes to stdout, and other differences. It's |
5 |
# probably OK to be honest. |
6 |
echo 'echo foo' | PS1='$ ' $SH --rcfile /dev/null -i |
7 |
## STDOUT: |
8 |
foo |
9 |
## END |
10 |
## STDERR: |
11 |
$ echo foo |
12 |
$ exit |
13 |
## END |
14 |
|
15 |
#### \[\] are non-printing |
16 |
PS1='\[foo\]\$' |
17 |
echo "${PS1@P}" |
18 |
## STDOUT: |
19 |
foo$ |
20 |
## END |
21 |
|
22 |
#### literal escapes |
23 |
PS1='\a\e\r\n' |
24 |
echo "${PS1@P}" |
25 |
## stdout-json: "\u0007\u001b\r\n\n" |
26 |
|
27 |
#### special case for $ |
28 |
# NOTE: This might be broken for # but it's hard to tell since we don't have |
29 |
# root. Could inject __TEST_EUID or something. |
30 |
PS1='$' |
31 |
echo "${PS1@P}" |
32 |
PS1='\$' |
33 |
echo "${PS1@P}" |
34 |
PS1='\\$' |
35 |
echo "${PS1@P}" |
36 |
PS1='\\\$' |
37 |
echo "${PS1@P}" |
38 |
PS1='\\\\$' |
39 |
echo "${PS1@P}" |
40 |
## STDOUT: |
41 |
$ |
42 |
$ |
43 |
$ |
44 |
\$ |
45 |
\$ |
46 |
## END |
47 |
|
48 |
#### PS1 evaluation order |
49 |
x='\' |
50 |
y='h' |
51 |
PS1='$x$y' |
52 |
echo "${PS1@P}" |
53 |
## STDOUT: |
54 |
\h |
55 |
## END |
56 |
|
57 |
#### PS1 evaluation order 2 |
58 |
foo=foo_value |
59 |
dir=$TMP/'$foo' # Directory name with a dollar! |
60 |
mkdir -p $dir |
61 |
cd $dir |
62 |
PS1='\w $foo' |
63 |
test "${PS1@P}" = "$PWD foo_value" |
64 |
echo status=$? |
65 |
## STDOUT: |
66 |
status=0 |
67 |
## END |
68 |
|
69 |
#### \1004 |
70 |
PS1='\1004$' |
71 |
echo "${PS1@P}" |
72 |
## STDOUT: |
73 |
@4$ |
74 |
## END |
75 |
|
76 |
#### \001 octal literals are supported |
77 |
PS1='[\045]' |
78 |
echo "${PS1@P}" |
79 |
## STDOUT: |
80 |
[%] |
81 |
## END |
82 |
|
83 |
#### \555 is beyond max octal byte of \377 and wrapped to m |
84 |
PS1='\555$' |
85 |
echo "${PS1@P}" |
86 |
## STDOUT: |
87 |
m$ |
88 |
## END |
89 |
|
90 |
#### \x55 hex literals not supported |
91 |
PS1='[\x55]' |
92 |
echo "${PS1@P}" |
93 |
## STDOUT: |
94 |
[\x55] |
95 |
## END |
96 |
|
97 |
#### Single backslash |
98 |
PS1='\' |
99 |
echo "${PS1@P}" |
100 |
## BUG bash stdout-json: "\\\u0002\n" |
101 |
## STDOUT: |
102 |
\ |
103 |
## END |
104 |
|
105 |
#### Escaped backslash |
106 |
PS1='\\' |
107 |
echo "${PS1@P}" |
108 |
## BUG bash stdout-json: "\\\u0002\n" |
109 |
## STDOUT: |
110 |
\ |
111 |
## END |
112 |
|
113 |
#### \0001 octal literals are not supported |
114 |
PS1='[\0455]' |
115 |
echo "${PS1@P}" |
116 |
## STDOUT: |
117 |
[%5] |
118 |
## END |
119 |
|
120 |
#### \u0001 unicode literals not supported |
121 |
PS1='[\u0001]' |
122 |
USER=$(whoami) |
123 |
test "${PS1@P}" = "[${USER}0001]" |
124 |
echo status=$? |
125 |
## STDOUT: |
126 |
status=0 |
127 |
## END |
128 |
|
129 |
#### constant string |
130 |
PS1='$ ' |
131 |
echo "${PS1@P}" |
132 |
## STDOUT: |
133 |
$ |
134 |
## END |
135 |
|
136 |
#### hostname |
137 |
|
138 |
# NOTE: This test is not hermetic. On my machine the short and long host name |
139 |
# are the same. |
140 |
|
141 |
PS1='\h ' |
142 |
test "${PS1@P}" = "$(hostname -s) " # short name |
143 |
echo status=$? |
144 |
PS1='\H ' |
145 |
test "${PS1@P}" = "$(hostname) " |
146 |
echo status=$? |
147 |
## STDOUT: |
148 |
status=0 |
149 |
status=0 |
150 |
## END |
151 |
|
152 |
#### username |
153 |
PS1='\u ' |
154 |
USER=$(whoami) |
155 |
test "${PS1@P}" = "${USER} " |
156 |
echo status=$? |
157 |
## STDOUT: |
158 |
status=0 |
159 |
## END |
160 |
|
161 |
#### current working dir |
162 |
PS1='\w ' |
163 |
test "${PS1@P}" = "${PWD} " |
164 |
echo status=$? |
165 |
## STDOUT: |
166 |
status=0 |
167 |
## END |
168 |
|
169 |
#### \W is basename of working dir |
170 |
PS1='\W ' |
171 |
test "${PS1@P}" = "$(basename $PWD) " |
172 |
echo status=$? |
173 |
## STDOUT: |
174 |
status=0 |
175 |
## END |