OILS / spec / builtin-fc.test.sh View on Github | oils.pub

247 lines, 101 significant
1## tags: interactive
2## compare_shells: bash
3## oils_failures_allowed: 2
4
5#### fc -l lists history commands
6printf "echo %s\n" {1..3} > tmp
7
8echo '
9HISTFILE=tmp
10history -c
11history -r
12
13fc -l
14' | $SH --norc -i
15
16# match osh's behaviour of echoing ^D for EOF
17case $SH in bash) echo '^D' ;; esac
18
19## STDOUT:
201 history -r
212 echo 1
223 echo 2
234 echo 3
24^D
25## END
26
27#### fc -ln lists history commands without numbers
28printf "echo %s\n" {1..3} > tmp
29
30echo '
31HISTFILE=tmp
32history -c
33history -r
34
35fc -ln
36' | $SH --norc -i
37
38# match osh's behaviour of echoing ^D for EOF
39case $SH in bash) echo '^D' ;; esac
40
41## STDOUT:
42 history -r
43 echo 1
44 echo 2
45 echo 3
46^D
47## END
48
49#### fc -lr lists history commands in reverse order
50printf "echo %s\n" {1..3} > tmp
51
52echo '
53HISTFILE=tmp
54history -c
55history -r
56
57fc -lr
58' | $SH --norc -i
59
60# match osh's behaviour of echoing ^D for EOF
61case $SH in bash) echo '^D' ;; esac
62
63## STDOUT:
644 echo 3
653 echo 2
662 echo 1
671 history -r
68^D
69## END
70
71#### fc -lnr lists history commands without numbers in reverse order
72printf "echo %s\n" {1..3} > tmp
73
74echo '
75HISTFILE=tmp
76history -c
77history -r
78
79fc -lnr
80' | $SH --norc -i
81
82# match osh's behaviour of echoing ^D for EOF
83case $SH in bash) echo '^D' ;; esac
84
85## STDOUT:
86 echo 3
87 echo 2
88 echo 1
89 history -r
90^D
91## END
92
93#### fc -l lists history commands with default page size
94printf "echo %s\n" {1..16} > tmp
95
96echo '
97HISTFILE=tmp
98history -c
99history -r
100
101fc -l
102' | $SH --norc -i
103
104# match osh's behaviour of echoing ^D for EOF
105case $SH in bash) echo '^D' ;; esac
106
107## STDOUT:
1082 echo 1
1093 echo 2
1104 echo 3
1115 echo 4
1126 echo 5
1137 echo 6
1148 echo 7
1159 echo 8
11610 echo 9
11711 echo 10
11812 echo 11
11913 echo 12
12014 echo 13
12115 echo 14
12216 echo 15
12317 echo 16
124^D
125## END
126
127#### fc -l [first] where first is an index
128printf "echo %s\n" {1..3} > tmp
129
130echo '
131HISTFILE=tmp
132history -c
133history -r
134
135fc -l 2
136' | $SH --norc -i
137
138# match osh's behaviour of echoing ^D for EOF
139case $SH in bash) echo '^D' ;; esac
140
141## STDOUT:
1422 echo 1
1433 echo 2
1444 echo 3
145^D
146## END
147
148#### fc -l [first] where first is an offset from current command
149printf "echo %s\n" {1..3} > tmp
150
151echo '
152HISTFILE=tmp
153history -c
154history -r
155
156fc -l -3
157' | $SH --norc -i
158
159# match osh's behaviour of echoing ^D for EOF
160case $SH in bash) echo '^D' ;; esac
161
162## STDOUT:
1632 echo 1
1643 echo 2
1654 echo 3
166^D
167## END
168
169#### fc -l [first] [last] where first and last are indexes
170printf "echo %s\n" {1..3} > tmp
171
172echo '
173HISTFILE=tmp
174history -c
175history -r
176
177fc -l 2 3
178' | $SH --norc -i
179
180# match osh's behaviour of echoing ^D for EOF
181case $SH in bash) echo '^D' ;; esac
182
183## STDOUT:
1842 echo 1
1853 echo 2
186^D
187## END
188
189#### fc -l [first] [last] where first and last are offsets from current command
190printf "echo %s\n" {1..3} > tmp
191
192echo '
193HISTFILE=tmp
194history -c
195history -r
196
197fc -l -3 -2
198' | $SH --norc -i
199
200# match osh's behaviour of echoing ^D for EOF
201case $SH in bash) echo '^D' ;; esac
202
203## STDOUT:
2042 echo 1
2053 echo 2
206^D
207## END
208
209#### fc -l [first] [last] where first and last are reversed indexes
210printf "echo %s\n" {1..3} > tmp
211
212echo '
213HISTFILE=tmp
214history -c
215history -r
216
217fc -l 3 2
218' | $SH --norc -i
219
220# match osh's behaviour of echoing ^D for EOF
221case $SH in bash) echo '^D' ;; esac
222
223## STDOUT:
2243 echo 2
2252 echo 1
226^D
227## END
228
229#### fc -lr [first] [last] where first and last are reversed indexes does not undo reverse
230printf "echo %s\n" {1..3} > tmp
231
232echo '
233HISTFILE=tmp
234history -c
235history -r
236
237fc -lr 3 2
238' | $SH --norc -i
239
240# match osh's behaviour of echoing ^D for EOF
241case $SH in bash) echo '^D' ;; esac
242
243## STDOUT:
2443 echo 2
2452 echo 1
246^D
247## END