mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-19 06:31:13 -03:00
Compare commits
1234 Commits
pre_fishfi
...
Integratio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e68508b0c | ||
|
|
2aac8e5dde | ||
|
|
209d8b7f2f | ||
|
|
26663e042f | ||
|
|
55986120aa | ||
|
|
aea9ad4965 | ||
|
|
216d32055d | ||
|
|
84978b7132 | ||
|
|
e4e9f6f221 | ||
|
|
77ec902ca7 | ||
|
|
7d9b0a00e4 | ||
|
|
f3c1ca3564 | ||
|
|
f109fa227d | ||
|
|
8befc474c1 | ||
|
|
622efba247 | ||
|
|
ce0c52d353 | ||
|
|
b03515276e | ||
|
|
30af350be0 | ||
|
|
1287b9d823 | ||
|
|
91aab03b90 | ||
|
|
e921dc50e0 | ||
|
|
dd6bb04ba7 | ||
|
|
c80bd104d2 | ||
|
|
22d1aaa27d | ||
|
|
2f5016262a | ||
|
|
47583877f1 | ||
|
|
1dbff80691 | ||
|
|
7abf6c71ad | ||
|
|
2da81b0ae7 | ||
|
|
d4c881791f | ||
|
|
516be01366 | ||
|
|
2b99190a1b | ||
|
|
3087f57453 | ||
|
|
4a4f8ec523 | ||
|
|
0c004147c0 | ||
|
|
451eb13e0e | ||
|
|
4e84cf1d38 | ||
|
|
72b7e64ad8 | ||
|
|
c3690b0878 | ||
|
|
b3f248fd19 | ||
|
|
d4686e6a59 | ||
|
|
14af6ba2af | ||
|
|
c3ee3af201 | ||
|
|
6496adf101 | ||
|
|
79f8d5c51e | ||
|
|
74ef1bc8ff | ||
|
|
26eeb9f37a | ||
|
|
ab385cd609 | ||
|
|
0f12f2b6b1 | ||
|
|
32c1d50887 | ||
|
|
956c94f30a | ||
|
|
3e69e5b082 | ||
|
|
330faab6cd | ||
|
|
fe6699f0bf | ||
|
|
807c5f2ef2 | ||
|
|
f7708955b6 | ||
|
|
be9024767e | ||
|
|
a1a83f8880 | ||
|
|
eb3a1f6739 | ||
|
|
03c1f2ef5b | ||
|
|
d215e86662 | ||
|
|
10962d7175 | ||
|
|
6889232b41 | ||
|
|
c54097af20 | ||
|
|
7c6695354e | ||
|
|
2d7fbf2476 | ||
|
|
1ef8206db1 | ||
|
|
b65f8d81fc | ||
|
|
e285d2939b | ||
|
|
6b602a4589 | ||
|
|
084542b943 | ||
|
|
ef8ea97044 | ||
|
|
dd6d0e774c | ||
|
|
f934310337 | ||
|
|
afe293c20a | ||
|
|
7f0a68f8d6 | ||
|
|
2517832718 | ||
|
|
bcf3accb74 | ||
|
|
1c5556334d | ||
|
|
299d803396 | ||
|
|
d513ace39d | ||
|
|
d5a9a4463c | ||
|
|
cf0baada2c | ||
|
|
49589e2da0 | ||
|
|
0e24676144 | ||
|
|
b0132821ac | ||
|
|
24afe544a3 | ||
|
|
3d7ff9f758 | ||
|
|
a81e70350b | ||
|
|
7f6f0ca103 | ||
|
|
c89bc73740 | ||
|
|
3100669b79 | ||
|
|
22c670c3d3 | ||
|
|
c37c7cee05 | ||
|
|
46579f3799 | ||
|
|
6de30028a8 | ||
|
|
c78c1427be | ||
|
|
953e7fd717 | ||
|
|
1ae08cfedf | ||
|
|
3c116cd077 | ||
|
|
bcab703e31 | ||
|
|
73046ec838 | ||
|
|
e1734468f5 | ||
|
|
aa78292c2a | ||
|
|
8bbd8ab073 | ||
|
|
b936be8e34 | ||
|
|
b8f34cdd35 | ||
|
|
993c028579 | ||
|
|
9285ade8a8 | ||
|
|
83e9f0dd91 | ||
|
|
c641f5cbdc | ||
|
|
c6302e3b3f | ||
|
|
94acb6ed5d | ||
|
|
42497d9932 | ||
|
|
3f172d13b2 | ||
|
|
437b4397b9 | ||
|
|
3a7ab3f030 | ||
|
|
fccf38a4d6 | ||
|
|
46edc49ede | ||
|
|
c05281492d | ||
|
|
5cebd3abf7 | ||
|
|
5ed5d637b8 | ||
|
|
516e18900c | ||
|
|
0970487cca | ||
|
|
d38f1380e9 | ||
|
|
2626b83b08 | ||
|
|
db0659aab4 | ||
|
|
e23a60a6bb | ||
|
|
3ea8d83d3f | ||
|
|
d9445f04b1 | ||
|
|
1543d02f96 | ||
|
|
11a444e914 | ||
|
|
2a6412481e | ||
|
|
b4447bfa4d | ||
|
|
72b5988e56 | ||
|
|
3a2c3c2288 | ||
|
|
9762a8ca1e | ||
|
|
e02e5e503d | ||
|
|
e4329f3ae7 | ||
|
|
f7082ee034 | ||
|
|
3ac9621f87 | ||
|
|
46e92e998e | ||
|
|
77dfd7b783 | ||
|
|
7d480ff579 | ||
|
|
37140d5e10 | ||
|
|
b04e874e43 | ||
|
|
d146f578a4 | ||
|
|
40c0c5a298 | ||
|
|
3a475a99fc | ||
|
|
9394583f96 | ||
|
|
3b4f4c5f59 | ||
|
|
34f2f77067 | ||
|
|
6b94708508 | ||
|
|
1d93e89eed | ||
|
|
e0e0bcdc1e | ||
|
|
1ed8af2ee8 | ||
|
|
3830c0adc4 | ||
|
|
5dbda6cd95 | ||
|
|
d8dbdc83c0 | ||
|
|
359a7cebde | ||
|
|
490ead52eb | ||
|
|
a5a7a32447 | ||
|
|
7e9652787b | ||
|
|
3b00d06a62 | ||
|
|
234fb7c2fe | ||
|
|
2c7e0ef577 | ||
|
|
2cbcc82968 | ||
|
|
b48e504522 | ||
|
|
4cce303c89 | ||
|
|
6a97b45ad1 | ||
|
|
1afdbb848e | ||
|
|
4d19bb17a9 | ||
|
|
b2012467b3 | ||
|
|
daf5ef1bbd | ||
|
|
85a5319c4b | ||
|
|
6ca11044a4 | ||
|
|
42be7733fe | ||
|
|
1d75c232ff | ||
|
|
97c9c9c9d1 | ||
|
|
ab52469fbb | ||
|
|
fba984272a | ||
|
|
fb3a41d3ad | ||
|
|
be7d02ebdd | ||
|
|
b989978dd3 | ||
|
|
d9c9760aac | ||
|
|
6ff88a44f0 | ||
|
|
cbcc439e03 | ||
|
|
bf282e9bd7 | ||
|
|
4c3d3af73e | ||
|
|
10648cac5b | ||
|
|
3bfcd5e105 | ||
|
|
87aca05e7f | ||
|
|
94b1d58cc2 | ||
|
|
c55cbd3f2f | ||
|
|
d89fcdcc5f | ||
|
|
76f715c486 | ||
|
|
bbab6b2fdc | ||
|
|
a8e92639af | ||
|
|
d99c2cb9a7 | ||
|
|
9f8fe3d5e3 | ||
|
|
3c8c8a7559 | ||
|
|
a61e2caadb | ||
|
|
f109d535b1 | ||
|
|
12095c721c | ||
|
|
7b873179ad | ||
|
|
f1d923714a | ||
|
|
b9ba227733 | ||
|
|
f7754a2927 | ||
|
|
125d12798d | ||
|
|
d3bec4e686 | ||
|
|
1b0e4a0067 | ||
|
|
286bef5eb7 | ||
|
|
c9b4163e23 | ||
|
|
fbedf020bc | ||
|
|
d3e9183303 | ||
|
|
aaa0c25ff7 | ||
|
|
2f43584727 | ||
|
|
e7c1cb7185 | ||
|
|
911c37e63e | ||
|
|
8b40f09e17 | ||
|
|
93dfb6f7d6 | ||
|
|
547b0a9850 | ||
|
|
4416753df0 | ||
|
|
dc54ec5b2b | ||
|
|
b682c4102e | ||
|
|
6d522e6ed6 | ||
|
|
635c87d629 | ||
|
|
a355cf24f1 | ||
|
|
bc7ad955a3 | ||
|
|
05125341f1 | ||
|
|
12332328c1 | ||
|
|
8d95d0834d | ||
|
|
db5eebd372 | ||
|
|
b119b4f1da | ||
|
|
694ab455cd | ||
|
|
46edc07ae4 | ||
|
|
2a7fc9c3a5 | ||
|
|
be23c0755e | ||
|
|
db55176212 | ||
|
|
66a445f043 | ||
|
|
6527a48897 | ||
|
|
3f9706a7f3 | ||
|
|
41fc3bcb74 | ||
|
|
d46859b9e8 | ||
|
|
51a955c75c | ||
|
|
9a89da3b33 | ||
|
|
e8da9999f6 | ||
|
|
3f5c02bf92 | ||
|
|
e918851902 | ||
|
|
e411bac592 | ||
|
|
ded81ec186 | ||
|
|
cd276030c1 | ||
|
|
818533f9f0 | ||
|
|
ff7cbab991 | ||
|
|
ad8d68dd43 | ||
|
|
0db1b6ce44 | ||
|
|
843d5a5977 | ||
|
|
406d7f1a47 | ||
|
|
7df89566f3 | ||
|
|
32b2c9fc9e | ||
|
|
3f8baeba20 | ||
|
|
1879dc4b59 | ||
|
|
ea8c6bc15e | ||
|
|
4683ce2771 | ||
|
|
798537d47b | ||
|
|
0257b02a8c | ||
|
|
27e71c5f37 | ||
|
|
cddf7e0986 | ||
|
|
2b35b3f06e | ||
|
|
92b2376c23 | ||
|
|
412902e4ae | ||
|
|
29fda9cb6c | ||
|
|
e7b3f5745c | ||
|
|
268d64d244 | ||
|
|
8f045b9ec5 | ||
|
|
2ea1c2be92 | ||
|
|
5e9ca72731 | ||
|
|
debfc0f712 | ||
|
|
1e65e7c996 | ||
|
|
d12b1650aa | ||
|
|
70a75dc88a | ||
|
|
fa090f2c9f | ||
|
|
b6bd6e399d | ||
|
|
a3b497b271 | ||
|
|
55b3cf4627 | ||
|
|
eb1c00c56b | ||
|
|
c58278758c | ||
|
|
3d0d9a250b | ||
|
|
274f018494 | ||
|
|
970d05df39 | ||
|
|
abae08a9fb | ||
|
|
a0edee51fa | ||
|
|
887474d607 | ||
|
|
3bf3c11b0b | ||
|
|
6d61919941 | ||
|
|
e07de09460 | ||
|
|
98a17f4046 | ||
|
|
f850c021b7 | ||
|
|
8600243683 | ||
|
|
c6e5987480 | ||
|
|
e0c858478a | ||
|
|
a3b15b995e | ||
|
|
57ef5289fe | ||
|
|
a63c0311bb | ||
|
|
9808829ece | ||
|
|
00b6431ad9 | ||
|
|
e020ad0c06 | ||
|
|
df0c1eb32c | ||
|
|
9057801c4b | ||
|
|
0f443ef37b | ||
|
|
a20e0b9e2e | ||
|
|
4b6bd7cae5 | ||
|
|
6f35792c74 | ||
|
|
f1b375b042 | ||
|
|
4e672427bc | ||
|
|
165068c81d | ||
|
|
89993e9cbf | ||
|
|
78ab7e7ba1 | ||
|
|
424bb589a2 | ||
|
|
664fee5c6e | ||
|
|
146a353085 | ||
|
|
214ef3dd0b | ||
|
|
406c8a6d1e | ||
|
|
6416cb45fb | ||
|
|
1db7c6233b | ||
|
|
640beafa8c | ||
|
|
44f70d2b52 | ||
|
|
acbb6fb8e2 | ||
|
|
1163961927 | ||
|
|
e1190eb1f3 | ||
|
|
dc37a8079e | ||
|
|
373cca0bf6 | ||
|
|
b32fcc7a8e | ||
|
|
e9c226b8be | ||
|
|
af9d611847 | ||
|
|
9d6c4fa678 | ||
|
|
b66233de78 | ||
|
|
ff49792f44 | ||
|
|
b2abd963f0 | ||
|
|
0ab9cf8054 | ||
|
|
c70e92e98d | ||
|
|
bf10d6c03b | ||
|
|
de084b4a0d | ||
|
|
e46cbea251 | ||
|
|
7f6e63aba5 | ||
|
|
25081f60c4 | ||
|
|
91bf41cfce | ||
|
|
552d8f394e | ||
|
|
f8e01628b2 | ||
|
|
3d1ad89963 | ||
|
|
2188bb9b88 | ||
|
|
f0000ea7d2 | ||
|
|
5b173dafae | ||
|
|
c939f2ee45 | ||
|
|
309dfeb6a8 | ||
|
|
bf3e4126b2 | ||
|
|
8a357e1866 | ||
|
|
b8135574c3 | ||
|
|
85fdf587c0 | ||
|
|
8d4a701f86 | ||
|
|
1c83144773 | ||
|
|
edb973fadc | ||
|
|
77f1b1f0fe | ||
|
|
a79d3c680c | ||
|
|
ac023f7588 | ||
|
|
f3c8f535a4 | ||
|
|
b02f6cf3bc | ||
|
|
b7c4a4fc3b | ||
|
|
9f33050a32 | ||
|
|
f73caeb6a3 | ||
|
|
15da4aaec7 | ||
|
|
9ee7b0a501 | ||
|
|
3c116f6ab3 | ||
|
|
431ef224e0 | ||
|
|
600aeb6ccc | ||
|
|
a4c646f75c | ||
|
|
7f35f98d7d | ||
|
|
8b10b0a614 | ||
|
|
a9ada13a23 | ||
|
|
1ae0e5d7cb | ||
|
|
808fac9b14 | ||
|
|
737972be2f | ||
|
|
4cb70e8e2a | ||
|
|
abf3ee6563 | ||
|
|
1a0a3d85ca | ||
|
|
1bbac9e5ce | ||
|
|
705793eae6 | ||
|
|
efa6e38741 | ||
|
|
183aea5c96 | ||
|
|
97ddf9a4f3 | ||
|
|
489366290a | ||
|
|
fb8f16373f | ||
|
|
fed352653d | ||
|
|
a697b2b60e | ||
|
|
efe9c82bc6 | ||
|
|
2bdb199169 | ||
|
|
d0dabb0ff6 | ||
|
|
27e4ece24f | ||
|
|
fc898eff65 | ||
|
|
dd317709f8 | ||
|
|
fde9842a8e | ||
|
|
3bf88110aa | ||
|
|
cc5c411039 | ||
|
|
37bdb20092 | ||
|
|
e31431140a | ||
|
|
8a66ba6c35 | ||
|
|
8a446f43ff | ||
|
|
d6b5558cf2 | ||
|
|
50c04752f5 | ||
|
|
2a91a7640c | ||
|
|
6b35250099 | ||
|
|
2ba92f92b7 | ||
|
|
0b1e371880 | ||
|
|
ce15abd577 | ||
|
|
30392bf66a | ||
|
|
71233ee894 | ||
|
|
af3059ab2a | ||
|
|
1f0ae8b06d | ||
|
|
d5af389d2e | ||
|
|
644607c29f | ||
|
|
aa477195d4 | ||
|
|
b0a9a5a756 | ||
|
|
882a62ad52 | ||
|
|
f9697c8e36 | ||
|
|
0479060858 | ||
|
|
c2e5403408 | ||
|
|
3d2b12e72a | ||
|
|
09b1eee5d0 | ||
|
|
28264423a4 | ||
|
|
87baa4d3d2 | ||
|
|
c5031c2b39 | ||
|
|
82223d3bad | ||
|
|
56dd25667d | ||
|
|
d4a171a791 | ||
|
|
978066a6de | ||
|
|
2628da4a59 | ||
|
|
ccb157c7a3 | ||
|
|
d43c803bfe | ||
|
|
eec6db0a23 | ||
|
|
983bc5cecc | ||
|
|
60435f99b9 | ||
|
|
332cda6b16 | ||
|
|
8d73f2af34 | ||
|
|
6a8219a02e | ||
|
|
c8f7d33a9a | ||
|
|
40ec2303ff | ||
|
|
19eddddcff | ||
|
|
b1e86d6fea | ||
|
|
b9283d48b5 | ||
|
|
33fc5c99ea | ||
|
|
a4581cb233 | ||
|
|
36dfc9f1bf | ||
|
|
4a55fff3b9 | ||
|
|
02f16e90b6 | ||
|
|
984a498063 | ||
|
|
c1b51c6530 | ||
|
|
224de547b3 | ||
|
|
43d2e15bb7 | ||
|
|
ac70772070 | ||
|
|
1feea366ca | ||
|
|
f599239fd4 | ||
|
|
a122d2eb50 | ||
|
|
17e7860700 | ||
|
|
34fab879cb | ||
|
|
b02ed0bbe6 | ||
|
|
165ba535f0 | ||
|
|
8253df7c3d | ||
|
|
4788da204b | ||
|
|
cf11d1e4e6 | ||
|
|
e557327860 | ||
|
|
e152cfac34 | ||
|
|
464f1f44aa | ||
|
|
bf27cb1f5e | ||
|
|
654010f639 | ||
|
|
918f84438f | ||
|
|
93e2415924 | ||
|
|
4837a2d0df | ||
|
|
be80e1a863 | ||
|
|
e53e00c4f9 | ||
|
|
90495f3ac5 | ||
|
|
6fc9e6f21e | ||
|
|
7117c4a5ee | ||
|
|
a3a7c48799 | ||
|
|
f545fb2491 | ||
|
|
e73be48d96 | ||
|
|
04b1b83039 | ||
|
|
e9d216bc84 | ||
|
|
87510ac77d | ||
|
|
44ce3e6731 | ||
|
|
26678682ca | ||
|
|
7d63900fb8 | ||
|
|
e47d56a84f | ||
|
|
9b52269a5b | ||
|
|
9992b8eb0e | ||
|
|
bab69f2672 | ||
|
|
2e33633698 | ||
|
|
eb7601d116 | ||
|
|
5827bfd9a2 | ||
|
|
dc8cc39bc8 | ||
|
|
47df1ae40a | ||
|
|
c9c2fc5ee3 | ||
|
|
b79854ad1a | ||
|
|
8229b17f0d | ||
|
|
4a5d02aab4 | ||
|
|
ed4e6cd3a5 | ||
|
|
7d45e6f12f | ||
|
|
0302162d8e | ||
|
|
1dfa404210 | ||
|
|
bd4551e2ef | ||
|
|
d6a56428d1 | ||
|
|
a10fa3a20b | ||
|
|
be5fde9e54 | ||
|
|
abfc7e16a1 | ||
|
|
d76f880faf | ||
|
|
21e83a881e | ||
|
|
5ba1261285 | ||
|
|
7bb844a778 | ||
|
|
8c24d49c73 | ||
|
|
5e371e8fe7 | ||
|
|
e46324ced9 | ||
|
|
5ea486b20a | ||
|
|
425afa63ce | ||
|
|
7c09a767b6 | ||
|
|
768f92303e | ||
|
|
34054fa1fb | ||
|
|
4a37d6d1f9 | ||
|
|
8dfc8625a7 | ||
|
|
e878947cb2 | ||
|
|
f56f84c6ac | ||
|
|
239d43dac4 | ||
|
|
8a63326411 | ||
|
|
01608cf062 | ||
|
|
e06d6ce4a2 | ||
|
|
58a0c6f9d3 | ||
|
|
f310f1e96c | ||
|
|
c7bf1aa222 | ||
|
|
be3fff9282 | ||
|
|
e52cf09bc1 | ||
|
|
57de1388e8 | ||
|
|
7ee0ce745e | ||
|
|
469743cd23 | ||
|
|
91e1d59869 | ||
|
|
5fb97f05a3 | ||
|
|
618b42980d | ||
|
|
211b9ea8b9 | ||
|
|
833abc27cc | ||
|
|
3d5a3f03fa | ||
|
|
51de26960c | ||
|
|
b67526aae8 | ||
|
|
14bf057c62 | ||
|
|
8eb53ea7ca | ||
|
|
9b60af4d52 | ||
|
|
956f99365a | ||
|
|
9904415144 | ||
|
|
83febbdc7d | ||
|
|
6b026e399c | ||
|
|
a661c03743 | ||
|
|
ffc03735e8 | ||
|
|
c7e24488eb | ||
|
|
fe7d2c57e3 | ||
|
|
4fc80b5057 | ||
|
|
12f3f5dcbb | ||
|
|
16f2ffc29d | ||
|
|
86a978d9ee | ||
|
|
f6fe3df59b | ||
|
|
e0764bb25e | ||
|
|
1ba0bfd10c | ||
|
|
593ab75a76 | ||
|
|
3589554028 | ||
|
|
1a59346b51 | ||
|
|
ff124465fd | ||
|
|
de5223db66 | ||
|
|
cc1395797e | ||
|
|
122791646e | ||
|
|
a3c4de52d6 | ||
|
|
95de6cf5a7 | ||
|
|
d788c84440 | ||
|
|
96046ffd30 | ||
|
|
b5e92a831b | ||
|
|
a2788129ff | ||
|
|
5bbf220077 | ||
|
|
f5d4e3f94c | ||
|
|
04ea680e9a | ||
|
|
3a940781d9 | ||
|
|
00fcd63b88 | ||
|
|
f3093649de | ||
|
|
670e33ab27 | ||
|
|
3606664cf7 | ||
|
|
81f45208b0 | ||
|
|
9145d05397 | ||
|
|
ef566836c4 | ||
|
|
10dfca1a75 | ||
|
|
b3e3f041fe | ||
|
|
e3ec361552 | ||
|
|
bfccc7133d | ||
|
|
f41a699f5d | ||
|
|
7d029778e6 | ||
|
|
26857fabdc | ||
|
|
a9b119833a | ||
|
|
c5ffe8a974 | ||
|
|
df1b4e1f21 | ||
|
|
61686aff34 | ||
|
|
ad6645c48d | ||
|
|
1e328c3546 | ||
|
|
0e2a625815 | ||
|
|
6eb66770a4 | ||
|
|
84729c4dfa | ||
|
|
8de8877c7c | ||
|
|
fdc6c3722a | ||
|
|
deca475972 | ||
|
|
ba070e21e4 | ||
|
|
35e9fd1bb0 | ||
|
|
4906609dd9 | ||
|
|
682353f9cc | ||
|
|
25c6671a87 | ||
|
|
c67702a498 | ||
|
|
5880cd88c8 | ||
|
|
54ceb4211e | ||
|
|
7a46227141 | ||
|
|
b904aa78e8 | ||
|
|
8185bee4b8 | ||
|
|
2e1b3325c6 | ||
|
|
1b8f1650dc | ||
|
|
1070b34996 | ||
|
|
13b1b73c15 | ||
|
|
e1de72d0ac | ||
|
|
dc837eb8a3 | ||
|
|
f6b76e6ecb | ||
|
|
e7cbcc83a4 | ||
|
|
390700ca71 | ||
|
|
b604321169 | ||
|
|
62c49f13ce | ||
|
|
eba75dbc2e | ||
|
|
32d2d0f0d0 | ||
|
|
81e0342bf6 | ||
|
|
56599621cc | ||
|
|
261bf12c91 | ||
|
|
b08fb86637 | ||
|
|
b290fd33b9 | ||
|
|
966bbd476f | ||
|
|
cf9bfe9e66 | ||
|
|
bb4a05032b | ||
|
|
7039e01136 | ||
|
|
e9f43f1097 | ||
|
|
150789690f | ||
|
|
e284233013 | ||
|
|
d06d6c6964 | ||
|
|
977a4477f6 | ||
|
|
33c6410809 | ||
|
|
7e321afd2a | ||
|
|
548ea1e54a | ||
|
|
4755c5f8c8 | ||
|
|
ea1bfd715e | ||
|
|
b1281c3fb9 | ||
|
|
257e9b04fe | ||
|
|
8643870822 | ||
|
|
6819696222 | ||
|
|
193bbd4e00 | ||
|
|
1bf168348e | ||
|
|
f8b4c1b389 | ||
|
|
830fba64b1 | ||
|
|
1cd61952b0 | ||
|
|
4ee1cc3b37 | ||
|
|
11dd904b6d | ||
|
|
0c03b6ddc7 | ||
|
|
176a3913aa | ||
|
|
6f0b00f983 | ||
|
|
69ace201f8 | ||
|
|
a04f31c5c0 | ||
|
|
1d9f47d1e5 | ||
|
|
36a91fc6ff | ||
|
|
cd3ed71137 | ||
|
|
73e56527bf | ||
|
|
24059924b1 | ||
|
|
bb100a2511 | ||
|
|
0c8c32cd03 | ||
|
|
a38d6e74f5 | ||
|
|
05d8dacb27 | ||
|
|
d6a0859eab | ||
|
|
4912967eab | ||
|
|
76e1cda495 | ||
|
|
c1a23bf450 | ||
|
|
b25b5bf5f6 | ||
|
|
079f17761c | ||
|
|
e1b8c425da | ||
|
|
5f05756e65 | ||
|
|
c0e996acf8 | ||
|
|
41ec58a524 | ||
|
|
0a5e7be129 | ||
|
|
b23d65b014 | ||
|
|
60ef7903e2 | ||
|
|
ee8fd21d28 | ||
|
|
232ed91ec7 | ||
|
|
7fccad156e | ||
|
|
11e56456a0 | ||
|
|
d07e78c59a | ||
|
|
c45479a6e5 | ||
|
|
345a528625 | ||
|
|
01d8490255 | ||
|
|
ea4b37d5c5 | ||
|
|
a1319cb8aa | ||
|
|
35c49d62d7 | ||
|
|
0576a11a6f | ||
|
|
c8f86d94c9 | ||
|
|
2b24eab26a | ||
|
|
7bbc7a61ce | ||
|
|
fe26284376 | ||
|
|
ab62fe6496 | ||
|
|
bc9bae0f7f | ||
|
|
e5939d1a18 | ||
|
|
5fadb7f200 | ||
|
|
a02aa7a316 | ||
|
|
3ab26a5d40 | ||
|
|
a8bae31939 | ||
|
|
faea588fb8 | ||
|
|
792e246262 | ||
|
|
85f19f9b8c | ||
|
|
40e4f49dbe | ||
|
|
05c721bebb | ||
|
|
e995cc9329 | ||
|
|
9457c115be | ||
|
|
1eddc79a90 | ||
|
|
ccfc909eb2 | ||
|
|
1a93cbba1e | ||
|
|
529d410bec | ||
|
|
4d1c0eaa52 | ||
|
|
adfd3c1098 | ||
|
|
f7d0c4b065 | ||
|
|
5fb32f1e2d | ||
|
|
f69489a4fc | ||
|
|
d34ce26c4e | ||
|
|
3f7fe94009 | ||
|
|
ae593decfc | ||
|
|
eea62125a1 | ||
|
|
96f36a63dc | ||
|
|
19e183f02f | ||
|
|
57f3df3cab | ||
|
|
08e78e63cf | ||
|
|
9228dffe5e | ||
|
|
93dc7d4cc1 | ||
|
|
1bead8adf7 | ||
|
|
6681f3bfec | ||
|
|
71f8960ef1 | ||
|
|
01780f19b1 | ||
|
|
1fa0c4d4d3 | ||
|
|
eebe126842 | ||
|
|
ebfa285122 | ||
|
|
27212719dc | ||
|
|
17567028da | ||
|
|
34fd8e0e00 | ||
|
|
6cf42075fc | ||
|
|
afd8d2f9ba | ||
|
|
1d54bff385 | ||
|
|
6dd0013a5d | ||
|
|
f2b5292bcb | ||
|
|
3a94f6e8b3 | ||
|
|
f2846a0b78 | ||
|
|
dbde7033d8 | ||
|
|
18f04adccb | ||
|
|
1ed65b6bd7 | ||
|
|
9b781c4c06 | ||
|
|
25f9105a97 | ||
|
|
602109bd8d | ||
|
|
631d27f7a8 | ||
|
|
aad27a7a68 | ||
|
|
4ac01154d9 | ||
|
|
4e2c7c57d7 | ||
|
|
6e65cfcc9a | ||
|
|
96a4b7eaa7 | ||
|
|
64afada7f0 | ||
|
|
9f563f4873 | ||
|
|
ca61d0ee8b | ||
|
|
e96dabadf1 | ||
|
|
b6601338c2 | ||
|
|
8167e1e07e | ||
|
|
23ce927301 | ||
|
|
c7941fc7b0 | ||
|
|
1078ad9ae9 | ||
|
|
c0085cbc61 | ||
|
|
a49d245b92 | ||
|
|
0ce6829e4c | ||
|
|
4e3acdcbdc | ||
|
|
85f808130d | ||
|
|
b187538339 | ||
|
|
93f6aabe12 | ||
|
|
10aa107380 | ||
|
|
53cba2a2e6 | ||
|
|
d871095d0b | ||
|
|
9bf8a5e877 | ||
|
|
3836bfe5a1 | ||
|
|
7698553c3a | ||
|
|
be1d216b34 | ||
|
|
85cbb943b5 | ||
|
|
ec34f2527a | ||
|
|
b877181e17 | ||
|
|
69446be1ee | ||
|
|
cc90f9cf80 | ||
|
|
457e6a5f46 | ||
|
|
e7db18bae2 | ||
|
|
f8e3e853aa | ||
|
|
b7ba252965 | ||
|
|
ae12e1b537 | ||
|
|
9255f625fa | ||
|
|
377d93d1cf | ||
|
|
19d14c7c3a | ||
|
|
6e3a823b7b | ||
|
|
51f9ff5389 | ||
|
|
4986e6e3f9 | ||
|
|
9d8ae184c9 | ||
|
|
4afdcf56fc | ||
|
|
0fe43eb880 | ||
|
|
4edfd6d9d6 | ||
|
|
8351ec0afd | ||
|
|
92ce84c26a | ||
|
|
9d31e52b2a | ||
|
|
dcd7d6769d | ||
|
|
87c0e0e971 | ||
|
|
6f9a523151 | ||
|
|
673faf7152 | ||
|
|
18ace555b0 | ||
|
|
d09c9fba02 | ||
|
|
f1d22b6300 | ||
|
|
da6295c428 | ||
|
|
86645b32e1 | ||
|
|
977c585f8b | ||
|
|
4c1ddab560 | ||
|
|
f5442bdd4a | ||
|
|
129525af21 | ||
|
|
c15975113a | ||
|
|
2d3d6e1c17 | ||
|
|
b0f4ff2879 | ||
|
|
070b10689c | ||
|
|
39863ce4d7 | ||
|
|
7cae1ae415 | ||
|
|
eca2100312 | ||
|
|
175249b455 | ||
|
|
294fbc8309 | ||
|
|
9bcc7df96f | ||
|
|
4bd63020ca | ||
|
|
4885842ae8 | ||
|
|
4df6b599b8 | ||
|
|
0c79bb6e7c | ||
|
|
1a264ab7c2 | ||
|
|
99b51ce6ea | ||
|
|
e0baab2722 | ||
|
|
71a8d39372 | ||
|
|
90826e4031 | ||
|
|
0e4f2cca01 | ||
|
|
ac3dce38f0 | ||
|
|
3be07cc645 | ||
|
|
07f5319472 | ||
|
|
47019e315a | ||
|
|
fe7fa46d57 | ||
|
|
007c5bc9f0 | ||
|
|
8c423b56df | ||
|
|
a868abb55a | ||
|
|
ecab34c787 | ||
|
|
307ea6dce2 | ||
|
|
d456b4f68e | ||
|
|
17e815348b | ||
|
|
953ab4b3cf | ||
|
|
9204780c1b | ||
|
|
fb2ed355ec | ||
|
|
675106cfa5 | ||
|
|
3aeadd9fb7 | ||
|
|
0e3eb38f11 | ||
|
|
dc23af6b32 | ||
|
|
b1bfa71338 | ||
|
|
3c190374b4 | ||
|
|
d8428463d8 | ||
|
|
725982cc5b | ||
|
|
f977dfcfe7 | ||
|
|
15079fa3bd | ||
|
|
79a92120ef | ||
|
|
a34565ca0f | ||
|
|
49ece586d5 | ||
|
|
2ec0778d78 | ||
|
|
cccd1cefbe | ||
|
|
8f145fa7fa | ||
|
|
ceb32f63e7 | ||
|
|
576c12b184 | ||
|
|
e2c3ca9950 | ||
|
|
8585e0e9b8 | ||
|
|
7394374a15 | ||
|
|
37defa739b | ||
|
|
51ed3fbc4b | ||
|
|
ab78075d06 | ||
|
|
52070ea577 | ||
|
|
f930303d3e | ||
|
|
268fb37517 | ||
|
|
ff17101316 | ||
|
|
ab536e5199 | ||
|
|
c10b3017d6 | ||
|
|
0f63e1f988 | ||
|
|
3bb537c183 | ||
|
|
ff23bf6f0c | ||
|
|
00d3e18780 | ||
|
|
a62f300753 | ||
|
|
0bc644abf0 | ||
|
|
31b7d076b7 | ||
|
|
a11687fc5c | ||
|
|
fa346cec3b | ||
|
|
0bdf7a598a | ||
|
|
0c9a1a56c2 | ||
|
|
c0655b6b08 | ||
|
|
dca9b83ec0 | ||
|
|
7ded90ae6a | ||
|
|
a6ab66080e | ||
|
|
89e1cad470 | ||
|
|
e55bc92d1f | ||
|
|
d6a59b538f | ||
|
|
1a87f44325 | ||
|
|
c8bc535f22 | ||
|
|
1889db3263 | ||
|
|
73b88f2304 | ||
|
|
21b8e5a5c6 | ||
|
|
b1ff14162f | ||
|
|
c6c55823ac | ||
|
|
8b8a970098 | ||
|
|
ebfcee6e67 | ||
|
|
63b330439e | ||
|
|
52d8fb301c | ||
|
|
dfe159e719 | ||
|
|
4e7e45a431 | ||
|
|
d81bd296fc | ||
|
|
6d3f257439 | ||
|
|
f92b24221a | ||
|
|
afd78f3f0b | ||
|
|
44f3f51e0d | ||
|
|
14a35e7c21 | ||
|
|
d173bb6e0a | ||
|
|
ce859c9e92 | ||
|
|
8ed20f3c28 | ||
|
|
0ced7d8e56 | ||
|
|
143ead8d00 | ||
|
|
6788c2710f | ||
|
|
ed7c10f366 | ||
|
|
68b93c624f | ||
|
|
36fe1e4a46 | ||
|
|
9ee4e4e05c | ||
|
|
ea65a0c519 | ||
|
|
f35d2629d4 | ||
|
|
0e5578204e | ||
|
|
063a465227 | ||
|
|
230fb921ec | ||
|
|
82a93d8406 | ||
|
|
2dda8634e9 | ||
|
|
2f313b799a | ||
|
|
d371256913 | ||
|
|
a7ec93b287 | ||
|
|
2c5001a5b3 | ||
|
|
191221eec5 | ||
|
|
27f374a38b | ||
|
|
baa813c46f | ||
|
|
79a22b1f8d | ||
|
|
087940ec9e | ||
|
|
8a46931e34 | ||
|
|
a9313fc0c3 | ||
|
|
dfba35aee8 | ||
|
|
5ae77b4317 | ||
|
|
a0bb2cdc6e | ||
|
|
0a5680c3e8 | ||
|
|
00764406d7 | ||
|
|
3ead99b088 | ||
|
|
8c0803e3c5 | ||
|
|
2da8df6202 | ||
|
|
17a75a5aa5 | ||
|
|
8b26d0104c | ||
|
|
36622c3578 | ||
|
|
fd4df6f9bb | ||
|
|
5d18d60e3b | ||
|
|
e4d98597c7 | ||
|
|
72da14e414 | ||
|
|
8ada404c5f | ||
|
|
ebba30d671 | ||
|
|
909d24cde6 | ||
|
|
4e912ef83d | ||
|
|
b17dfff3fd | ||
|
|
52dc415d0b | ||
|
|
392232246e | ||
|
|
cf54ad8242 | ||
|
|
fdfa5c0602 | ||
|
|
50ee5d28cd | ||
|
|
f74a82776f | ||
|
|
3553e65089 | ||
|
|
ad7c5886bc | ||
|
|
b30090f946 | ||
|
|
8f637975a4 | ||
|
|
94a764d6ea | ||
|
|
38e40862fe | ||
|
|
5ea78f55f2 | ||
|
|
a515db4aea | ||
|
|
90e979d0d9 | ||
|
|
8232857d07 | ||
|
|
2ae56564ef | ||
|
|
f24a0170be | ||
|
|
fd56465931 | ||
|
|
376e199ebb | ||
|
|
a837a27b34 | ||
|
|
62bd43f17f | ||
|
|
917b4ff8bc | ||
|
|
5fe7c065dc | ||
|
|
e074ad4807 | ||
|
|
5f3fe4acff | ||
|
|
4ccc197451 | ||
|
|
237cf19a77 | ||
|
|
2206e221bd | ||
|
|
d9bb9b73ad | ||
|
|
d5c382bb1a | ||
|
|
52daf6cf41 | ||
|
|
74a7303c23 | ||
|
|
d8a9991738 | ||
|
|
ca1c8243c8 | ||
|
|
14b3a5be56 | ||
|
|
ed89df7e9d | ||
|
|
1bedc16544 | ||
|
|
ac0b97a571 | ||
|
|
7b3d670e23 | ||
|
|
c9f4e91df8 | ||
|
|
c0ed169fdc | ||
|
|
412894bfc8 | ||
|
|
aad6e5648b | ||
|
|
8f1423946f | ||
|
|
51da4856e2 | ||
|
|
3b56c58f00 | ||
|
|
4fd2531302 | ||
|
|
fdef238a83 | ||
|
|
9787901ddb | ||
|
|
6e58c9f7c8 | ||
|
|
a08450bcb6 | ||
|
|
a92d9d442b | ||
|
|
e2ff77b4ec | ||
|
|
caf7a93382 | ||
|
|
afcda2f724 | ||
|
|
fcea723aa7 | ||
|
|
faf80588ab | ||
|
|
fc589611e2 | ||
|
|
5ecd350311 | ||
|
|
4b6c6c59b5 | ||
|
|
0f8ffa6226 | ||
|
|
6def61dfe9 | ||
|
|
b39bebee06 | ||
|
|
dce189fc6d | ||
|
|
0a4c72e78b | ||
|
|
d66700a0e4 | ||
|
|
b59a22bef0 | ||
|
|
9b1930588f | ||
|
|
18bb64cd43 | ||
|
|
d975187433 | ||
|
|
910863e9ea | ||
|
|
a38490429b | ||
|
|
80e8f6a0d1 | ||
|
|
e5ff5f7484 | ||
|
|
646240fc54 | ||
|
|
19cd7a248d | ||
|
|
f1b1d1ca75 | ||
|
|
e5bba2294d | ||
|
|
19cfd9b5d6 | ||
|
|
7e1b15a0cc | ||
|
|
19858c574d | ||
|
|
f891ea5713 | ||
|
|
d3311c81e5 | ||
|
|
b6bc4381fb | ||
|
|
b3d0561c09 | ||
|
|
1bbe901bcd | ||
|
|
4f8b4379f5 | ||
|
|
bc8a288386 | ||
|
|
3dc56de0ae | ||
|
|
b2e5809180 | ||
|
|
7e52523541 | ||
|
|
8bc83c5967 | ||
|
|
029c8c06c2 | ||
|
|
063fc0c48b | ||
|
|
191eeab589 | ||
|
|
3f8621e566 | ||
|
|
5f686ebb47 | ||
|
|
6a31457c6d | ||
|
|
e6f7912a25 | ||
|
|
8a2737566c | ||
|
|
006523ac59 | ||
|
|
c0e783eb6e | ||
|
|
399c78fbf7 | ||
|
|
a0a43046b3 | ||
|
|
e8af86017a | ||
|
|
382ffe9b6a | ||
|
|
e5b34d5cd5 | ||
|
|
0dba7b3313 | ||
|
|
27f2859258 | ||
|
|
eeed45da0f | ||
|
|
067dff8489 | ||
|
|
7d3151191d | ||
|
|
98fa1325f5 | ||
|
|
bd45b79ed8 | ||
|
|
0a616a9dbb | ||
|
|
a534c397f5 | ||
|
|
737589ec01 | ||
|
|
a7f8ee90c0 | ||
|
|
b14683200a | ||
|
|
c82410bfda | ||
|
|
00ad837eb4 | ||
|
|
9ab54030b9 | ||
|
|
5ad6849d4e | ||
|
|
7fcf25a78f | ||
|
|
5c205c43d1 | ||
|
|
f20f49d872 | ||
|
|
fb63c3908c | ||
|
|
623eb42a6a | ||
|
|
6afc06b97e | ||
|
|
cdd5b1ed26 | ||
|
|
884b4026dd | ||
|
|
62f49c55ce | ||
|
|
0b4b6c498d | ||
|
|
409f70c7f3 | ||
|
|
bb19fe703a | ||
|
|
eef1e3e77e | ||
|
|
562ba1291e | ||
|
|
3adf6d25f6 | ||
|
|
beece6a828 | ||
|
|
207ab2aa5b | ||
|
|
4ccc2550d0 | ||
|
|
0c9e398bef | ||
|
|
af2d348543 | ||
|
|
13f72decf4 | ||
|
|
3ad7de0fcb | ||
|
|
48408b0a0b | ||
|
|
cd7d1f2bfe | ||
|
|
ed66a46113 | ||
|
|
8e4e30d266 | ||
|
|
f988dcd6f9 | ||
|
|
143091edad | ||
|
|
79e0405f6a | ||
|
|
316f81119f | ||
|
|
8d016040ab | ||
|
|
4da6986a68 | ||
|
|
3b8a4e56b0 | ||
|
|
966cd6a8ca | ||
|
|
f243cd86c9 | ||
|
|
1a5d866a91 | ||
|
|
a1d8ed83dd | ||
|
|
7f284c404f | ||
|
|
d1b3b6a0ed | ||
|
|
9b37bc667f | ||
|
|
4eea68b5a4 | ||
|
|
87429bc03c | ||
|
|
6c28448e84 | ||
|
|
843ba4ac2c | ||
|
|
d6545588a3 | ||
|
|
26b375a0de | ||
|
|
2f1cac604d | ||
|
|
8e56763c98 | ||
|
|
e94e1cc72f | ||
|
|
4dfe36feb1 | ||
|
|
0d1c2a3b2a | ||
|
|
378fd60756 | ||
|
|
fa569b32fb | ||
|
|
78f8317de8 | ||
|
|
6e8637fbc9 | ||
|
|
8403aae928 | ||
|
|
b43c8da66b | ||
|
|
da85bdc401 | ||
|
|
7e486e3b5c | ||
|
|
062e423125 | ||
|
|
3d8face1f9 | ||
|
|
0c99fc5b4d | ||
|
|
51d7d5d0da | ||
|
|
c959584831 | ||
|
|
fa796d668f | ||
|
|
e4ee4ec3d1 | ||
|
|
0073a93079 | ||
|
|
7e124cf95e | ||
|
|
c647bed9d5 | ||
|
|
6f330f961b | ||
|
|
140ead65b6 | ||
|
|
55091d9deb | ||
|
|
1b3427acd9 | ||
|
|
60d1ac4fec | ||
|
|
9b133a978d | ||
|
|
203c749e6c | ||
|
|
f3e2d2f68f | ||
|
|
a359f45df2 | ||
|
|
e8b6d48ad0 | ||
|
|
8ba79d6ab9 | ||
|
|
57c9eeeecb | ||
|
|
f78c4fa751 | ||
|
|
3ba6e9db5d | ||
|
|
610246c48f | ||
|
|
d0e18e3d20 | ||
|
|
72cfdbbb4e | ||
|
|
15296dedd5 | ||
|
|
943cc68f54 | ||
|
|
3bb4d0b276 | ||
|
|
9cc2217a26 | ||
|
|
ee687ee433 | ||
|
|
9b56b67c0e | ||
|
|
48655e882e | ||
|
|
7f49d37a51 | ||
|
|
9f8a1168e6 | ||
|
|
c18d177b8c | ||
|
|
7bde2b5cbf | ||
|
|
7b3377e78c | ||
|
|
feed900f3d | ||
|
|
7530057c6e | ||
|
|
a6b3f6b5d4 | ||
|
|
76f870a30a | ||
|
|
02092f315e | ||
|
|
9ef9284a34 | ||
|
|
820acb981b | ||
|
|
2516fd90eb | ||
|
|
de23368d03 | ||
|
|
4df57fda09 | ||
|
|
6f45832aed | ||
|
|
fec0415d4e | ||
|
|
04c7d87261 | ||
|
|
6abf3db13e | ||
|
|
99000e68b7 | ||
|
|
bef046a51a | ||
|
|
78322a6321 | ||
|
|
46fa2dd2f0 | ||
|
|
451399b344 | ||
|
|
22a8e57a57 | ||
|
|
9cd279e0e9 | ||
|
|
b67eaa3abd | ||
|
|
046c9b56f5 | ||
|
|
6ad80247ce | ||
|
|
0b744edfa4 | ||
|
|
0d8bb78f66 | ||
|
|
28ecc68841 | ||
|
|
7c7aba1202 | ||
|
|
74a1d70b8a | ||
|
|
165a5aaa83 | ||
|
|
04856aded0 | ||
|
|
a9c238a1fc | ||
|
|
8d2f107d61 | ||
|
|
3f16ace678 |
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
/build_tools export-ignore
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -4,7 +4,9 @@
|
||||
Doxyfile.help
|
||||
Makefile
|
||||
autom4te.cache/
|
||||
build/
|
||||
command_list.txt
|
||||
confdefs.h
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
@@ -13,7 +15,6 @@ configure
|
||||
doc.h
|
||||
doc_src/commands.hdr
|
||||
doc_src/index.hdr
|
||||
etc/config.fish
|
||||
po/*.gmo
|
||||
fish
|
||||
fish.spec
|
||||
@@ -28,6 +29,6 @@ share/config.fish
|
||||
share/man/
|
||||
toc.txt
|
||||
user_doc/
|
||||
xsel-1.2.0/
|
||||
xcuserdata
|
||||
tests/*tmp.*
|
||||
tests/foo.txt
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
24-01-2012 Jan Kanis
|
||||
* Added a changelog file
|
||||
* removed unescaping if the 'commandline' builtin is called without the -o (tokenise) flag
|
||||
* Added a changelog file
|
||||
* removed unescaping if the 'commandline' builtin is called without the -o (tokenise) flag
|
||||
|
||||
73
INSTALL
73
INSTALL
@@ -1,73 +0,0 @@
|
||||
|
||||
Known issues
|
||||
============
|
||||
|
||||
Fish is developed using GCC, with the goal of using only C89 language
|
||||
features. Fish does, however use the *wprintf family of functions,
|
||||
which are new to the C99 standrard. It is not unlikely that any given
|
||||
release contains a few GCC:isms, but ICC 9.0.030 has been found to
|
||||
produce working binaries. GCC 2.95.* won't compile fish, but GCC 3.2.3
|
||||
is known to work. Patches to fix any remaining GNU:isms are welcome.
|
||||
|
||||
Older versions of Doxygen has bugs in the man-page generation which
|
||||
cause the builtin help to render incorrectly. Doxygen 1.2.14 is known
|
||||
to have this problem.
|
||||
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
Fish requires the following programs and libraries to build:
|
||||
|
||||
- Doxygen
|
||||
- Curses or Ncurses
|
||||
- GNU make
|
||||
- GCC
|
||||
|
||||
fish also relies on standard unix tools such as cat, cut, grep, sed,
|
||||
whoami, bc and echo. Fish does not yet support cross-compilation,
|
||||
separate build directories or any other fancy configure options.
|
||||
|
||||
|
||||
Simple install procedure
|
||||
========================
|
||||
|
||||
Always begin by uninstalling any previous fish versions. This is done
|
||||
by running the command 'make uninstall' in the source directory of
|
||||
your previous fish installation.
|
||||
|
||||
Next, if you have downloaded a fresh copy of the darcs repository of
|
||||
fish, you need to run the 'autoconf' command.
|
||||
|
||||
Then, use following commands to compile fish:
|
||||
|
||||
./configure
|
||||
make # Compile fish
|
||||
make install # Install fish
|
||||
echo /usr/local/bin/fish >>/etc/shells # Add fish to list of shells
|
||||
|
||||
Finally, if you wish to use fish as your default shell, use the
|
||||
following command:
|
||||
|
||||
% chsh -s /usr/local/bin/fish
|
||||
|
||||
chsh will prompt you for your password, and change your default shell.
|
||||
|
||||
|
||||
Local install procedure
|
||||
=======================
|
||||
|
||||
If you have downloaded the darcs repository of fish, you need to run
|
||||
autoconf to generate the configure script.
|
||||
|
||||
To install fish in your own home directory (typically as non-root),
|
||||
type:
|
||||
|
||||
% ./configure --prefix=$HOME
|
||||
% make # Compile fish
|
||||
% make install # Install fish
|
||||
|
||||
You will not be able to use fish as the default shell unless you also
|
||||
add the corresponding line to /etc/shells, which mostly defeats the
|
||||
point of a local install. As a workaround, you can add fish as the
|
||||
last command of the init files for your regular shell.
|
||||
529
Makefile.in
529
Makefile.in
@@ -38,7 +38,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
# Programs
|
||||
#
|
||||
|
||||
CC := @CC@
|
||||
CXX := @CXX@
|
||||
INSTALL:=@INSTALL@
|
||||
|
||||
|
||||
@@ -55,23 +55,20 @@ mandir = @mandir@
|
||||
sysconfdir = @sysconfdir@
|
||||
docdir = @docdir@
|
||||
localedir = @localedir@
|
||||
prefix = @prefix@
|
||||
optbindirs = @optbindirs@
|
||||
|
||||
#
|
||||
# Various flags
|
||||
#
|
||||
|
||||
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\"
|
||||
CFLAGS = @CFLAGS@ $(MACROS) $(EXTRA_CFLAGS)
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
MACROS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\" -DBINDIR=L\"$(bindir)\"
|
||||
CXXFLAGS = @CXXFLAGS@ $(MACROS) $(EXTRA_CXXFLAGS)
|
||||
LDFLAGS = @LIBS@ @LDFLAGS@
|
||||
LDFLAGS_FISH = ${LDFLAGS} @LIBS_FISH@ @LDFLAGS_FISH@
|
||||
LDFLAGS_FISH_INDENT = ${LDFLAGS} @LIBS_FISH_INDENT@
|
||||
LDFLAGS_FISH_PAGER = ${LDFLAGS} @LIBS_FISH_PAGER@
|
||||
LDFLAGS_FISHD = ${LDFLAGS} @LIBS_FISHD@
|
||||
LDFLAGS_MIMEDB = ${LDFLAGS} @LIBS_MIMEDB@
|
||||
LDFLAGS_SET_COLOR = ${LDFLAGS} @LIBS_SET_COLOR@
|
||||
|
||||
#
|
||||
# Set to 1 if we have gettext
|
||||
@@ -81,11 +78,11 @@ HAVE_GETTEXT=@HAVE_GETTEXT@
|
||||
|
||||
|
||||
#
|
||||
#Additional .c files used by common.o. These also have a corresponding
|
||||
#Additional .cpp files used by common.o. These also have a corresponding
|
||||
#.h file.
|
||||
#
|
||||
|
||||
COMMON_FILES := util.c halloc.c halloc_util.c fallback.c
|
||||
COMMON_FILES := util.cpp fallback.cpp
|
||||
|
||||
|
||||
#
|
||||
@@ -96,8 +93,9 @@ FISH_OBJS := function.o builtin.o complete.o env.o exec.o expand.o \
|
||||
highlight.o history.o kill.o parser.o proc.o reader.o sanity.o \
|
||||
tokenizer.o wildcard.o wgetopt.o wutil.o input.o output.o intern.o \
|
||||
env_universal.o env_universal_common.o input_common.o event.o \
|
||||
signal.o io.o parse_util.o common.o screen.o path.o \
|
||||
parser_keywords.o
|
||||
signal.o io.o parse_util.o common.o screen.o path.o autoload.o \
|
||||
parser_keywords.o iothread.o color.o postfork.o \
|
||||
builtin_test.o
|
||||
|
||||
FISH_INDENT_OBJS := fish_indent.o print_help.o common.o \
|
||||
parser_keywords.o wutil.o tokenizer.o
|
||||
@@ -106,8 +104,9 @@ parser_keywords.o wutil.o tokenizer.o
|
||||
# Additional files used by builtin.o
|
||||
#
|
||||
|
||||
BUILTIN_FILES := builtin_set.c builtin_commandline.c \
|
||||
builtin_ulimit.c builtin_complete.c builtin_jobs.c
|
||||
BUILTIN_FILES := builtin_set.cpp builtin_commandline.cpp \
|
||||
builtin_ulimit.cpp builtin_complete.cpp builtin_jobs.cpp \
|
||||
builtin_set_color.cpp builtin_printf.cpp
|
||||
|
||||
|
||||
#
|
||||
@@ -116,7 +115,7 @@ BUILTIN_FILES := builtin_set.c builtin_commandline.c \
|
||||
|
||||
FISH_PAGER_OBJS := fish_pager.o output.o wutil.o \
|
||||
input_common.o env_universal.o env_universal_common.o common.o \
|
||||
print_help.o
|
||||
print_help.o iothread.o color.o
|
||||
|
||||
|
||||
#
|
||||
@@ -158,7 +157,16 @@ HDR_FILES_SRC := doc_src/index.hdr.in doc_src/commands.hdr.in doc_src/design.hdr
|
||||
# These are the generated result files
|
||||
#
|
||||
|
||||
HDR_FILES := $(subst .hdr.in,.hdr,$(HDR_FILES_SRC))
|
||||
HDR_FILES := $(HDR_FILES_SRC:.hdr.in=.hdr)
|
||||
|
||||
# Use a pattern rule so that Make knows to only issue one invocation
|
||||
# per http://www.gnu.org/software/make/manual/make.html#Pattern-Intro
|
||||
|
||||
# Internalized scripts are currently disabled.
|
||||
# For now, we just generate empty arrays.
|
||||
# To generate them again, you would run this:
|
||||
# ./internalize_scripts.py share/functions/*.fish share/completions/*.fish
|
||||
|
||||
|
||||
#
|
||||
# Files containing documentation for external commands.
|
||||
@@ -189,14 +197,14 @@ DOC_SRC_DIR_FILES := $(HDR_FILES_SRC) $(HELP_SRC)
|
||||
# Files in ./
|
||||
#
|
||||
|
||||
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
|
||||
Makefile.in configure configure.ac config.h.in install-sh \
|
||||
set_color.c key_reader.c $(MIME_OBJS:.o=.h) \
|
||||
$(MIME_OBJS:.o=.c) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
|
||||
$(COMMON_FILES) $(COMMON_FILES:.c=.h) $(FISH_OBJS:.o=.c) \
|
||||
fish.spec.in INSTALL README user_doc.head.html xsel-0.9.6.tar \
|
||||
ChangeLog config.sub config.guess fish_tests.c fish.c fish_pager.c \
|
||||
fishd.c seq.in make_vcs_completions.fish $(FISH_INDENT_OBJS:.o=.c)
|
||||
MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help \
|
||||
Makefile.in configure configure.ac config.h.in install-sh \
|
||||
key_reader.cpp $(MIME_OBJS:.o=.h) \
|
||||
$(MIME_OBJS:.o=.cpp) $(FISH_OBJS:.o=.h) $(BUILTIN_FILES) \
|
||||
$(COMMON_FILES) $(COMMON_FILES:.cpp=.h) $(FISH_OBJS:.o=.cpp) \
|
||||
fish.spec.in INSTALL README user_doc.head.html \
|
||||
ChangeLog config.sub config.guess fish_tests.cpp fish.cpp fish_pager.cpp \
|
||||
fishd.cpp make_vcs_completions.fish $(FISH_INDENT_OBJS:.o=.cpp)
|
||||
|
||||
#
|
||||
# The sorting is not meaningful in itself, but it has the side effect
|
||||
@@ -207,20 +215,6 @@ MAIN_DIR_FILES_UNSORTED := Doxyfile Doxyfile.user Doxyfile.help.in \
|
||||
MAIN_DIR_FILES := $(sort $(MAIN_DIR_FILES_UNSORTED))
|
||||
|
||||
|
||||
#
|
||||
# Files in ./etc/
|
||||
#
|
||||
|
||||
ETC_DIR_FILES :=etc/config.fish.in
|
||||
|
||||
|
||||
#
|
||||
# Files in ./share/
|
||||
#
|
||||
|
||||
SHARE_DIR_FILES :=share/config.fish.in
|
||||
|
||||
|
||||
#
|
||||
# Files in ./tests/
|
||||
#
|
||||
@@ -247,16 +241,14 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)
|
||||
# Programs to install
|
||||
#
|
||||
|
||||
SIMPLE_PROGRAMS := fish set_color mimedb fish_pager fishd fish_indent
|
||||
PROGRAMS := $(SIMPLE_PROGRAMS) @XSEL_BIN@ @SEQ_FALLBACK@
|
||||
|
||||
PROGRAMS := fish mimedb fish_pager fishd fish_indent
|
||||
|
||||
#
|
||||
# Manual pages to install
|
||||
#
|
||||
|
||||
MANUALS := $(addsuffix .1, $(addprefix share/man/, \
|
||||
$(SIMPLE_PROGRAMS))) @XSEL_MAN_PATH@
|
||||
MANUALS := $(addsuffix .1, $(addprefix share/man/man1/, \
|
||||
$(PROGRAMS)))
|
||||
|
||||
|
||||
#
|
||||
@@ -267,18 +259,11 @@ TRANSLATIONS_SRC := $(wildcard po/*.po)
|
||||
TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
|
||||
|
||||
|
||||
#
|
||||
# Extra util
|
||||
#
|
||||
|
||||
XSEL := @XSEL@
|
||||
XSEL_BIN := @XSEL_BIN@
|
||||
|
||||
#
|
||||
# Make everything needed for installing fish
|
||||
#
|
||||
|
||||
all: $(PROGRAMS) user_doc share/man etc/config.fish share/config.fish $(TRANSLATIONS)
|
||||
all: $(PROGRAMS) user_doc share/man $(TRANSLATIONS)
|
||||
@echo fish has now been built.
|
||||
@echo Use \'$(MAKE) install\' to install fish.
|
||||
.PHONY: all
|
||||
@@ -301,12 +286,9 @@ Makefile: Makefile.in configure
|
||||
# and should only be used when debuging fish.
|
||||
#
|
||||
|
||||
debug:
|
||||
$(MAKE) all EXTRA_CFLAGS="-O0 -Wno-unused -Werror -g"
|
||||
.PHONY: debug
|
||||
|
||||
prof:
|
||||
$(MAKE) all EXTRA_CFLAGS="-pg" LDFLAGS="-pg"
|
||||
prof: EXTRA_CXXFLAGS += -pg
|
||||
prof: LDFLAGS += -pg
|
||||
prof: all
|
||||
.PHONY: prof
|
||||
|
||||
#
|
||||
@@ -315,19 +297,18 @@ prof:
|
||||
|
||||
# Depend on the sources (*.hdr.in) and manually make the
|
||||
# intermediate *.hdr and doc.h files if needed
|
||||
# Allow doxygen to fail, e.g. if it does not exist
|
||||
|
||||
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC)
|
||||
$(MAKE) doc.h $(HDR_FILES)
|
||||
doxygen Doxyfile.user
|
||||
touch user_doc
|
||||
user_doc: $(HDR_FILES_SRC) Doxyfile.user user_doc.head.html $(HELP_SRC) doc.h $(HDR_FILES)
|
||||
- (cat Doxyfile.user ; echo PROJECT_NUMBER=@PACKAGE_VERSION@) | doxygen - && touch user_doc
|
||||
|
||||
|
||||
#
|
||||
# Source code documentation. Also includes user documentation.
|
||||
#
|
||||
|
||||
doc: *.h *.c doc.h Doxyfile
|
||||
doxygen;
|
||||
doc: *.h *.cpp doc.h Doxyfile
|
||||
(cat Doxyfile ; echo PROJECT_NUMBER=@PACKAGE_VERSION@) | doxygen - ;
|
||||
|
||||
|
||||
#
|
||||
@@ -351,14 +332,6 @@ test: $(PROGRAMS) fish_tests
|
||||
.PHONY: test
|
||||
|
||||
|
||||
#
|
||||
# Build the xsel program, which is maintained in its own tarball
|
||||
#
|
||||
|
||||
$(XSEL_BIN):
|
||||
$(MAKE) -C $(XSEL) || echo "Failed to build xsel - either add the required dependencies or use './configure --without-xsel' to disable it."
|
||||
|
||||
|
||||
#
|
||||
# commands.hdr collects documentation on all commands, functions and
|
||||
# builtins
|
||||
@@ -377,14 +350,14 @@ doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in
|
||||
cat $@.in | awk '{if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@
|
||||
|
||||
|
||||
toc.txt: $(subst index.hdr,index.hdr.in,$(HDR_FILES))
|
||||
toc.txt: $(HDR_FILES:index.hdr=index.hdr.in)
|
||||
-rm toc.tmp $@
|
||||
for i in $(subst index.hdr,index.hdr.in,$(HDR_FILES)); do\
|
||||
for i in $(HDR_FILES:index.hdr=index.hdr.in); do\
|
||||
NAME=`basename $$i .hdr`; \
|
||||
NAME=`basename $$NAME .hdr.in`; \
|
||||
sed <$$i >>toc.tmp -n \
|
||||
-e 's,.*\\page *\([^ ]*\) *\(.*\)$$,- <a href="'$$NAME'.html" name="toc-'$$NAME'">\2</a>,p' \
|
||||
-e 's,.*\\section *\([^ ]*\) *\(.*\)$$, - <a href="'$$NAME'.html#\1" name="toc-'$$NAME'">\2</a>,p'; \
|
||||
-e 's,.*\\page *\([^ ]*\) *\(.*\)$$,- <a href="'$$NAME'.html" id="toc-'$$NAME'">\2</a>,p' \
|
||||
-e 's,.*\\section *\([^ ]*\) *\(.*\)$$, - <a href="'$$NAME'.html#\1">\2</a>,p'; \
|
||||
done
|
||||
mv toc.tmp $@
|
||||
|
||||
@@ -453,10 +426,10 @@ doc.h: $(HDR_FILES)
|
||||
# Create a template translation object
|
||||
#
|
||||
|
||||
messages.pot: *.c *.h etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq
|
||||
messages.pot: *.cpp *.h share/completions/*.fish share/functions/*.fish
|
||||
if test $(HAVE_GETTEXT) = 1;then \
|
||||
xgettext -k_ -kN_ *.c *.h -o messages.pot; \
|
||||
if xgettext -j -k_ -kN_ -k--description -LShell etc/*.in share/*.in share/completions/*.fish share/functions/*.fish seq -o messages.pot; then true; else \
|
||||
xgettext -k_ -kN_ *.cpp *.h -o messages.pot; \
|
||||
if xgettext -j -k_ -kN_ -k--description -LShell share/completions/*.fish share/functions/*.fish -o messages.pot; then true; else \
|
||||
echo "Your xgettext version is too old to build the messages.pot file"\
|
||||
rm messages.pot\
|
||||
false;\
|
||||
@@ -496,23 +469,10 @@ common.o: $(COMMON_FILES)
|
||||
#
|
||||
|
||||
share/man: $(HELP_SRC)
|
||||
-rm doc_src/*.doxygen # Remove temp files from previous run
|
||||
-rm -r help_doc
|
||||
-mkdir share/man
|
||||
touch share/man
|
||||
for i in $(HELP_SRC); do \
|
||||
FILE=doc_src/`basename $$i .txt`.doxygen; \
|
||||
echo "/** \page" `basename $$i .txt` >$$FILE; \
|
||||
cat $$i >>$$FILE; \
|
||||
echo "*/" >>$$FILE; \
|
||||
done
|
||||
doxygen Doxyfile.help
|
||||
for i in $(HELP_SRC); do \
|
||||
CMD_NAME=`basename $$i .txt`; \
|
||||
sed -e "s/\(.\)\\.SH/\1/" -e "s/$$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" <help_doc/man/man1/$$CMD_NAME.1 >share/man/$$CMD_NAME.1; \
|
||||
done
|
||||
rm doc_src/*.doxygen # Clean up intermediate files in doc_src/
|
||||
rm -r help_doc # Clean up intermediate help_doc tree
|
||||
-rm -Rf share/man/man1
|
||||
./build_tools/build_documentation.sh Doxyfile.help ./doc_src ./share
|
||||
|
||||
#
|
||||
# The build rules for installing/uninstalling fish
|
||||
@@ -549,6 +509,20 @@ check-uninstall:
|
||||
fi;
|
||||
.PHONY: check-uninstall
|
||||
|
||||
check-legacy-binaries:
|
||||
@SEQLOC=$(prefix)/bin/seq;\
|
||||
if test -f "$$SEQLOC" && grep -q '\(^#!/.*/fish\|^#!/usr/bin/env fish\)' "$$SEQLOC"; then\
|
||||
echo "An outdated seq from a previous fish install was found. You should remove it with:";\
|
||||
echo " rm '$$SEQLOC'";\
|
||||
fi;
|
||||
@SETCOLOR_LOC=$(prefix)/bin/set_color;\
|
||||
if test -x "$$SETCOLOR_LOC" && $$SETCOLOR_LOC -v 2>&1 >/dev/null | grep -q "^set_color, version "; then\
|
||||
echo "An outdated set_color from a previous fish install was found. You should remove it with:";\
|
||||
echo " rm '$$SETCOLOR_LOC'";\
|
||||
fi;
|
||||
@true;
|
||||
.PHONY: check-legacy-binaries
|
||||
|
||||
|
||||
#
|
||||
# This check makes sure that the install-sh script is executable. The
|
||||
@@ -565,36 +539,69 @@ install-sh:
|
||||
# Try to install after checking for incompatible installed versions.
|
||||
#
|
||||
|
||||
install: all install-sh check-uninstall install-force
|
||||
install: all install-sh check-uninstall install-force check-legacy-binaries
|
||||
.PHONY: install
|
||||
|
||||
#
|
||||
# Xcode install
|
||||
#
|
||||
xcode-install:
|
||||
rm -Rf /tmp/fish_build;\
|
||||
xcodebuild install DSTROOT=/tmp/fish_build;\
|
||||
ditto /tmp/fish_build /
|
||||
.PHONY: xcode-install
|
||||
|
||||
#
|
||||
# Force installation, even in presense of incompatible previous
|
||||
# version. This may fail.
|
||||
# These 'true' lines are to prevent installs from failing for (e.g.) missing man pages.
|
||||
#
|
||||
|
||||
install-force: all install-translations
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
|
||||
for i in $(PROGRAMS); do\
|
||||
$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir) ; \
|
||||
true ;\
|
||||
done;
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man/man1
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts
|
||||
$(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/
|
||||
$(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/
|
||||
for i in $(COMPLETIONS_DIR_FILES); do \
|
||||
for i in $(COMPLETIONS_DIR_FILES:%='%'); do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/completions/; \
|
||||
true; \
|
||||
done;
|
||||
for i in $(FUNCTIONS_DIR_FILES); do \
|
||||
for i in $(FUNCTIONS_DIR_FILES:%='%'); do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/functions/; \
|
||||
true; \
|
||||
done;
|
||||
for i in share/man/*.1; do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/; \
|
||||
for i in share/man/man1/*.1; do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/man/man1/; \
|
||||
true; \
|
||||
done;
|
||||
for i in share/tools/*.py; do\
|
||||
$(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/; \
|
||||
true; \
|
||||
done;
|
||||
for i in share/tools/web_config/*; do\
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \
|
||||
true; \
|
||||
done;
|
||||
for i in share/tools/web_config/sample_prompts/*.fish; do\
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts/; \
|
||||
true; \
|
||||
done;
|
||||
for i in share/tools/web_config/*.py; do\
|
||||
$(INSTALL) -m 755 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \
|
||||
true; \
|
||||
done;
|
||||
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
|
||||
for i in user_doc/html/* ChangeLog; do \
|
||||
if test -f $$i; then \
|
||||
@@ -604,14 +611,19 @@ install-force: all install-translations
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
|
||||
for i in $(MANUALS); do \
|
||||
$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
|
||||
true; \
|
||||
done;
|
||||
@echo fish is now installed on your system.
|
||||
@echo To run fish, type \'fish\' in your terminal.
|
||||
@echo
|
||||
@echo To use fish as your login shell:
|
||||
@echo \* add the line \'$(DESTDIR)$(bindir)/fish\' to the file \'/etc/shells\'.
|
||||
@grep -q -- "$(DESTDIR)$(bindir)/fish" /etc/shells || echo \* add the line \'$(DESTDIR)$(bindir)/fish\' to the file \'/etc/shells\'.
|
||||
@echo \* use the command \'chsh -s $(DESTDIR)$(bindir)/fish\'.
|
||||
@echo
|
||||
@echo To set your colors, run \'fish_config\'
|
||||
@echo To scan your man pages for completions, run \'fish_update_completions\'
|
||||
@echo To autocomplete command suggestions press Ctrl + F or right arrow key.
|
||||
@echo
|
||||
@echo Have fun!
|
||||
.PHONY: install-force
|
||||
|
||||
@@ -624,17 +636,15 @@ uninstall: uninstall-translations
|
||||
-for i in $(PROGRAMS); do \
|
||||
rm -f $(DESTDIR)$(bindir)/$$i; \
|
||||
done;
|
||||
-rm -f $(DESTDIR)$(bindir)/xsel
|
||||
-rm -f $(DESTDIR)$(sysconfdir)/fish/config.fish
|
||||
-rmdir $(DESTDIR)$(sysconfdir)/fish
|
||||
-rm -rf $(DESTDIR)$(sysconfdir)/fish
|
||||
-if test -d $(DESTDIR)$(datadir)/fish; then \
|
||||
rm -r $(DESTDIR)$(datadir)/fish; \
|
||||
fi
|
||||
-if test -d $(DESTDIR)$(docdir); then \
|
||||
rm -r $(DESTDIR)$(docdir);\
|
||||
rm -rf $(DESTDIR)$(docdir);\
|
||||
fi
|
||||
-for i in $(MANUALS); do \
|
||||
rm -f $(DESTDIR)$(mandir)/man1/`basename $$i`*; \
|
||||
rm -rf $(DESTDIR)$(mandir)/man1/`basename $$i`*; \
|
||||
done;
|
||||
.PHONY: uninstall
|
||||
|
||||
@@ -693,7 +703,7 @@ uninstall-translations:
|
||||
#
|
||||
|
||||
fish: $(FISH_OBJS) fish.o
|
||||
$(CC) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
|
||||
$(CXX) $(FISH_OBJS) fish.o $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -701,7 +711,7 @@ fish: $(FISH_OBJS) fish.o
|
||||
#
|
||||
|
||||
fish_pager: $(FISH_PAGER_OBJS)
|
||||
$(CC) $(FISH_PAGER_OBJS) $(LDFLAGS_FISH_PAGER) -o $@
|
||||
$(CXX) $(FISH_PAGER_OBJS) $(LDFLAGS_FISH_PAGER) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -709,7 +719,7 @@ fish_pager: $(FISH_PAGER_OBJS)
|
||||
#
|
||||
|
||||
fishd: $(FISHD_OBJS)
|
||||
$(CC) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
||||
$(CXX) $(FISHD_OBJS) $(LDFLAGS_FISHD) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -717,7 +727,7 @@ fishd: $(FISHD_OBJS)
|
||||
#
|
||||
|
||||
fish_tests: $(FISH_TESTS_OBJS)
|
||||
$(CC) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
|
||||
$(CXX) $(FISH_TESTS_OBJS) $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -727,23 +737,7 @@ fish_tests: $(FISH_TESTS_OBJS)
|
||||
#
|
||||
|
||||
mimedb: $(MIME_OBJS)
|
||||
$(CC) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Build the set_color program
|
||||
#
|
||||
|
||||
set_color: set_color.o print_help.o common.o
|
||||
$(CC) set_color.o print_help.o common.o wutil.o $(LDFLAGS_SET_COLOR) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Test program for the tokenizer library
|
||||
#
|
||||
|
||||
tokenizer_test: tokenizer.c tokenizer.h wutil.o common.o
|
||||
$(CC) $(CFLAGS) tokenizer.c wutil.o common.o -D TOKENIZER_TEST $(LDFLAGS) -o $@
|
||||
$(CXX) $(MIME_OBJS) $(LDFLAGS_MIMEDB) -o $@
|
||||
|
||||
|
||||
#
|
||||
@@ -751,68 +745,25 @@ tokenizer_test: tokenizer.c tokenizer.h wutil.o common.o
|
||||
#
|
||||
|
||||
fish_indent: $(FISH_INDENT_OBJS)
|
||||
$(CC) $(FISH_INDENT_OBJS) $(LDFLAGS_FISH_INDENT) -o $@
|
||||
$(CXX) $(FISH_INDENT_OBJS) $(LDFLAGS_FISH_INDENT) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Neat little program to show output from terminal
|
||||
#
|
||||
|
||||
key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o
|
||||
$(CC) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o $(LDFLAGS_FISH) -o $@
|
||||
key_reader: key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o iothread.o
|
||||
$(CXX) key_reader.o input_common.o common.o env_universal.o env_universal_common.o wutil.o iothread.o $(LDFLAGS_FISH) -o $@
|
||||
|
||||
|
||||
#
|
||||
# Update dependencies
|
||||
#
|
||||
depend:
|
||||
makedepend -fMakefile.in -Y *.c
|
||||
makedepend -fMakefile.in -Y *.cpp
|
||||
./config.status
|
||||
.PHONY: depend
|
||||
|
||||
#
|
||||
# Copy all the source files into a new directory and use tar to create
|
||||
# an archive from it. Simplest way I could think of to make an archive
|
||||
# witout backups, autogenerated files, etc.
|
||||
#
|
||||
# Uses install instead of mkdir so build won't fail if the directory
|
||||
# exists
|
||||
#
|
||||
|
||||
fish-@PACKAGE_VERSION@.tar: $(DOC_SRC_DIR_FILES) $(MAIN_DIR_FILES) $(ETC_DIR_FILES) $(TEST_DIR_FILES) $(SHARE_DIR_FILES) $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) ChangeLog user_doc share/man
|
||||
rm -rf fish-@PACKAGE_VERSION@
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/doc_src
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/user_doc
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/etc
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/completions
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/functions
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/share/man
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/tests
|
||||
$(INSTALL) -d fish-@PACKAGE_VERSION@/po
|
||||
cp -f $(DOC_SRC_DIR_FILES) fish-@PACKAGE_VERSION@/doc_src
|
||||
cp -f $(MAIN_DIR_FILES) fish-@PACKAGE_VERSION@/
|
||||
cp -f $(ETC_DIR_FILES) fish-@PACKAGE_VERSION@/etc/
|
||||
cp -f $(SHARE_DIR_FILES) fish-@PACKAGE_VERSION@/share/
|
||||
cp -f $(COMPLETIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/completions/
|
||||
cp -f $(FUNCTIONS_DIR_FILES) fish-@PACKAGE_VERSION@/share/functions/
|
||||
cp -f $(TESTS_DIR_FILES) fish-@PACKAGE_VERSION@/tests/
|
||||
cp -f $(TRANSLATIONS_SRC) fish-@PACKAGE_VERSION@/po/
|
||||
cp -f share/man/*.1 fish-@PACKAGE_VERSION@/share/man/
|
||||
cp -rf user_doc fish-@PACKAGE_VERSION@/
|
||||
tar -c fish-@PACKAGE_VERSION@ >fish-@PACKAGE_VERSION@.tar
|
||||
rm -rf fish-@PACKAGE_VERSION@
|
||||
|
||||
|
||||
#
|
||||
# Just an alias for fish-@PACKAGE_VERSION@.tar
|
||||
#
|
||||
|
||||
tar: fish-@PACKAGE_VERSION@.tar
|
||||
.PHONY: tar
|
||||
|
||||
|
||||
#
|
||||
# Make compressed tar archives
|
||||
#
|
||||
@@ -864,10 +815,8 @@ rpm: fish-@PACKAGE_VERSION@.tar.bz2 fish.spec
|
||||
#
|
||||
|
||||
distclean: clean
|
||||
rm -f fish.spec Doxyfile.help
|
||||
rm -f etc/config.fish seq share/config.fish
|
||||
rm -f fish.spec
|
||||
rm -f config.status config.log config.h Makefile
|
||||
rm -rf $(XSEL)
|
||||
.PHONY: distclean
|
||||
|
||||
|
||||
@@ -876,139 +825,157 @@ distclean: clean
|
||||
# are created by the configure script.
|
||||
#
|
||||
|
||||
# Don't delete the docs unless we have Doxygen installed
|
||||
# We provide pre-built docs in the tarball, and if they get
|
||||
# deleted we won't be able to regenerate them
|
||||
|
||||
clean:
|
||||
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.c doc_src/*.o doc_src/commands.hdr
|
||||
rm -f *.o doc.h doc.tmp doc_src/*.doxygen doc_src/*.cpp doc_src/*.o doc_src/commands.hdr
|
||||
rm -f $(GENERATED_INTERN_SCRIPT_FILES)
|
||||
rm -f tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt
|
||||
rm -f $(PROGRAMS) fish_tests tokenizer_test key_reader
|
||||
rm -f share/config.fish etc/config.fish doc_src/index.hdr doc_src/commands.hdr
|
||||
rm -f $(PROGRAMS) fish_tests key_reader
|
||||
rm -f command_list.txt toc.txt
|
||||
rm -f doc_src/index.hdr doc_src/commands.hdr
|
||||
rm -f fish-@PACKAGE_VERSION@.tar
|
||||
rm -f fish-@PACKAGE_VERSION@.tar.gz
|
||||
rm -f fish-@PACKAGE_VERSION@.tar.bz2
|
||||
rm -rf doc;
|
||||
if command -v doxygen; then \
|
||||
rm -rf doc user_doc share/man; \
|
||||
fi
|
||||
rm -rf fish-@PACKAGE_VERSION@
|
||||
rm -f $(TRANSLATIONS)
|
||||
test ! -d "$(XSEL)" || make -C $(XSEL) clean
|
||||
.PHONY: clean
|
||||
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
builtin.o: config.h fallback.h util.h wutil.h builtin.h io.h function.h
|
||||
builtin.o: complete.h proc.h parser.h event.h reader.h env.h common.h
|
||||
builtin.o: wgetopt.h sanity.h tokenizer.h wildcard.h input_common.h input.h
|
||||
builtin.o: intern.h signal.h exec.h highlight.h halloc.h halloc_util.h
|
||||
builtin.o: parse_util.h parser_keywords.h expand.h path.h builtin_set.c
|
||||
builtin.o: builtin_commandline.c builtin_complete.c builtin_ulimit.c
|
||||
builtin.o: builtin_jobs.c
|
||||
builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h builtin.h
|
||||
builtin_commandline.o: io.h common.h wgetopt.h reader.h proc.h parser.h
|
||||
builtin_commandline.o: event.h tokenizer.h input_common.h input.h
|
||||
builtin_commandline.o: parse_util.h
|
||||
builtin_complete.o: config.h signal.h fallback.h util.h wutil.h builtin.h
|
||||
builtin_complete.o: io.h common.h complete.h wgetopt.h parser.h proc.h
|
||||
builtin_complete.o: event.h reader.h
|
||||
builtin_jobs.o: config.h fallback.h util.h wutil.h builtin.h io.h proc.h
|
||||
builtin_jobs.o: parser.h event.h common.h wgetopt.h
|
||||
builtin_set.o: config.h signal.h fallback.h util.h wutil.h builtin.h io.h
|
||||
builtin_set.o: env.h expand.h common.h wgetopt.h proc.h parser.h event.h
|
||||
builtin_ulimit.o: config.h fallback.h util.h builtin.h io.h common.h
|
||||
autoload.o: config.h autoload.h common.h util.h lru.h wutil.h signal.h env.h
|
||||
autoload.o: exec.h proc.h io.h
|
||||
builtin.o: config.h signal.h fallback.h util.h wutil.h common.h builtin.h
|
||||
builtin.o: io.h function.h event.h complete.h proc.h parser.h reader.h env.h
|
||||
builtin.o: wgetopt.h sanity.h tokenizer.h wildcard.h expand.h input_common.h
|
||||
builtin.o: input.h intern.h exec.h highlight.h screen.h color.h parse_util.h
|
||||
builtin.o: autoload.h lru.h parser_keywords.h path.h history.h
|
||||
builtin.o: builtin_set.cpp builtin_commandline.cpp builtin_complete.cpp
|
||||
builtin.o: builtin_ulimit.cpp builtin_jobs.cpp builtin_printf.cpp
|
||||
builtin_commandline.o: config.h signal.h fallback.h util.h wutil.h common.h
|
||||
builtin_commandline.o: builtin.h io.h wgetopt.h reader.h complete.h proc.h
|
||||
builtin_commandline.o: parser.h event.h function.h tokenizer.h input_common.h
|
||||
builtin_commandline.o: input.h parse_util.h autoload.h lru.h
|
||||
builtin_complete.o: config.h signal.h fallback.h util.h wutil.h common.h
|
||||
builtin_complete.o: builtin.h io.h complete.h wgetopt.h parser.h proc.h
|
||||
builtin_complete.o: event.h function.h reader.h
|
||||
builtin_jobs.o: config.h fallback.h signal.h util.h wutil.h common.h
|
||||
builtin_jobs.o: builtin.h io.h proc.h parser.h event.h function.h wgetopt.h
|
||||
builtin_set.o: config.h signal.h fallback.h util.h wutil.h common.h builtin.h
|
||||
builtin_set.o: io.h env.h expand.h wgetopt.h proc.h parser.h event.h
|
||||
builtin_set.o: function.h
|
||||
builtin_test.o: config.h common.h util.h builtin.h io.h wutil.h proc.h
|
||||
builtin_test.o: signal.h
|
||||
builtin_ulimit.o: config.h fallback.h signal.h util.h builtin.h io.h common.h
|
||||
builtin_ulimit.o: wgetopt.h
|
||||
common.o: config.h fallback.h util.h wutil.h common.h expand.h proc.h io.h
|
||||
common.o: wildcard.h parser.h event.h util.c halloc.c halloc.h halloc_util.c
|
||||
common.o: fallback.c
|
||||
complete.o: config.h signal.h fallback.h util.h tokenizer.h wildcard.h proc.h
|
||||
complete.o: io.h parser.h event.h function.h complete.h builtin.h env.h
|
||||
complete.o: exec.h expand.h common.h reader.h history.h intern.h parse_util.h
|
||||
complete.o: parser_keywords.h halloc.h halloc_util.h wutil.h path.h
|
||||
env.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h env.h
|
||||
env.o: sanity.h expand.h history.h reader.h parser.h event.h env_universal.h
|
||||
env.o: env_universal_common.h input_common.h path.h halloc.h halloc_util.h
|
||||
env.o: complete.h
|
||||
builtin_printf.o: wgetopt.h
|
||||
color.o: color.h config.h common.h util.h fallback.h signal.h
|
||||
common.o: config.h fallback.h signal.h util.h wutil.h common.h expand.h
|
||||
common.o: proc.h io.h wildcard.h parser.h event.h function.h complete.h
|
||||
common.o: util.cpp fallback.cpp
|
||||
complete.o: config.h signal.h fallback.h util.h tokenizer.h common.h
|
||||
complete.o: wildcard.h expand.h proc.h io.h parser.h event.h function.h
|
||||
complete.o: complete.h builtin.h env.h exec.h reader.h history.h wutil.h
|
||||
complete.o: intern.h parse_util.h autoload.h lru.h parser_keywords.h path.h
|
||||
env.o: config.h signal.h fallback.h util.h wutil.h common.h proc.h io.h env.h
|
||||
env.o: sanity.h expand.h history.h reader.h complete.h parser.h event.h
|
||||
env.o: function.h env_universal.h env_universal_common.h input.h
|
||||
env.o: input_common.h path.h
|
||||
env_universal.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
env_universal.o: env_universal_common.h env_universal.h
|
||||
env_universal_common.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
env_universal_common.o: env_universal_common.h
|
||||
event.o: config.h signal.h fallback.h util.h wutil.h function.h proc.h io.h
|
||||
event.o: parser.h event.h common.h halloc_util.h
|
||||
exec.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
|
||||
exec.o: exec.h parser.h event.h builtin.h function.h env.h wildcard.h
|
||||
exec.o: sanity.h expand.h halloc.h halloc_util.h parse_util.h
|
||||
event.o: config.h signal.h fallback.h util.h wutil.h common.h function.h
|
||||
event.o: event.h proc.h io.h parser.h
|
||||
exec.o: config.h signal.h fallback.h util.h iothread.h postfork.h common.h
|
||||
exec.o: proc.h io.h wutil.h exec.h parser.h event.h function.h builtin.h
|
||||
exec.o: env.h wildcard.h expand.h sanity.h parse_util.h autoload.h lru.h
|
||||
expand.o: config.h signal.h fallback.h util.h common.h wutil.h env.h proc.h
|
||||
expand.o: io.h parser.h event.h expand.h wildcard.h exec.h tokenizer.h
|
||||
expand.o: complete.h parse_util.h halloc.h halloc_util.h
|
||||
fallback.o: config.h fallback.h util.h
|
||||
fish.o: config.h signal.h fallback.h util.h common.h reader.h io.h builtin.h
|
||||
fish.o: function.h complete.h wutil.h env.h sanity.h proc.h parser.h event.h
|
||||
fish.o: expand.h intern.h exec.h output.h halloc.h halloc_util.h history.h
|
||||
fish.o: path.h
|
||||
fish_indent.o: config.h fallback.h util.h common.h wutil.h halloc.h
|
||||
fish_indent.o: halloc_util.h tokenizer.h print_help.h parser_keywords.h
|
||||
expand.o: io.h parser.h event.h function.h expand.h wildcard.h exec.h
|
||||
expand.o: tokenizer.h complete.h parse_util.h autoload.h lru.h
|
||||
fallback.o: config.h fallback.h signal.h util.h
|
||||
fish.o: config.h signal.h fallback.h util.h common.h reader.h io.h complete.h
|
||||
fish.o: builtin.h function.h event.h wutil.h env.h sanity.h proc.h parser.h
|
||||
fish.o: expand.h intern.h exec.h output.h screen.h color.h history.h path.h
|
||||
fish_indent.o: config.h fallback.h signal.h util.h common.h wutil.h
|
||||
fish_indent.o: tokenizer.h print_help.h parser_keywords.h
|
||||
fish_pager.o: config.h signal.h fallback.h util.h wutil.h common.h complete.h
|
||||
fish_pager.o: output.h input_common.h env_universal.h env_universal_common.h
|
||||
fish_pager.o: halloc.h halloc_util.h print_help.h
|
||||
fish_pager.o: output.h screen.h color.h input_common.h env_universal.h
|
||||
fish_pager.o: env_universal_common.h print_help.h
|
||||
fish_tests.o: config.h signal.h fallback.h util.h common.h proc.h io.h
|
||||
fish_tests.o: reader.h builtin.h function.h complete.h wutil.h env.h expand.h
|
||||
fish_tests.o: parser.h event.h tokenizer.h output.h exec.h path.h halloc.h
|
||||
fish_tests.o: halloc_util.h
|
||||
fish_tests.o: reader.h complete.h builtin.h function.h event.h autoload.h
|
||||
fish_tests.o: lru.h wutil.h env.h expand.h parser.h tokenizer.h output.h
|
||||
fish_tests.o: screen.h color.h exec.h path.h history.h highlight.h iothread.h
|
||||
fish_tests.o: postfork.h
|
||||
fishd.o: config.h signal.h fallback.h util.h common.h wutil.h
|
||||
fishd.o: env_universal_common.h halloc.h halloc_util.h path.h print_help.h
|
||||
function.o: config.h signal.h wutil.h fallback.h util.h function.h proc.h
|
||||
function.o: io.h parser.h event.h common.h intern.h reader.h parse_util.h
|
||||
function.o: parser_keywords.h env.h expand.h halloc.h halloc_util.h
|
||||
halloc.o: config.h fallback.h util.h common.h halloc.h
|
||||
halloc_util.o: config.h fallback.h util.h common.h halloc.h
|
||||
highlight.o: config.h signal.h fallback.h util.h wutil.h highlight.h
|
||||
highlight.o: tokenizer.h proc.h io.h parser.h event.h parse_util.h
|
||||
highlight.o: parser_keywords.h builtin.h function.h env.h expand.h sanity.h
|
||||
highlight.o: common.h complete.h output.h halloc.h halloc_util.h wildcard.h
|
||||
highlight.o: path.h
|
||||
history.o: config.h fallback.h util.h wutil.h history.h common.h halloc.h
|
||||
history.o: halloc_util.h intern.h path.h signal.h
|
||||
input.o: config.h signal.h fallback.h util.h wutil.h reader.h io.h proc.h
|
||||
input.o: common.h sanity.h input_common.h input.h parser.h event.h env.h
|
||||
input.o: expand.h output.h intern.h halloc.h halloc_util.h
|
||||
input_common.o: config.h fallback.h util.h common.h wutil.h input_common.h
|
||||
input_common.o: env_universal.h env_universal_common.h
|
||||
intern.o: config.h fallback.h util.h wutil.h common.h intern.h
|
||||
io.o: config.h fallback.h util.h wutil.h exec.h proc.h io.h common.h halloc.h
|
||||
key_reader.o: config.h fallback.h input_common.h
|
||||
kill.o: config.h signal.h fallback.h util.h wutil.h kill.h proc.h io.h
|
||||
kill.o: sanity.h common.h env.h exec.h halloc.h path.h
|
||||
mimedb.o: config.h xdgmime.h fallback.h util.h print_help.h
|
||||
output.o: config.h signal.h fallback.h util.h wutil.h expand.h common.h
|
||||
output.o: output.h halloc_util.h highlight.h
|
||||
parse_util.o: config.h fallback.h util.h wutil.h common.h tokenizer.h
|
||||
parse_util.o: parse_util.h expand.h intern.h exec.h proc.h io.h env.h
|
||||
parse_util.o: signal.h wildcard.h halloc_util.h
|
||||
fishd.o: env_universal_common.h path.h env.h print_help.h
|
||||
function.o: config.h signal.h wutil.h common.h util.h fallback.h function.h
|
||||
function.o: event.h proc.h io.h parser.h intern.h reader.h complete.h
|
||||
function.o: parse_util.h autoload.h lru.h parser_keywords.h env.h expand.h
|
||||
highlight.o: config.h signal.h fallback.h util.h wutil.h common.h highlight.h
|
||||
highlight.o: env.h screen.h color.h tokenizer.h proc.h io.h parser.h event.h
|
||||
highlight.o: function.h parse_util.h autoload.h lru.h parser_keywords.h
|
||||
highlight.o: builtin.h expand.h sanity.h complete.h output.h wildcard.h
|
||||
highlight.o: path.h history.h
|
||||
history.o: config.h fallback.h signal.h util.h sanity.h tokenizer.h common.h
|
||||
history.o: wutil.h history.h intern.h path.h env.h autoload.h lru.h
|
||||
history.o: iothread.h
|
||||
input.o: config.h signal.h fallback.h util.h wutil.h common.h reader.h io.h
|
||||
input.o: complete.h proc.h sanity.h input_common.h input.h parser.h event.h
|
||||
input.o: function.h env.h expand.h output.h screen.h color.h intern.h
|
||||
input_common.o: config.h fallback.h signal.h util.h common.h wutil.h
|
||||
input_common.o: input_common.h env_universal.h env_universal_common.h
|
||||
input_common.o: iothread.h
|
||||
intern.o: config.h fallback.h signal.h util.h wutil.h common.h intern.h
|
||||
io.o: config.h fallback.h signal.h util.h wutil.h common.h exec.h proc.h io.h
|
||||
iothread.o: config.h iothread.h common.h util.h signal.h
|
||||
key_reader.o: config.h common.h util.h fallback.h signal.h input_common.h
|
||||
kill.o: config.h signal.h fallback.h util.h wutil.h common.h kill.h proc.h
|
||||
kill.o: io.h sanity.h env.h exec.h path.h
|
||||
mimedb.o: config.h xdgmime.h fallback.h signal.h util.h print_help.h
|
||||
output.o: config.h signal.h fallback.h util.h wutil.h common.h expand.h
|
||||
output.o: output.h screen.h color.h highlight.h env.h
|
||||
parse_util.o: config.h fallback.h signal.h util.h wutil.h common.h
|
||||
parse_util.o: tokenizer.h parse_util.h autoload.h lru.h expand.h intern.h
|
||||
parse_util.o: exec.h proc.h io.h env.h wildcard.h
|
||||
parser.o: config.h signal.h fallback.h util.h common.h wutil.h proc.h io.h
|
||||
parser.o: parser.h event.h parser_keywords.h tokenizer.h exec.h wildcard.h
|
||||
parser.o: function.h builtin.h env.h expand.h reader.h sanity.h
|
||||
parser.o: parser.h event.h function.h parser_keywords.h tokenizer.h exec.h
|
||||
parser.o: wildcard.h expand.h builtin.h env.h reader.h complete.h sanity.h
|
||||
parser.o: env_universal.h env_universal_common.h intern.h parse_util.h
|
||||
parser.o: halloc.h halloc_util.h path.h
|
||||
parser_keywords.o: config.h fallback.h common.h util.h parser_keywords.h
|
||||
path.o: config.h fallback.h util.h common.h env.h wutil.h halloc.h
|
||||
path.o: halloc_util.h path.h expand.h
|
||||
parser.o: autoload.h lru.h path.h
|
||||
parser_keywords.o: config.h fallback.h signal.h common.h util.h
|
||||
parser_keywords.o: parser_keywords.h
|
||||
path.o: config.h fallback.h signal.h util.h common.h env.h wutil.h path.h
|
||||
path.o: expand.h
|
||||
postfork.o: signal.h postfork.h config.h common.h util.h proc.h io.h wutil.h
|
||||
postfork.o: iothread.h exec.h
|
||||
print_help.o: print_help.h
|
||||
proc.o: config.h signal.h fallback.h util.h wutil.h proc.h io.h common.h
|
||||
proc.o: reader.h sanity.h env.h parser.h event.h halloc.h halloc_util.h
|
||||
proc.o: output.h
|
||||
reader.o: config.h signal.h fallback.h util.h wutil.h highlight.h reader.h
|
||||
reader.o: io.h proc.h parser.h event.h complete.h history.h common.h sanity.h
|
||||
reader.o: env.h exec.h expand.h tokenizer.h kill.h input_common.h input.h
|
||||
reader.o: function.h output.h screen.h halloc.h halloc_util.h parse_util.h
|
||||
proc.o: config.h signal.h fallback.h util.h wutil.h common.h proc.h io.h
|
||||
proc.o: reader.h complete.h sanity.h env.h parser.h event.h function.h
|
||||
proc.o: output.h screen.h color.h
|
||||
reader.o: config.h signal.h fallback.h util.h wutil.h common.h highlight.h
|
||||
reader.o: env.h screen.h color.h reader.h io.h complete.h proc.h parser.h
|
||||
reader.o: event.h function.h history.h sanity.h exec.h expand.h tokenizer.h
|
||||
reader.o: kill.h input_common.h input.h output.h iothread.h intern.h path.h
|
||||
reader.o: parse_util.h autoload.h lru.h
|
||||
sanity.o: config.h signal.h fallback.h util.h common.h sanity.h proc.h io.h
|
||||
sanity.o: history.h reader.h kill.h wutil.h
|
||||
screen.o: config.h fallback.h common.h util.h wutil.h output.h highlight.h
|
||||
screen.o: screen.h env.h
|
||||
set_color.o: config.h fallback.h print_help.h
|
||||
sanity.o: history.h wutil.h reader.h complete.h kill.h
|
||||
screen.o: config.h fallback.h signal.h common.h util.h wutil.h output.h
|
||||
screen.o: screen.h color.h highlight.h env.h
|
||||
signal.o: config.h signal.h common.h util.h fallback.h wutil.h event.h
|
||||
signal.o: reader.h io.h proc.h
|
||||
tokenizer.o: config.h fallback.h util.h wutil.h tokenizer.h common.h
|
||||
util.o: config.h fallback.h util.h common.h wutil.h
|
||||
wgetopt.o: config.h wgetopt.h wutil.h fallback.h
|
||||
wildcard.o: config.h fallback.h util.h wutil.h complete.h common.h wildcard.h
|
||||
wildcard.o: reader.h io.h expand.h exec.h proc.h halloc_util.h
|
||||
wutil.o: config.h fallback.h util.h common.h wutil.h halloc.h halloc_util.h
|
||||
signal.o: reader.h io.h complete.h proc.h
|
||||
tokenizer.o: config.h fallback.h signal.h util.h wutil.h common.h tokenizer.h
|
||||
util.o: config.h fallback.h signal.h util.h common.h wutil.h
|
||||
wgetopt.o: config.h wgetopt.h wutil.h common.h util.h fallback.h signal.h
|
||||
wildcard.o: config.h fallback.h signal.h util.h wutil.h common.h complete.h
|
||||
wildcard.o: wildcard.h expand.h reader.h io.h exec.h proc.h
|
||||
wutil.o: config.h fallback.h signal.h util.h common.h wutil.h
|
||||
xdgmime.o: xdgmime.h xdgmimeint.h xdgmimeglob.h xdgmimemagic.h xdgmimealias.h
|
||||
xdgmime.o: xdgmimeparent.h
|
||||
xdgmimealias.o: xdgmimealias.h xdgmime.h xdgmimeint.h
|
||||
|
||||
15
README
15
README
@@ -1,15 +0,0 @@
|
||||
How to find documentation for fish
|
||||
==================================
|
||||
|
||||
The fish documentation is distributed in an intermediate format. To
|
||||
view it, you have to type:
|
||||
|
||||
% make user_doc
|
||||
|
||||
Which will create the directory user_doc, containing html
|
||||
documentation for fish. If you build and install fish, the
|
||||
documentation will be available through the 'help' builtin.
|
||||
|
||||
After installation, you can start fish by typing fish in the
|
||||
terminal. After fish has started, try using the help command for more
|
||||
information.
|
||||
71
README.md
Normal file
71
README.md
Normal file
@@ -0,0 +1,71 @@
|
||||
[fish](http://ridiculousfish.com/shell/) - the friendly interactive shell
|
||||
================================================
|
||||
|
||||
fish is a smart and user-friendly command line shell for OS X, Linux, and the rest of the family. fish includes features like syntax highlighting, autosuggest-as-you-type, and fancy tab completions that just work, with no configuration required.
|
||||
|
||||
For more on fish's design philosophy, see the [design document](http://ridiculousfish.com/shell/user_doc/html/design.html).
|
||||
|
||||
## Quick Start
|
||||
|
||||
fish generally works like other shells, like bash or zsh. A few important differences are documented at <http://ridiculousfish.com/shell/faq.html>
|
||||
|
||||
Detailed user documentation is available by running `help` within fish, and also at <http://ridiculousfish.com/shell/user_doc/html/>
|
||||
|
||||
## Building
|
||||
|
||||
fish is written in a sane subset of C++98, with a few components from C++TR1. It builds successfully with g++ 4.2 or later, and with clang. It also will build as C++11.
|
||||
|
||||
fish can be built using autotools or Xcode.
|
||||
|
||||
### Autotools Build
|
||||
|
||||
autoconf
|
||||
./configure
|
||||
make [gmake on BSD]
|
||||
sudo make install
|
||||
|
||||
### Xcode Development Build
|
||||
|
||||
* Build the `base` target in Xcode
|
||||
* Run the fish executable, for example, in `DerivedData/fish/Build/Products/Debug/base/bin/fish`
|
||||
|
||||
### Xcode Build and Install
|
||||
|
||||
xcodebuild install
|
||||
sudo ditto /tmp/fish.dst /
|
||||
|
||||
## Help, it didn't build!
|
||||
|
||||
If fish reports that it could not find curses, try installing a curses development package and build again.
|
||||
|
||||
On Debian or Ubuntu you want:
|
||||
|
||||
sudo apt-get install libncurses5-dev libncursesw5-dev
|
||||
|
||||
on RedHat, CentOS, or Amazon EC2:
|
||||
|
||||
sudo yum install ncurses-devel
|
||||
|
||||
## Packages for Linux
|
||||
|
||||
Nightly builds for several Linux distros can be downloaded from <http://download.opensuse.org/repositories/home:/siteshwar/>
|
||||
|
||||
## Switching to fish
|
||||
|
||||
If you wish to use fish as your default shell, use the following command:
|
||||
|
||||
chsh -s /usr/local/bin/fish
|
||||
|
||||
chsh will prompt you for your password, and change your default shell.
|
||||
|
||||
To switch your default shell back, you can run:
|
||||
|
||||
chsh -s /bin/bash
|
||||
|
||||
Substitute /bin/bash with /bin/tcsh or /bin/zsh as appropriate.
|
||||
|
||||
## Contact Us
|
||||
|
||||
Questions, comments, rants and raves can be posted to the official fish mailing list at <https://lists.sourceforge.net/lists/listinfo/fish-users> or join us on our IRC channel #fish at irc.oftc.net
|
||||
|
||||
Found a bug? Have an awesome idea? Please open an issue on this github page.
|
||||
105
STYLEGUIDE.md
Normal file
105
STYLEGUIDE.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# Style guide
|
||||
|
||||
This is style guide for fish contributors. You should use it for any new code
|
||||
that you would add to this project and try to format existing code to use this
|
||||
style.
|
||||
|
||||
## Formatting
|
||||
|
||||
1. fish uses the Allman/BSD style of indentation.
|
||||
2. Indent with spaces, not tabs.
|
||||
3. Use 4 spaces per indent (unless needed like `Makefile`).
|
||||
4. Opening curly bracket is on the following line:
|
||||
|
||||
// ✔:
|
||||
struct name
|
||||
{
|
||||
// code
|
||||
};
|
||||
|
||||
void func()
|
||||
{
|
||||
// code
|
||||
}
|
||||
|
||||
if (...)
|
||||
{
|
||||
// code
|
||||
}
|
||||
|
||||
// ✗:
|
||||
void func() {
|
||||
// code
|
||||
}
|
||||
|
||||
5. Put space after `if`, `while` and `for` before conditions.
|
||||
|
||||
// ✔:
|
||||
if () {}
|
||||
|
||||
// ✗:
|
||||
if() {}
|
||||
|
||||
6. Put spaces before and after operators excluding increment and decrement;
|
||||
|
||||
// ✔:
|
||||
int a = 1 + 2 * 3;
|
||||
a++;
|
||||
|
||||
// ✗:
|
||||
int a=1+2*3;
|
||||
a ++;
|
||||
|
||||
7. Never put spaces between function name and parameters list.
|
||||
|
||||
// ✔:
|
||||
func(args);
|
||||
|
||||
// ✗:
|
||||
func (args);
|
||||
|
||||
8. Never put spaces after `(` and before `)`.
|
||||
9. Always put space after comma and semicolon.
|
||||
|
||||
// ✔:
|
||||
func(arg1, arg2);
|
||||
|
||||
for (int i = 0; i < LENGTH; i++) {}
|
||||
|
||||
// ✗:
|
||||
func(arg1,arg2);
|
||||
|
||||
for (int i = 0;i<LENGTH;i++) {}
|
||||
|
||||
## Documentation
|
||||
|
||||
Document your code using [Doxygen][dox].
|
||||
|
||||
1. Documentation comment should use double star notation or tripple slash:
|
||||
|
||||
// ✔:
|
||||
/// Some var
|
||||
int var;
|
||||
|
||||
/**
|
||||
* Some func
|
||||
*/
|
||||
void func();
|
||||
|
||||
2. Use slash as tag mark:
|
||||
|
||||
// ✔:
|
||||
|
||||
/**
|
||||
* \param a an integer argument.
|
||||
* \param s a constant character pointer.
|
||||
* \return The results
|
||||
*/
|
||||
int foo(int a, const char *s);
|
||||
|
||||
## Naming
|
||||
|
||||
All names in code should be `small_snake_case`. No Hungarian notation is used.
|
||||
Classes and structs names should be followed by `_t`.
|
||||
|
||||
[dox]: http://www.stack.nl/~dimitri/doxygen/ "Doxygen homepage"
|
||||
376
autoload.cpp
Normal file
376
autoload.cpp
Normal file
@@ -0,0 +1,376 @@
|
||||
/** \file autoload.cpp
|
||||
|
||||
The classes responsible for autoloading functions and completions.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "autoload.h"
|
||||
#include "wutil.h"
|
||||
#include "common.h"
|
||||
#include "signal.h"
|
||||
#include "env.h"
|
||||
#include "exec.h"
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* The time before we'll recheck an autoloaded file */
|
||||
static const int kAutoloadStalenessInterval = 15;
|
||||
|
||||
file_access_attempt_t access_file(const wcstring &path, int mode)
|
||||
{
|
||||
//printf("Touch %ls\n", path.c_str());
|
||||
file_access_attempt_t result = {0};
|
||||
struct stat statbuf;
|
||||
if (wstat(path, &statbuf))
|
||||
{
|
||||
result.error = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.mod_time = statbuf.st_mtime;
|
||||
if (waccess(path, mode))
|
||||
{
|
||||
result.error = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.accessible = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Note that we record the last checked time after the call, on the assumption that in a slow filesystem, the lag comes before the kernel check, not after.
|
||||
result.stale = false;
|
||||
result.last_checked = time(NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t * const scripts, size_t script_count) :
|
||||
lock(),
|
||||
env_var_name(env_var_name_var),
|
||||
builtin_scripts(scripts),
|
||||
builtin_script_count(script_count),
|
||||
last_path(),
|
||||
is_loading_set()
|
||||
{
|
||||
pthread_mutex_init(&lock, NULL);
|
||||
}
|
||||
|
||||
autoload_t::~autoload_t()
|
||||
{
|
||||
pthread_mutex_destroy(&lock);
|
||||
}
|
||||
|
||||
void autoload_t::node_was_evicted(autoload_function_t *node)
|
||||
{
|
||||
// This should only ever happen on the main thread
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
|
||||
// Tell ourselves that the command was removed if it was loaded
|
||||
if (! node->is_loaded)
|
||||
this->command_removed(node->key);
|
||||
delete node;
|
||||
}
|
||||
|
||||
int autoload_t::unload(const wcstring &cmd)
|
||||
{
|
||||
return this->evict_node(cmd);
|
||||
}
|
||||
|
||||
int autoload_t::load(const wcstring &cmd, bool reload)
|
||||
{
|
||||
int res;
|
||||
CHECK_BLOCK(0);
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
|
||||
env_var_t path_var = env_get_string(env_var_name);
|
||||
|
||||
/*
|
||||
Do we know where to look?
|
||||
*/
|
||||
if (path_var.empty())
|
||||
return 0;
|
||||
|
||||
/* Check if the lookup path has changed. If so, drop all loaded files. path_var may only be inspected on the main thread. */
|
||||
if (path_var != this->last_path)
|
||||
{
|
||||
this->last_path = path_var;
|
||||
scoped_lock locker(lock);
|
||||
this->evict_all_nodes();
|
||||
}
|
||||
|
||||
/** Warn and fail on infinite recursion. It's OK to do this because this function is only called on the main thread. */
|
||||
if (this->is_loading(cmd))
|
||||
{
|
||||
debug(0,
|
||||
_(L"Could not autoload item '%ls', it is already being autoloaded. "
|
||||
L"This is a circular dependency in the autoloading scripts, please remove it."),
|
||||
cmd.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Mark that we're loading this */
|
||||
is_loading_set.insert(cmd);
|
||||
|
||||
/* Get the list of paths from which we will try to load */
|
||||
std::vector<wcstring> path_list;
|
||||
tokenize_variable_array(path_var, path_list);
|
||||
|
||||
/* Try loading it */
|
||||
res = this->locate_file_and_maybe_load_it(cmd, true, reload, path_list);
|
||||
|
||||
/* Clean up */
|
||||
bool erased = !! is_loading_set.erase(cmd);
|
||||
assert(erased);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool autoload_t::can_load(const wcstring &cmd, const env_vars_snapshot_t &vars)
|
||||
{
|
||||
const env_var_t path_var = vars.get(env_var_name);
|
||||
if (path_var.missing_or_empty())
|
||||
return false;
|
||||
|
||||
std::vector<wcstring> path_list;
|
||||
tokenize_variable_array(path_var, path_list);
|
||||
return this->locate_file_and_maybe_load_it(cmd, false, false, path_list);
|
||||
}
|
||||
|
||||
static bool script_name_precedes_script_name(const builtin_script_t &script1, const builtin_script_t &script2)
|
||||
{
|
||||
return wcscmp(script1.name, script2.name) < 0;
|
||||
}
|
||||
|
||||
void autoload_t::unload_all(void)
|
||||
{
|
||||
scoped_lock locker(lock);
|
||||
this->evict_all_nodes();
|
||||
}
|
||||
|
||||
/** Check whether the given command is loaded. */
|
||||
bool autoload_t::has_tried_loading(const wcstring &cmd)
|
||||
{
|
||||
scoped_lock locker(lock);
|
||||
autoload_function_t * func = this->get_node(cmd);
|
||||
return func != NULL;
|
||||
}
|
||||
|
||||
static bool is_stale(const autoload_function_t *func)
|
||||
{
|
||||
/** Return whether this function is stale. Internalized functions can never be stale. */
|
||||
return ! func->is_internalized && time(NULL) - func->access.last_checked > kAutoloadStalenessInterval;
|
||||
}
|
||||
|
||||
autoload_function_t *autoload_t::get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction)
|
||||
{
|
||||
ASSERT_IS_LOCKED(lock);
|
||||
autoload_function_t *func = this->get_node(cmd);
|
||||
if (! func)
|
||||
{
|
||||
func = new autoload_function_t(cmd);
|
||||
if (allow_eviction)
|
||||
{
|
||||
this->add_node(func);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->add_node_without_eviction(func);
|
||||
}
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
This internal helper function does all the real work. By using two
|
||||
functions, the internal function can return on various places in
|
||||
the code, and the caller can take care of various cleanup work.
|
||||
|
||||
cmd: the command name ('grep')
|
||||
really_load: whether to actually parse it as a function, or just check it it exists
|
||||
reload: whether to reload it if it's already loaded
|
||||
path_list: the set of paths to check
|
||||
|
||||
Result: if really_load is true, returns whether the function was loaded. Otherwise returns whether the function existed.
|
||||
*/
|
||||
bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list)
|
||||
{
|
||||
/* Note that we are NOT locked in this function! */
|
||||
size_t i;
|
||||
bool reloaded = 0;
|
||||
|
||||
/* Try using a cached function. If we really want the function to be loaded, require that it be really loaded. If we're not reloading, allow stale functions. */
|
||||
{
|
||||
bool allow_stale_functions = ! reload;
|
||||
|
||||
/* Take a lock */
|
||||
scoped_lock locker(lock);
|
||||
|
||||
/* Get the function */
|
||||
autoload_function_t * func = this->get_node(cmd);
|
||||
|
||||
/* Determine if we can use this cached function */
|
||||
bool use_cached;
|
||||
if (! func)
|
||||
{
|
||||
/* Can't use a function that doesn't exist */
|
||||
use_cached = false;
|
||||
}
|
||||
else if (really_load && ! func->is_placeholder && ! func->is_loaded)
|
||||
{
|
||||
/* Can't use an unloaded function */
|
||||
use_cached = false;
|
||||
}
|
||||
else if (! allow_stale_functions && is_stale(func))
|
||||
{
|
||||
/* Can't use a stale function */
|
||||
use_cached = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* I guess we can use it */
|
||||
use_cached = true;
|
||||
}
|
||||
|
||||
/* If we can use this function, return whether we were able to access it */
|
||||
if (use_cached)
|
||||
{
|
||||
return func->is_internalized || func->access.accessible;
|
||||
}
|
||||
}
|
||||
/* The source of the script will end up here */
|
||||
wcstring script_source;
|
||||
bool has_script_source = false;
|
||||
|
||||
/* Whether we found an accessible file */
|
||||
bool found_file = false;
|
||||
|
||||
/* Look for built-in scripts via a binary search */
|
||||
const builtin_script_t *matching_builtin_script = NULL;
|
||||
if (builtin_script_count > 0)
|
||||
{
|
||||
const builtin_script_t test_script = {cmd.c_str(), NULL};
|
||||
const builtin_script_t *array_end = builtin_scripts + builtin_script_count;
|
||||
const builtin_script_t *found = std::lower_bound(builtin_scripts, array_end, test_script, script_name_precedes_script_name);
|
||||
if (found != array_end && ! wcscmp(found->name, test_script.name))
|
||||
{
|
||||
/* We found it */
|
||||
matching_builtin_script = found;
|
||||
}
|
||||
}
|
||||
if (matching_builtin_script)
|
||||
{
|
||||
has_script_source = true;
|
||||
script_source = str2wcstring(matching_builtin_script->def);
|
||||
|
||||
/* Make a node representing this function */
|
||||
scoped_lock locker(lock);
|
||||
autoload_function_t *func = this->get_autoloaded_function_with_creation(cmd, really_load);
|
||||
|
||||
/* This function is internalized */
|
||||
func->is_internalized = true;
|
||||
|
||||
/* It's a fiction to say the script is loaded at this point, but we're definitely going to load it down below. */
|
||||
if (really_load) func->is_loaded = true;
|
||||
}
|
||||
|
||||
if (! has_script_source)
|
||||
{
|
||||
/* Iterate over path searching for suitable completion files */
|
||||
for (i=0; i<path_list.size(); i++)
|
||||
{
|
||||
wcstring next = path_list.at(i);
|
||||
wcstring path = next + L"/" + cmd + L".fish";
|
||||
|
||||
const file_access_attempt_t access = access_file(path, R_OK);
|
||||
if (access.accessible)
|
||||
{
|
||||
/* Found it! */
|
||||
found_file = true;
|
||||
|
||||
/* Now we're actually going to take the lock. */
|
||||
scoped_lock locker(lock);
|
||||
autoload_function_t *func = this->get_node(cmd);
|
||||
|
||||
/* Generate the source if we need to load it */
|
||||
bool need_to_load_function = really_load && (func == NULL || func->access.mod_time != access.mod_time || ! func->is_loaded);
|
||||
if (need_to_load_function)
|
||||
{
|
||||
|
||||
/* Generate the script source */
|
||||
wcstring esc = escape_string(path, 1);
|
||||
script_source = L". " + esc;
|
||||
has_script_source = true;
|
||||
|
||||
/* Remove any loaded command because we are going to reload it. Note that this will deadlock if command_removed calls back into us. */
|
||||
if (func && func->is_loaded)
|
||||
{
|
||||
command_removed(cmd);
|
||||
func->is_placeholder = false;
|
||||
}
|
||||
|
||||
/* Mark that we're reloading it */
|
||||
reloaded = true;
|
||||
}
|
||||
|
||||
/* Create the function if we haven't yet. This does not load it. Do not trigger eviction unless we are actually loading, because we don't want to evict off of the main thread. */
|
||||
if (! func)
|
||||
{
|
||||
func = get_autoloaded_function_with_creation(cmd, really_load);
|
||||
}
|
||||
|
||||
/* It's a fiction to say the script is loaded at this point, but we're definitely going to load it down below. */
|
||||
if (need_to_load_function) func->is_loaded = true;
|
||||
|
||||
/* Unconditionally record our access time */
|
||||
func->access = access;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
If no file or builtin script was found we insert a placeholder function.
|
||||
Later we only research if the current time is at least five seconds later.
|
||||
This way, the files won't be searched over and over again.
|
||||
*/
|
||||
if (! found_file && ! has_script_source)
|
||||
{
|
||||
scoped_lock locker(lock);
|
||||
/* Generate a placeholder */
|
||||
autoload_function_t *func = this->get_node(cmd);
|
||||
if (! func)
|
||||
{
|
||||
func = new autoload_function_t(cmd);
|
||||
func->is_placeholder = true;
|
||||
if (really_load)
|
||||
{
|
||||
this->add_node(func);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->add_node_without_eviction(func);
|
||||
}
|
||||
}
|
||||
func->access.last_checked = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we have a script, either built-in or a file source, then run it */
|
||||
if (really_load && has_script_source)
|
||||
{
|
||||
if (exec_subshell(script_source, false /* do not apply exit status */) == -1)
|
||||
{
|
||||
/* Do nothing on failure */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (really_load)
|
||||
{
|
||||
return reloaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
return found_file || has_script_source;
|
||||
}
|
||||
}
|
||||
138
autoload.h
Normal file
138
autoload.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/** \file autoload.h
|
||||
|
||||
The classes responsible for autoloading functions and completions.
|
||||
*/
|
||||
|
||||
#ifndef FISH_AUTOLOAD_H
|
||||
#define FISH_AUTOLOAD_H
|
||||
|
||||
#include <wchar.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include "common.h"
|
||||
#include "lru.h"
|
||||
|
||||
/** A struct responsible for recording an attempt to access a file. */
|
||||
struct file_access_attempt_t
|
||||
{
|
||||
time_t mod_time; /** The modification time of the file */
|
||||
time_t last_checked; /** When we last checked the file */
|
||||
bool accessible; /** Whether we believe we could access this file */
|
||||
bool stale; /** Whether the access attempt is stale */
|
||||
int error; /** If we could not access the file, the error code */
|
||||
};
|
||||
|
||||
file_access_attempt_t access_file(const wcstring &path, int mode);
|
||||
|
||||
struct autoload_function_t : public lru_node_t
|
||||
{
|
||||
autoload_function_t(const wcstring &key) : lru_node_t(key), access(), is_loaded(false), is_placeholder(false), is_internalized(false) { }
|
||||
file_access_attempt_t access; /** The last access attempt */
|
||||
bool is_loaded; /** Whether we have actually loaded this function */
|
||||
bool is_placeholder; /** Whether we are a placeholder that stands in for "no such function". If this is true, then is_loaded must be false. */
|
||||
bool is_internalized; /** Whether this function came from a builtin "internalized" script */
|
||||
};
|
||||
|
||||
struct builtin_script_t
|
||||
{
|
||||
const wchar_t *name;
|
||||
const char *def;
|
||||
};
|
||||
|
||||
struct builtin_script_t;
|
||||
class env_vars_snapshot_t;
|
||||
|
||||
/**
|
||||
A class that represents a path from which we can autoload, and the autoloaded contents.
|
||||
*/
|
||||
class autoload_t : private lru_cache_t<autoload_function_t>
|
||||
{
|
||||
private:
|
||||
|
||||
/** Lock for thread safety */
|
||||
pthread_mutex_t lock;
|
||||
|
||||
/** The environment variable name */
|
||||
const wcstring env_var_name;
|
||||
|
||||
/** Builtin script array */
|
||||
const struct builtin_script_t *const builtin_scripts;
|
||||
|
||||
/** Builtin script count */
|
||||
const size_t builtin_script_count;
|
||||
|
||||
/** The path from which we most recently autoloaded */
|
||||
wcstring last_path;
|
||||
|
||||
/**
|
||||
A table containing all the files that are currently being
|
||||
loaded. This is here to help prevent recursion.
|
||||
*/
|
||||
std::set<wcstring> is_loading_set;
|
||||
|
||||
bool is_loading(const wcstring &name) const
|
||||
{
|
||||
return is_loading_set.find(name) != is_loading_set.end();
|
||||
}
|
||||
|
||||
void remove_all_functions(void)
|
||||
{
|
||||
this->evict_all_nodes();
|
||||
}
|
||||
|
||||
bool locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list);
|
||||
|
||||
virtual void node_was_evicted(autoload_function_t *node);
|
||||
|
||||
autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction);
|
||||
|
||||
protected:
|
||||
/** Overridable callback for when a command is removed */
|
||||
virtual void command_removed(const wcstring &cmd) { }
|
||||
|
||||
public:
|
||||
|
||||
/** Create an autoload_t for the given environment variable name */
|
||||
autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts, size_t script_count);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~autoload_t();
|
||||
|
||||
/**
|
||||
Autoload the specified file, if it exists in the specified path. Do
|
||||
not load it multiple times unless its timestamp changes or
|
||||
parse_util_unload is called.
|
||||
|
||||
Autoloading one file may unload another.
|
||||
|
||||
\param cmd the filename to search for. The suffix '.fish' is always added to this name
|
||||
\param on_unload a callback function to run if a suitable file is found, which has not already been run. unload will also be called for old files which are unloaded.
|
||||
\param reload wheter to recheck file timestamps on already loaded files
|
||||
*/
|
||||
int load(const wcstring &cmd, bool reload);
|
||||
|
||||
/** Check whether we have tried loading the given command. Does not do any I/O. */
|
||||
bool has_tried_loading(const wcstring &cmd);
|
||||
|
||||
/**
|
||||
Tell the autoloader that the specified file, in the specified path,
|
||||
is no longer loaded.
|
||||
|
||||
\param cmd the filename to search for. The suffix '.fish' is always added to this name
|
||||
\param on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.
|
||||
\return non-zero if the file was removed, zero if the file had not yet been loaded
|
||||
*/
|
||||
int unload(const wcstring &cmd);
|
||||
|
||||
/**
|
||||
Unloads all files.
|
||||
*/
|
||||
void unload_all();
|
||||
|
||||
/** Check whether the given command could be loaded, but do not load it. */
|
||||
bool can_load(const wcstring &cmd, const env_vars_snapshot_t &vars);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
136
build_tools/build_documentation.sh
Executable file
136
build_tools/build_documentation.sh
Executable file
@@ -0,0 +1,136 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script is run as part of the build process
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
# Use fish's defaults
|
||||
DOXYFILE=Doxyfile.help
|
||||
INPUTDIR=doc_src
|
||||
OUTPUTDIR=share
|
||||
echo "Using defaults: $0 ${DOXYFILE} ${INPUTDIR} ${OUTPUTDIR}"
|
||||
elif test $# -eq 3
|
||||
then
|
||||
DOXYFILE="$1"
|
||||
INPUTDIR="$2"
|
||||
OUTPUTDIR="$3"
|
||||
else
|
||||
echo "Usage: $0 doxygen_file input_directory output_directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine which man pages we don't want to generate.
|
||||
# Don't make a test man page. fish's test is conforming, so the system man pages
|
||||
# are applicable and generally better.
|
||||
# on OS X, don't make a man page for open, since we defeat fish's open function on OS X.
|
||||
CONDEMNED_PAGES=test.1
|
||||
if test `uname` = 'Darwin'; then
|
||||
CONDEMNED_PAGES="$CONDEMNED_PAGES open.1"
|
||||
fi
|
||||
|
||||
# Helper function to turn a relative path into an absolute path
|
||||
resolve_path()
|
||||
{
|
||||
D=`command dirname "$1"`
|
||||
B=`command basename "$1"`
|
||||
echo "`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
|
||||
}
|
||||
|
||||
# Expand relative paths
|
||||
DOXYFILE=`resolve_path "$DOXYFILE"`
|
||||
INPUTDIR=`resolve_path "$INPUTDIR"`
|
||||
OUTPUTDIR=`resolve_path "$OUTPUTDIR"`
|
||||
|
||||
echo " doxygen file: $DOXYFILE"
|
||||
echo " input directory: $INPUTDIR"
|
||||
echo " output directory: $OUTPUTDIR"
|
||||
echo " skipping: $CONDEMNED_PAGES"
|
||||
|
||||
# Make sure INPUTDIR is found
|
||||
if test ! -d "$INPUTDIR"; then
|
||||
echo >&2 "Could not find input directory '${INPUTDIR}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure doxygen is found
|
||||
DOXYGENPATH=`command -v doxygen`
|
||||
if test -z "$DOXYGENPATH" ; then
|
||||
for i in /usr/local/bin/doxygen /opt/bin/doxygen /Applications/Doxygen.app/Contents/Resources/doxygen ~/Applications/Doxygen.app/Contents/Resources/doxygen ; do
|
||||
if test -f "$i"; then
|
||||
DOXYGENPATH="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if test -z "$DOXYGENPATH"; then
|
||||
echo >&2 "doxygen is not installed, so documentation will not be built."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Determine where our output should go
|
||||
if ! mkdir -p "${OUTPUTDIR}" ; then
|
||||
echo "Could not create output directory '${OUTPUTDIR}'"
|
||||
fi
|
||||
|
||||
# Make a temporary directory
|
||||
TMPLOC=`mktemp -d -t fish_doc_build_XXXXXX` || { echo >&2 "Could not build documentation because mktemp failed"; exit 1; }
|
||||
|
||||
# Copy stuff to the temp directory
|
||||
for i in "$INPUTDIR"/*.txt; do
|
||||
INPUTFILE=$TMPLOC/`basename $i .txt`.doxygen
|
||||
echo "/** \page" `basename $i .txt` > $INPUTFILE
|
||||
cat $i >>$INPUTFILE
|
||||
echo "*/" >>$INPUTFILE
|
||||
done
|
||||
|
||||
# Make some extra stuff to pass to doxygen
|
||||
# Input is kept as . because we cd to the input directory beforehand
|
||||
# This prevents doxygen from generating "documentation" for intermediate directories
|
||||
DOXYPARAMS=$(cat <<EOF
|
||||
PROJECT_NUMBER=2.0.0
|
||||
INPUT=.
|
||||
OUTPUT_DIRECTORY=$OUTPUTDIR
|
||||
QUIET=YES
|
||||
EOF
|
||||
);
|
||||
|
||||
# echo "$DOXYPARAMS"
|
||||
|
||||
# Clear out the output directory first
|
||||
find "${OUTPUTDIR}" -name "*.1" -delete
|
||||
|
||||
# Run doxygen
|
||||
cd "$TMPLOC"
|
||||
(cat "${DOXYFILE}" ; echo "$DOXYPARAMS";) | "$DOXYGENPATH" -
|
||||
|
||||
# Remember errors
|
||||
RESULT=$?
|
||||
|
||||
cd "${OUTPUTDIR}/man/man1/"
|
||||
if test "$RESULT" = 0 ; then
|
||||
|
||||
# Postprocess the files
|
||||
for i in "$INPUTDIR"/*.txt; do
|
||||
# It would be nice to use -i here for edit in place, but that is not portable
|
||||
CMD_NAME=`basename "$i" .txt`;
|
||||
sed -e "s/\(.\)\\.SH/\1/" -e "s/$CMD_NAME *\\\\- *\"\(.*\)\"/\1/" "${CMD_NAME}.1" > "${CMD_NAME}.1.tmp"
|
||||
mv "${CMD_NAME}.1.tmp" "${CMD_NAME}.1"
|
||||
done
|
||||
|
||||
# Erase condemned pages
|
||||
rm -f $CONDEMNED_PAGES
|
||||
|
||||
fi
|
||||
|
||||
# Destroy TMPLOC
|
||||
echo "Cleaning up '$TMPLOC'"
|
||||
rm -Rf "$TMPLOC"
|
||||
|
||||
if test "$RESULT" = 0; then
|
||||
# Tell the user what we did
|
||||
echo "Output man pages into '${OUTPUTDIR}'"
|
||||
else
|
||||
echo "Doxygen failed. See the output log for details."
|
||||
fi
|
||||
exit $RESULT
|
||||
3
build_tools/description-pak
Normal file
3
build_tools/description-pak
Normal file
@@ -0,0 +1,3 @@
|
||||
This is the_ridiculous'fish s delightful fork of, fish friendly interactive shell. For more information, visit http://ridiculousfish.com/shell/ .
|
||||
|
||||
This installer will install fish, but will not modify your /etc/shells file or your default shell. I trust you know how to do that yourself if you care to!
|
||||
8
build_tools/make_csv_completions.fish
Executable file
8
build_tools/make_csv_completions.fish
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for csv. Meant to be executed
|
||||
# from the root directory (so the completions get put in the right place).
|
||||
|
||||
. build_tools/make_vcs_completions_generic.fish
|
||||
|
||||
write_completions csv >share/completions/csv.fish
|
||||
12
build_tools/make_darcs_completions.fish
Executable file
12
build_tools/make_darcs_completions.fish
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for darcs. Meant to be
|
||||
# executed from the root directory (so the completions get put in the right
|
||||
# place).
|
||||
|
||||
. build_tools/make_vcs_completions_generic.fish
|
||||
|
||||
set darcs_comp 'complete -c darcs -n "not __fish_use_subcommand" -a "(test -f _darcs/prefs/repos; and cat _darcs/prefs/repos)" --description "Darcs repo"'
|
||||
set darcs_comp $darcs_comp 'complete -c darcs -a "test predist boringfile binariesfile" -n "contains setpref (commandline -poc)" --description "Set the specified option" -x'
|
||||
|
||||
write_completions darcs $darcs_comp >share/completions/darcs.fish
|
||||
18
build_tools/make_deb.sh
Executable file
18
build_tools/make_deb.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Terminate on error
|
||||
set -e
|
||||
|
||||
sudo rm -Rf /tmp/fishfish
|
||||
mkdir /tmp/fishfish
|
||||
git archive --format=tar fish_fish | tar -x -C /tmp/fishfish
|
||||
mkdir /tmp/fishfish/doc-pak
|
||||
cp README INSTALL CHANGELOG release_notes.html /tmp/fishfish/doc-pak/
|
||||
cp build_tools/description-pak /tmp/fishfish/
|
||||
cd /tmp/fishfish
|
||||
autoconf
|
||||
./configure
|
||||
make -j 3
|
||||
sudo checkinstall --default --pakdir ~/fish_built/ --pkgversion 0.9 make install
|
||||
mv ~/fish_built/fishfish_0.9-1_i386.deb ~/fish_built/fishfish_0.9_i386.deb
|
||||
|
||||
8
build_tools/make_hg_completions.fish
Executable file
8
build_tools/make_hg_completions.fish
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for hg. Meant to be executed
|
||||
# from the root directory (so the completions get put in the right place).
|
||||
|
||||
. build_tools/make_vcs_completions_generic.fish
|
||||
|
||||
write_completions hg >share/completions/hg.fish
|
||||
23
build_tools/make_pkg.sh
Executable file
23
build_tools/make_pkg.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION=`sed -E -n 's/^.*PACKAGE_VERSION "([0-9.]+)"/\1/p' osx/config.h`
|
||||
if test -z "$VERSION" ; then
|
||||
echo "Could not get version from osx/config.h"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Version is $VERSION"
|
||||
|
||||
set -x
|
||||
|
||||
make distclean
|
||||
rm -Rf /tmp/fish_pkg
|
||||
|
||||
#Exit on error
|
||||
set -e
|
||||
|
||||
mkdir -p /tmp/fish_pkg/root /tmp/fish_pkg/intermediates /tmp/fish_pkg/dst
|
||||
xcodebuild install -scheme install_tree -configuration Release DSTROOT=/tmp/fish_pkg/root/
|
||||
pkgbuild --scripts build_tools/osx_package_scripts --root /tmp/fish_pkg/root/ --identifier 'com.ridiculousfish.fish-shell-pkg' --version "$VERSION" /tmp/fish_pkg/intermediates/fish.pkg
|
||||
|
||||
productbuild --package-path /tmp/fish_pkg/intermediates --distribution build_tools/osx_distribution.xml --resources build_tools/osx_package_resources/ ~/fish_built/fish.pkg
|
||||
8
build_tools/make_svn_completions.fish
Executable file
8
build_tools/make_svn_completions.fish
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for svn. Meant to be executed
|
||||
# from the root directory (so the completions get put in the right place).
|
||||
|
||||
. build_tools/make_vcs_completions_generic.fish
|
||||
|
||||
write_completions svn >share/completions/svn.fish
|
||||
46
build_tools/make_tarball.sh
Executable file
46
build_tools/make_tarball.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Script to generate a tarball
|
||||
# We use git to output a tree. But we also want to build the user documentation
|
||||
# and put that in the tarball, so that nobody needs to have doxygen installed
|
||||
# to build it.
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# We wil generate a tarball with a prefix "fish"
|
||||
# git can do that automatically for us via git-archive
|
||||
# but to get the documentation in, we need to make a symlink called "fish"
|
||||
# and tar from that, so that the documentation gets the right prefix
|
||||
|
||||
# Get the current directory, which we'll use for symlinks
|
||||
wd="$PWD"
|
||||
|
||||
# The name of the prefix, which is the directory that you get when you untar
|
||||
prefix="fish"
|
||||
|
||||
# The path where we will output the tar file
|
||||
path=~/fish_built/fish-2.0.tar
|
||||
|
||||
# Clean up stuff we've written before
|
||||
rm -f "$path" "$path".gz
|
||||
|
||||
# git starts the archive
|
||||
git archive --format=tar --prefix="$prefix"/ master > "$path"
|
||||
|
||||
# tarball out the documentation
|
||||
make user_doc
|
||||
make share/man
|
||||
cd /tmp
|
||||
rm -f "$prefix"
|
||||
ln -s "$wd" "$prefix"
|
||||
tar --append --file="$path" "$prefix"/user_doc/html
|
||||
tar --append --file="$path" "$prefix"/share/man
|
||||
rm -f "$prefix"
|
||||
|
||||
# gzip it
|
||||
gzip "$path"
|
||||
|
||||
# Output what we did, and the sha1 hash
|
||||
echo "Tarball written to $path".gz
|
||||
openssl sha1 "$path".gz
|
||||
9
build_tools/make_vcs_completions.fish
Executable file
9
build_tools/make_vcs_completions.fish
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for hg, darcs and a
|
||||
# few other vcs systems.
|
||||
|
||||
build_tools/make_darcs_completions.fish
|
||||
build_tools/make_hg_completions.fish
|
||||
build_tools/make_svn_completions.fish
|
||||
build_tools/make_csv_completions.fish
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
#
|
||||
# This file produces command specific completions for hg, darcs and a
|
||||
# few other vcs systems. It uses the fact that all these systems have a
|
||||
# somewhat uniform command line help mechanism.
|
||||
# This file provides generic functions for generating specific completions for
|
||||
# hg, darcs and a few other vcs systems. It uses the fact that all these
|
||||
# systems have a somewhat uniform command line help mechanism.
|
||||
#
|
||||
|
||||
function cap
|
||||
@@ -227,11 +227,3 @@ function write_completions
|
||||
echo \n\n
|
||||
|
||||
end
|
||||
|
||||
set darcs_comp 'complete -c darcs -n "not __fish_use_subcommand" -a "(test -f _darcs/prefs/repos; and cat _darcs/prefs/repos)" --description "Darcs repo"'
|
||||
set darcs_comp $darcs_comp 'complete -c darcs -a "test predist boringfile binariesfile" -n "contains setpref (commandline -poc)" --description "Set the specified option" -x'
|
||||
|
||||
write_completions darcs $darcs_comp >share/completions/darcs.fish
|
||||
write_completions hg >share/completions/hg.fish
|
||||
write_completions svn >share/completions/svn.fish
|
||||
write_completions cvs >share/completions/cvs.fish
|
||||
18
build_tools/osx_distribution.xml
Normal file
18
build_tools/osx_distribution.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<installer-gui-script minSpecVersion="1">
|
||||
<title>fish shell</title>
|
||||
<welcome file="welcome.rtf"/>
|
||||
<background file="terminal_logo.png" scaling="proportional" alignment="bottomleft"/>
|
||||
<pkg-ref id="com.ridiculousfish.fish-shell-pkg"/>
|
||||
<options customize="never" require-scripts="false"/>
|
||||
<choices-outline>
|
||||
<line choice="default">
|
||||
<line choice="com.ridiculousfish.fish-shell-pkg"/>
|
||||
</line>
|
||||
</choices-outline>
|
||||
<choice id="default"/>
|
||||
<choice id="com.ridiculousfish.fish-shell-pkg" visible="false">
|
||||
<pkg-ref id="com.ridiculousfish.fish-shell-pkg"/>
|
||||
</choice>
|
||||
<pkg-ref id="com.ridiculousfish.fish-shell-pkg" version="0" onConclusion="none">fish.pkg</pkg-ref>
|
||||
</installer-gui-script>
|
||||
BIN
build_tools/osx_package_resources/terminal_logo.png
Normal file
BIN
build_tools/osx_package_resources/terminal_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
25
build_tools/osx_package_resources/welcome.rtf
Normal file
25
build_tools/osx_package_resources/welcome.rtf
Normal file
@@ -0,0 +1,25 @@
|
||||
{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf370
|
||||
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;}
|
||||
{\colortbl;\red255\green255\blue255;}
|
||||
{\info
|
||||
{\author dlkfjslfjsfdlkfk}}\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
||||
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
|
||||
|
||||
\f0\fs30 \cf0 The fish shell is a smart and user friendly command line shell. For more information, visit {\field{\*\fldinst{HYPERLINK "http://fishshell.com"}}{\fldrslt http://fishshell.com}}.\
|
||||
\
|
||||
fish will be installed into
|
||||
\f1\fs26 /usr/local/
|
||||
\f0\fs30 , and fish will be added to
|
||||
\f1\fs26 /etc/shells
|
||||
\f0\fs30 if necessary.\
|
||||
\
|
||||
Your default shell will
|
||||
\i not
|
||||
\i0 be changed. To make fish your default, run:\
|
||||
\
|
||||
|
||||
\f1 chsh -s /usr/local/bin/fish
|
||||
\f0 \
|
||||
\
|
||||
Enjoy!\
|
||||
}
|
||||
53
build_tools/osx_package_scripts/add-shell
Executable file
53
build_tools/osx_package_scripts/add-shell
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# Modified from Debian's add-shell to work on OS X
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
echo usage: $0 shellname [shellname ...]
|
||||
exit 1
|
||||
fi
|
||||
|
||||
scriptname=`basename "$0"`
|
||||
if [[ $UID -ne 0 ]]; then
|
||||
echo "${scriptname} must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file=/etc/shells
|
||||
# I want this to be GUARANTEED to be on the same filesystem as $file
|
||||
tmpfile=${file}.tmp
|
||||
|
||||
set -o noclobber
|
||||
|
||||
trap "rm -f $tmpfile" EXIT
|
||||
|
||||
if ! cat $file > $tmpfile
|
||||
then
|
||||
cat 1>&2 <<EOF
|
||||
Either another instance of $0 is running, or it was previously interrupted.
|
||||
Please examine ${tmpfile} to see if it should be moved onto ${file}.
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Append a newline if it doesn't exist
|
||||
if [ "$(tail -c1 "$tmpfile"; echo x)" != $'\nx' ]; then
|
||||
echo "" >> "$tmpfile"
|
||||
fi
|
||||
|
||||
for i
|
||||
do
|
||||
if ! grep -q "^${i}$" "$tmpfile"
|
||||
then
|
||||
echo $i >> "$tmpfile"
|
||||
fi
|
||||
done
|
||||
|
||||
chmod 0644 $tmpfile
|
||||
chown root:wheel $tmpfile
|
||||
|
||||
mv $tmpfile $file
|
||||
|
||||
trap "" EXIT
|
||||
exit 0
|
||||
3
build_tools/osx_package_scripts/postinstall
Executable file
3
build_tools/osx_package_scripts/postinstall
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh -x
|
||||
|
||||
./add-shell /usr/local/bin/fish > /tmp/fish_postinstall_output.log
|
||||
4147
builtin.cpp
Normal file
4147
builtin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
64
builtin.h
64
builtin.h
@@ -1,5 +1,5 @@
|
||||
/** \file builtin.h
|
||||
Prototypes for functions for executing builtin functions.
|
||||
Prototypes for functions for executing builtin functions.
|
||||
*/
|
||||
|
||||
#ifndef FISH_BUILTIN_H
|
||||
@@ -9,12 +9,15 @@
|
||||
|
||||
#include "util.h"
|
||||
#include "io.h"
|
||||
#include "common.h"
|
||||
|
||||
class parser_t;
|
||||
|
||||
enum
|
||||
{
|
||||
COMMAND_NOT_BUILTIN,
|
||||
BUILTIN_REGULAR,
|
||||
BUILTIN_FUNCTION
|
||||
COMMAND_NOT_BUILTIN,
|
||||
BUILTIN_REGULAR,
|
||||
BUILTIN_FUNCTION
|
||||
}
|
||||
;
|
||||
|
||||
@@ -46,7 +49,7 @@ enum
|
||||
/**
|
||||
Error message for unknown switch
|
||||
*/
|
||||
#define BUILTIN_ERR_UNKNOWN _( L"%ls: Unknown option '%ls'\n" )
|
||||
#define BUILTIN_ERR_UNKNOWN _( L"%ls: Unknown option '%ls'\n" )
|
||||
|
||||
/**
|
||||
Error message for invalid character in variable name
|
||||
@@ -70,6 +73,10 @@ enum
|
||||
|
||||
#define BUILTIN_FOR_ERR_NAME _( L"%ls: '%ls' is not a valid variable name\n" )
|
||||
|
||||
/** Error messages for 'else if' */
|
||||
#define BUILTIN_ELSEIF_ERR_COUNT _( L"%ls: can only take 'if' and then another command as an argument\n")
|
||||
#define BUILTIN_ELSEIF_ERR_ARGUMENT _( L"%ls: any second argument must be 'if'\n")
|
||||
|
||||
/**
|
||||
Error message when too many arguments are supplied to a builtin
|
||||
*/
|
||||
@@ -86,15 +93,13 @@ enum
|
||||
#define BUILTIN_END_BLOCK_UNKNOWN _( L"%ls: Unknown block type '%ls'\n" )
|
||||
|
||||
#define BUILTIN_ERR_NOT_NUMBER _( L"%ls: Argument '%ls' is not a number\n" )
|
||||
/**
|
||||
Stringbuffer used to represent standard output
|
||||
*/
|
||||
extern string_buffer_t *sb_out;
|
||||
|
||||
/**
|
||||
Stringbuffer used to represent standard error
|
||||
*/
|
||||
extern string_buffer_t *sb_err;
|
||||
/** Get the string used to represent stdout and stderr */
|
||||
const wcstring &get_stdout_buffer();
|
||||
const wcstring &get_stderr_buffer();
|
||||
|
||||
/** Output an error */
|
||||
void builtin_show_error(const wcstring &err);
|
||||
|
||||
/**
|
||||
Kludge. Tells builtins if output is to screen
|
||||
@@ -120,11 +125,12 @@ void builtin_destroy();
|
||||
/**
|
||||
Is there a builtin command with the given name?
|
||||
*/
|
||||
int builtin_exists( wchar_t *cmd );
|
||||
int builtin_exists(const wcstring &cmd);
|
||||
|
||||
/**
|
||||
Execute a builtin command
|
||||
|
||||
\param parser The parser being used
|
||||
\param argv Array containing the command and parameters
|
||||
of the builtin. The list is terminated by a
|
||||
null pointer. This syntax resembles the syntax
|
||||
@@ -133,28 +139,29 @@ int builtin_exists( wchar_t *cmd );
|
||||
|
||||
\return the exit status of the builtin command
|
||||
*/
|
||||
int builtin_run( wchar_t **argv, io_data_t *io );
|
||||
int builtin_run(parser_t &parser, const wchar_t * const *argv, const io_chain_t &io);
|
||||
|
||||
/** Returns a list of all builtin names */
|
||||
wcstring_list_t builtin_get_names(void);
|
||||
|
||||
/** Insert all builtin names into list. */
|
||||
void builtin_get_names(std::vector<completion_t> &list);
|
||||
|
||||
/**
|
||||
Insert all builtin names into l. These are not copies of the strings and should not be freed after use.
|
||||
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output strings is created.
|
||||
*/
|
||||
void builtin_get_names( array_list_t *list );
|
||||
void builtin_push_io(parser_t &parser, int stdin_fd);
|
||||
|
||||
/**
|
||||
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output string_buffer_ts is created.
|
||||
Pops a set of input/output from the stack. The output strings are destroued, but the input file is not closed.
|
||||
*/
|
||||
void builtin_push_io( int stdin_fd );
|
||||
|
||||
/**
|
||||
Pops a set of input/output from the stack. The output string_buffer_ts are destroued, but the input file is not closed.
|
||||
*/
|
||||
void builtin_pop_io();
|
||||
void builtin_pop_io(parser_t &parser);
|
||||
|
||||
|
||||
/**
|
||||
Return a one-line description of the specified builtin
|
||||
Return a one-line description of the specified builtin.
|
||||
*/
|
||||
const wchar_t *builtin_get_desc( const wchar_t *b );
|
||||
wcstring builtin_get_desc(const wcstring &b);
|
||||
|
||||
|
||||
/**
|
||||
@@ -167,10 +174,9 @@ const wchar_t *builtin_complete_get_temporary_buffer();
|
||||
|
||||
/**
|
||||
Run the __fish_print_help function to obtain the help information
|
||||
for the specified command. The resulting string will be valid until
|
||||
the next time this function is called, and must never be free'd manually.
|
||||
for the specified command.
|
||||
*/
|
||||
|
||||
wchar_t *builtin_help_get( const wchar_t *cmd );
|
||||
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,664 +0,0 @@
|
||||
/** \file builtin_commandline.c Functions defining the commandline builtin
|
||||
|
||||
Functions used for implementing the commandline builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
#include "reader.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "tokenizer.h"
|
||||
#include "input_common.h"
|
||||
#include "input.h"
|
||||
|
||||
#include "parse_util.h"
|
||||
|
||||
/**
|
||||
Which part of the comandbuffer are we operating on
|
||||
*/
|
||||
enum
|
||||
{
|
||||
STRING_MODE=1, /**< Operate on entire buffer */
|
||||
JOB_MODE, /**< Operate on job under cursor */
|
||||
PROCESS_MODE, /**< Operate on process under cursor */
|
||||
TOKEN_MODE /**< Operate on token under cursor */
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
For text insertion, how should it be done
|
||||
*/
|
||||
enum
|
||||
{
|
||||
REPLACE_MODE=1, /**< Replace current text */
|
||||
INSERT_MODE, /**< Insert at cursor position */
|
||||
APPEND_MODE /**< Insert at end of current token/command/buffer */
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Pointer to what the commandline builtin considers to be the current
|
||||
contents of the command line buffer.
|
||||
*/
|
||||
static wchar_t *current_buffer=0;
|
||||
/**
|
||||
What the commandline builtin considers to be the current cursor
|
||||
position.
|
||||
*/
|
||||
static int current_cursor_pos = -1;
|
||||
|
||||
/**
|
||||
Returns the current commandline buffer.
|
||||
*/
|
||||
static wchar_t *get_buffer()
|
||||
{
|
||||
return current_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the position of the cursor
|
||||
*/
|
||||
static int get_cursor_pos()
|
||||
{
|
||||
return current_cursor_pos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Replace/append/insert the selection with/at/after the specified string.
|
||||
|
||||
\param begin beginning of selection
|
||||
\param end end of selection
|
||||
\param insert the string to insert
|
||||
\param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the test update is performed
|
||||
*/
|
||||
static void replace_part( const wchar_t *begin,
|
||||
const wchar_t *end,
|
||||
wchar_t *insert,
|
||||
int append_mode )
|
||||
{
|
||||
const wchar_t *buff = get_buffer();
|
||||
string_buffer_t out;
|
||||
int out_pos=get_cursor_pos();
|
||||
|
||||
sb_init( &out );
|
||||
|
||||
sb_append_substring( &out, buff, begin-buff );
|
||||
|
||||
switch( append_mode)
|
||||
{
|
||||
case REPLACE_MODE:
|
||||
{
|
||||
|
||||
sb_append( &out, insert );
|
||||
out_pos = wcslen( insert ) + (begin-buff);
|
||||
break;
|
||||
|
||||
}
|
||||
case APPEND_MODE:
|
||||
{
|
||||
sb_append_substring( &out, begin, end-begin );
|
||||
sb_append( &out, insert );
|
||||
break;
|
||||
}
|
||||
case INSERT_MODE:
|
||||
{
|
||||
int cursor = get_cursor_pos() -(begin-buff);
|
||||
sb_append_substring( &out, begin, cursor );
|
||||
sb_append( &out, insert );
|
||||
sb_append_substring( &out, begin+cursor, end-begin-cursor );
|
||||
out_pos += wcslen( insert );
|
||||
break;
|
||||
}
|
||||
}
|
||||
sb_append( &out, end );
|
||||
reader_set_buffer( (wchar_t *)out.buff, out_pos );
|
||||
sb_destroy( &out );
|
||||
}
|
||||
|
||||
/**
|
||||
Output the specified selection.
|
||||
|
||||
\param begin start of selection
|
||||
\param end end of selection
|
||||
\param cut_at_cursor whether printing should stop at the surrent cursor position
|
||||
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
|
||||
*/
|
||||
static void write_part( const wchar_t *begin,
|
||||
const wchar_t *end,
|
||||
int cut_at_cursor,
|
||||
int tokenize )
|
||||
{
|
||||
tokenizer tok;
|
||||
string_buffer_t out;
|
||||
wchar_t *buff;
|
||||
int pos;
|
||||
|
||||
pos = get_cursor_pos()-(begin-get_buffer());
|
||||
|
||||
if( tokenize )
|
||||
{
|
||||
buff = wcsndup( begin, end-begin );
|
||||
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
|
||||
sb_init( &out );
|
||||
|
||||
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
|
||||
tok_has_next( &tok );
|
||||
tok_next( &tok ) )
|
||||
{
|
||||
if( (cut_at_cursor) &&
|
||||
(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
|
||||
break;
|
||||
|
||||
switch( tok_last_type( &tok ) )
|
||||
{
|
||||
case TOK_STRING:
|
||||
{
|
||||
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
|
||||
sb_append( &out, tmp, L"\n", (void *)0 );
|
||||
free( tmp );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sb_append( sb_out,
|
||||
(wchar_t *)out.buff );
|
||||
|
||||
free( buff );
|
||||
tok_destroy( &tok );
|
||||
sb_destroy( &out );
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t *buff;
|
||||
|
||||
if( cut_at_cursor )
|
||||
{
|
||||
end = begin+pos;
|
||||
}
|
||||
|
||||
buff = wcsndup( begin, end-begin );
|
||||
|
||||
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
|
||||
|
||||
sb_append( sb_out, buff );
|
||||
sb_append( sb_out, L"\n" );
|
||||
|
||||
free( buff );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
The commandline builtin. It is used for specifying a new value for
|
||||
the commandline.
|
||||
*/
|
||||
static int builtin_commandline( wchar_t **argv )
|
||||
{
|
||||
|
||||
int buffer_part=0;
|
||||
int cut_at_cursor=0;
|
||||
|
||||
int argc = builtin_count_args( argv );
|
||||
int append_mode=0;
|
||||
|
||||
int function_mode = 0;
|
||||
|
||||
int tokenize = 0;
|
||||
|
||||
int cursor_mode = 0;
|
||||
int line_mode = 0;
|
||||
int search_mode = 0;
|
||||
wchar_t *begin, *end;
|
||||
|
||||
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
|
||||
if( current_buffer )
|
||||
{
|
||||
current_cursor_pos = wcslen( current_buffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
current_buffer = reader_get_buffer();
|
||||
current_cursor_pos = reader_get_cursor_pos();
|
||||
}
|
||||
|
||||
if( !get_buffer() )
|
||||
{
|
||||
if (is_interactive_session)
|
||||
{
|
||||
/*
|
||||
Prompt change requested while we don't have
|
||||
a prompt, most probably while reading the
|
||||
init files. Just ignore it.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Can not set commandline in non-interactive mode\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
woptind=0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"append", no_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"insert", no_argument, 0, 'i'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"replace", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-job", no_argument, 0, 'j'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-process", no_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-token", no_argument, 0, 't'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-buffer", no_argument, 0, 'b'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cut-at-cursor", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"function", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"tokenize", no_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"input", required_argument, 0, 'I'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cursor", no_argument, 0, 'C'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"line", no_argument, 0, 'L'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"search-mode", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"abijpctwforhI:CLS",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
|
||||
case L'a':
|
||||
append_mode = APPEND_MODE;
|
||||
break;
|
||||
|
||||
case L'b':
|
||||
buffer_part = STRING_MODE;
|
||||
break;
|
||||
|
||||
|
||||
case L'i':
|
||||
append_mode = INSERT_MODE;
|
||||
break;
|
||||
|
||||
case L'r':
|
||||
append_mode = REPLACE_MODE;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
cut_at_cursor=1;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
buffer_part = TOKEN_MODE;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
buffer_part = JOB_MODE;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
buffer_part = PROCESS_MODE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
function_mode=1;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
tokenize=1;
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
current_buffer = woptarg;
|
||||
current_cursor_pos = wcslen( woptarg );
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
cursor_mode = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
line_mode = 1;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
search_mode = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help( argv[0], sb_out );
|
||||
return 0;
|
||||
|
||||
case L'?':
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( function_mode )
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if( argc == woptind )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_MISSING,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
wint_t c = input_function_get_code( argv[i] );
|
||||
if( c != -1 )
|
||||
{
|
||||
/*
|
||||
input_unreadch inserts the specified keypress or
|
||||
readline function at the top of the stack of unused
|
||||
keypresses
|
||||
*/
|
||||
input_unreadch(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Unknown input function '%ls'\n"),
|
||||
argv[0],
|
||||
argv[i] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
|
||||
{
|
||||
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if( (tokenize || cut_at_cursor) && (argc-woptind) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
|
||||
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( append_mode && !(argc-woptind) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
L"insertion mode switches can not be used when not in insertion mode" );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Set default modes
|
||||
*/
|
||||
if( !append_mode )
|
||||
{
|
||||
append_mode = REPLACE_MODE;
|
||||
}
|
||||
|
||||
if( !buffer_part )
|
||||
{
|
||||
buffer_part = STRING_MODE;
|
||||
}
|
||||
|
||||
if( cursor_mode )
|
||||
{
|
||||
if( argc-woptind )
|
||||
{
|
||||
wchar_t *endptr;
|
||||
int new_pos;
|
||||
errno = 0;
|
||||
|
||||
new_pos = wcstol( argv[woptind], &endptr, 10 );
|
||||
if( *endptr || errno )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_NOT_NUMBER,
|
||||
argv[0],
|
||||
argv[woptind] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
}
|
||||
|
||||
current_buffer = reader_get_buffer();
|
||||
new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
|
||||
reader_set_buffer( current_buffer, new_pos );
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( line_mode )
|
||||
{
|
||||
int pos = reader_get_cursor_pos();
|
||||
wchar_t *buff = reader_get_buffer();
|
||||
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if( search_mode )
|
||||
{
|
||||
return !reader_search_mode();
|
||||
}
|
||||
|
||||
|
||||
switch( buffer_part )
|
||||
{
|
||||
case STRING_MODE:
|
||||
{
|
||||
begin = get_buffer();
|
||||
end = begin+wcslen(begin);
|
||||
break;
|
||||
}
|
||||
|
||||
case PROCESS_MODE:
|
||||
{
|
||||
parse_util_process_extent( get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end );
|
||||
break;
|
||||
}
|
||||
|
||||
case JOB_MODE:
|
||||
{
|
||||
parse_util_job_extent( get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end );
|
||||
break;
|
||||
}
|
||||
|
||||
case TOKEN_MODE:
|
||||
{
|
||||
parse_util_token_extent( get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end,
|
||||
0, 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch(argc-woptind)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
write_part( begin, end, cut_at_cursor, tokenize );
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
replace_part( begin, end, argv[woptind], append_mode );
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
string_buffer_t sb;
|
||||
int i;
|
||||
|
||||
sb_init( &sb );
|
||||
|
||||
sb_append( &sb, argv[woptind] );
|
||||
|
||||
for( i=woptind+1; i<argc; i++ )
|
||||
{
|
||||
sb_append( &sb, L"\n" );
|
||||
sb_append( &sb, argv[i] );
|
||||
}
|
||||
|
||||
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
|
||||
sb_destroy( &sb );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
642
builtin_commandline.cpp
Normal file
642
builtin_commandline.cpp
Normal file
@@ -0,0 +1,642 @@
|
||||
/** \file builtin_commandline.c Functions defining the commandline builtin
|
||||
|
||||
Functions used for implementing the commandline builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
#include "reader.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "tokenizer.h"
|
||||
#include "input_common.h"
|
||||
#include "input.h"
|
||||
|
||||
#include "parse_util.h"
|
||||
|
||||
/**
|
||||
Which part of the comandbuffer are we operating on
|
||||
*/
|
||||
enum
|
||||
{
|
||||
STRING_MODE=1, /**< Operate on entire buffer */
|
||||
JOB_MODE, /**< Operate on job under cursor */
|
||||
PROCESS_MODE, /**< Operate on process under cursor */
|
||||
TOKEN_MODE /**< Operate on token under cursor */
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
For text insertion, how should it be done
|
||||
*/
|
||||
enum
|
||||
{
|
||||
REPLACE_MODE=1, /**< Replace current text */
|
||||
INSERT_MODE, /**< Insert at cursor position */
|
||||
APPEND_MODE /**< Insert at end of current token/command/buffer */
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Pointer to what the commandline builtin considers to be the current
|
||||
contents of the command line buffer.
|
||||
*/
|
||||
static const wchar_t *current_buffer=0;
|
||||
/**
|
||||
What the commandline builtin considers to be the current cursor
|
||||
position.
|
||||
*/
|
||||
static size_t current_cursor_pos = (size_t)(-1);
|
||||
|
||||
/**
|
||||
Returns the current commandline buffer.
|
||||
*/
|
||||
static const wchar_t *get_buffer()
|
||||
{
|
||||
return current_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the position of the cursor
|
||||
*/
|
||||
static size_t get_cursor_pos()
|
||||
{
|
||||
return current_cursor_pos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Replace/append/insert the selection with/at/after the specified string.
|
||||
|
||||
\param begin beginning of selection
|
||||
\param end end of selection
|
||||
\param insert the string to insert
|
||||
\param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the test update is performed
|
||||
*/
|
||||
static void replace_part(const wchar_t *begin,
|
||||
const wchar_t *end,
|
||||
const wchar_t *insert,
|
||||
int append_mode)
|
||||
{
|
||||
const wchar_t *buff = get_buffer();
|
||||
size_t out_pos = get_cursor_pos();
|
||||
|
||||
wcstring out;
|
||||
|
||||
out.append(buff, begin - buff);
|
||||
|
||||
switch (append_mode)
|
||||
{
|
||||
case REPLACE_MODE:
|
||||
{
|
||||
|
||||
out.append(insert);
|
||||
out_pos = wcslen(insert) + (begin-buff);
|
||||
break;
|
||||
|
||||
}
|
||||
case APPEND_MODE:
|
||||
{
|
||||
out.append(begin, end-begin);
|
||||
out.append(insert);
|
||||
break;
|
||||
}
|
||||
case INSERT_MODE:
|
||||
{
|
||||
long cursor = get_cursor_pos() -(begin-buff);
|
||||
out.append(begin, cursor);
|
||||
out.append(insert);
|
||||
out.append(begin+cursor, end-begin-cursor);
|
||||
out_pos += wcslen(insert);
|
||||
break;
|
||||
}
|
||||
}
|
||||
out.append(end);
|
||||
reader_set_buffer(out, out_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
Output the specified selection.
|
||||
|
||||
\param begin start of selection
|
||||
\param end end of selection
|
||||
\param cut_at_cursor whether printing should stop at the surrent cursor position
|
||||
\param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
|
||||
*/
|
||||
static void write_part(const wchar_t *begin,
|
||||
const wchar_t *end,
|
||||
int cut_at_cursor,
|
||||
int tokenize)
|
||||
{
|
||||
wcstring out;
|
||||
wchar_t *buff;
|
||||
size_t pos;
|
||||
|
||||
pos = get_cursor_pos()-(begin-get_buffer());
|
||||
|
||||
if (tokenize)
|
||||
{
|
||||
buff = wcsndup(begin, end-begin);
|
||||
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
|
||||
out.clear();
|
||||
tokenizer_t tok(buff, TOK_ACCEPT_UNFINISHED);
|
||||
for (; tok_has_next(&tok); tok_next(&tok))
|
||||
{
|
||||
if ((cut_at_cursor) &&
|
||||
(tok_get_pos(&tok)+wcslen(tok_last(&tok)) >= pos))
|
||||
break;
|
||||
|
||||
switch (tok_last_type(&tok))
|
||||
{
|
||||
case TOK_STRING:
|
||||
{
|
||||
out.append(escape_string(tok_last(&tok), UNESCAPE_INCOMPLETE));
|
||||
out.push_back(L'\n');
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
stdout_buffer.append(out);
|
||||
|
||||
free(buff);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cut_at_cursor)
|
||||
{
|
||||
end = begin+pos;
|
||||
}
|
||||
|
||||
// debug( 0, L"woot2 %ls -> %ls", buff, esc );
|
||||
|
||||
stdout_buffer.append(begin, end - begin);
|
||||
stdout_buffer.append(L"\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
The commandline builtin. It is used for specifying a new value for
|
||||
the commandline.
|
||||
*/
|
||||
static int builtin_commandline(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
|
||||
int buffer_part=0;
|
||||
int cut_at_cursor=0;
|
||||
|
||||
int argc = builtin_count_args(argv);
|
||||
int append_mode=0;
|
||||
|
||||
int function_mode = 0;
|
||||
|
||||
int tokenize = 0;
|
||||
|
||||
int cursor_mode = 0;
|
||||
int line_mode = 0;
|
||||
int search_mode = 0;
|
||||
const wchar_t *begin, *end;
|
||||
|
||||
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
|
||||
if (current_buffer)
|
||||
{
|
||||
current_cursor_pos = wcslen(current_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_buffer = reader_get_buffer();
|
||||
current_cursor_pos = reader_get_cursor_pos();
|
||||
}
|
||||
|
||||
if (!get_buffer())
|
||||
{
|
||||
if (is_interactive_session)
|
||||
{
|
||||
/*
|
||||
Prompt change requested while we don't have
|
||||
a prompt, most probably while reading the
|
||||
init files. Just ignore it.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
stderr_buffer.append(argv[0]);
|
||||
stderr_buffer.append(L": Can not set commandline in non-interactive mode\n");
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
woptind=0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"append", no_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"insert", no_argument, 0, 'i'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"replace", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-job", no_argument, 0, 'j'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-process", no_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-token", no_argument, 0, 't'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"current-buffer", no_argument, 0, 'b'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cut-at-cursor", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"function", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"tokenize", no_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"input", required_argument, 0, 'I'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cursor", no_argument, 0, 'C'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"line", no_argument, 0, 'L'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"search-mode", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"abijpctwforhI:CLS",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
if (long_options[opt_index].flag != 0)
|
||||
break;
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
return 1;
|
||||
|
||||
case L'a':
|
||||
append_mode = APPEND_MODE;
|
||||
break;
|
||||
|
||||
case L'b':
|
||||
buffer_part = STRING_MODE;
|
||||
break;
|
||||
|
||||
|
||||
case L'i':
|
||||
append_mode = INSERT_MODE;
|
||||
break;
|
||||
|
||||
case L'r':
|
||||
append_mode = REPLACE_MODE;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
cut_at_cursor=1;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
buffer_part = TOKEN_MODE;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
buffer_part = JOB_MODE;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
buffer_part = PROCESS_MODE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
function_mode=1;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
tokenize=1;
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
current_buffer = woptarg;
|
||||
current_cursor_pos = wcslen(woptarg);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
cursor_mode = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
line_mode = 1;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
search_mode = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
|
||||
case L'?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (function_mode)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (argc == woptind)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_MISSING,
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
for (i=woptind; i<argc; i++)
|
||||
{
|
||||
wchar_t c = input_function_get_code(argv[i]);
|
||||
if (c != (wchar_t)(-1))
|
||||
{
|
||||
/*
|
||||
input_unreadch inserts the specified keypress or
|
||||
readline function at the top of the stack of unused
|
||||
keypresses
|
||||
*/
|
||||
input_unreadch(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Unknown input function '%ls'\n"),
|
||||
argv[0],
|
||||
argv[i]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Check for invalid switch combinations
|
||||
*/
|
||||
if ((search_mode || line_mode || cursor_mode) && (argc-woptind > 1))
|
||||
{
|
||||
|
||||
append_format(stderr_buffer,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
NULL);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if ((tokenize || cut_at_cursor) && (argc-woptind))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
L"--cut-at-cursor and --tokenize can not be used when setting the commandline");
|
||||
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (append_mode && !(argc-woptind))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO2,
|
||||
argv[0],
|
||||
L"insertion mode switches can not be used when not in insertion mode");
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Set default modes
|
||||
*/
|
||||
if (!append_mode)
|
||||
{
|
||||
append_mode = REPLACE_MODE;
|
||||
}
|
||||
|
||||
if (!buffer_part)
|
||||
{
|
||||
buffer_part = STRING_MODE;
|
||||
}
|
||||
|
||||
if (cursor_mode)
|
||||
{
|
||||
if (argc-woptind)
|
||||
{
|
||||
wchar_t *endptr;
|
||||
long new_pos;
|
||||
errno = 0;
|
||||
|
||||
new_pos = wcstol(argv[woptind], &endptr, 10);
|
||||
if (*endptr || errno)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_NOT_NUMBER,
|
||||
argv[0],
|
||||
argv[woptind]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
}
|
||||
|
||||
current_buffer = reader_get_buffer();
|
||||
new_pos = maxi(0L, mini(new_pos, (long)wcslen(current_buffer)));
|
||||
reader_set_buffer(current_buffer, (size_t)new_pos);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stdout_buffer, L"%lu\n", (unsigned long)reader_get_cursor_pos());
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (line_mode)
|
||||
{
|
||||
size_t pos = reader_get_cursor_pos();
|
||||
const wchar_t *buff = reader_get_buffer();
|
||||
append_format(stdout_buffer, L"%lu\n", (unsigned long)parse_util_lineno(buff, pos));
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if (search_mode)
|
||||
{
|
||||
return !reader_search_mode();
|
||||
}
|
||||
|
||||
|
||||
switch (buffer_part)
|
||||
{
|
||||
case STRING_MODE:
|
||||
{
|
||||
begin = get_buffer();
|
||||
end = begin+wcslen(begin);
|
||||
break;
|
||||
}
|
||||
|
||||
case PROCESS_MODE:
|
||||
{
|
||||
parse_util_process_extent(get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end);
|
||||
break;
|
||||
}
|
||||
|
||||
case JOB_MODE:
|
||||
{
|
||||
parse_util_job_extent(get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end);
|
||||
break;
|
||||
}
|
||||
|
||||
case TOKEN_MODE:
|
||||
{
|
||||
parse_util_token_extent(get_buffer(),
|
||||
get_cursor_pos(),
|
||||
&begin,
|
||||
&end,
|
||||
0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (argc-woptind)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
write_part(begin, end, cut_at_cursor, tokenize);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
replace_part(begin, end, argv[woptind], append_mode);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
wcstring sb = argv[woptind];
|
||||
int i;
|
||||
|
||||
for (i=woptind+1; i<argc; i++)
|
||||
{
|
||||
sb.push_back(L'\n');
|
||||
sb.append(argv[i]);
|
||||
}
|
||||
|
||||
replace_part(begin, end, sb.c_str(), append_mode);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,646 +0,0 @@
|
||||
/** \file builtin_complete.c Functions defining the complete builtin
|
||||
|
||||
Functions used for implementing the complete builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "complete.h"
|
||||
#include "wgetopt.h"
|
||||
#include "parser.h"
|
||||
#include "reader.h"
|
||||
|
||||
|
||||
/**
|
||||
Internal storage for the builtin_get_temporary_buffer() function.
|
||||
*/
|
||||
static const wchar_t *temporary_buffer;
|
||||
|
||||
/*
|
||||
builtin_complete_* are a set of rather silly looping functions that
|
||||
make sure that all the proper combinations of complete_add or
|
||||
complete_remove get called. This is needed since complete allows you
|
||||
to specify multiple switches on a single commandline, like 'complete
|
||||
-s a -s b -s c', but the complete_add function only accepts one
|
||||
short switch and one long switch.
|
||||
*/
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_add2( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags )
|
||||
{
|
||||
int i;
|
||||
const wchar_t *s;
|
||||
|
||||
for( s=short_opt; *s; s++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( gnu_opt ); i++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
(wchar_t *)al_get(gnu_opt, i ),
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( old_opt ); i++ )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
(wchar_t *)al_get(old_opt, i ),
|
||||
1,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
if( al_get_count( old_opt )+al_get_count( gnu_opt )+wcslen(short_opt) == 0 )
|
||||
{
|
||||
complete_add( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_add( array_list_t *cmd,
|
||||
array_list_t *path,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt,
|
||||
int result_mode,
|
||||
int authoritative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( cmd ); i++ )
|
||||
{
|
||||
builtin_complete_add2( al_get( cmd, i ),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authoritative( al_get( cmd, i ),
|
||||
COMMAND,
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( path ); i++ )
|
||||
{
|
||||
builtin_complete_add2( al_get( path, i ),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
|
||||
if( authoritative != -1 )
|
||||
{
|
||||
complete_set_authoritative( al_get( path, i ),
|
||||
PATH,
|
||||
authoritative );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove3( wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
array_list_t *long_opt )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( long_opt ); i++ )
|
||||
{
|
||||
complete_remove( cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
(wchar_t *)al_get( long_opt, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove2( wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt )
|
||||
{
|
||||
const wchar_t *s = (wchar_t *)short_opt;
|
||||
if( *s )
|
||||
{
|
||||
for( ; *s; s++ )
|
||||
{
|
||||
if( al_get_count( old_opt) + al_get_count( gnu_opt ) == 0 )
|
||||
{
|
||||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0 );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
gnu_opt );
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
old_opt );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
gnu_opt );
|
||||
builtin_complete_remove3( cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
old_opt );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove( array_list_t *cmd,
|
||||
array_list_t *path,
|
||||
const wchar_t *short_opt,
|
||||
array_list_t *gnu_opt,
|
||||
array_list_t *old_opt )
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for( i=0; i<al_get_count( cmd ); i++ )
|
||||
{
|
||||
builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt );
|
||||
}
|
||||
|
||||
for( i=0; i<al_get_count( path ); i++ )
|
||||
{
|
||||
builtin_complete_remove2( (wchar_t *)al_get( path, i ),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *builtin_complete_get_temporary_buffer()
|
||||
{
|
||||
return temporary_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
The complete builtin. Used for specifying programmable
|
||||
tab-completions. Calls the functions in complete.c for any heavy
|
||||
lifting. Defined in builtin_complete.c
|
||||
*/
|
||||
static int builtin_complete( wchar_t **argv )
|
||||
{
|
||||
int res=0;
|
||||
int argc=0;
|
||||
int result_mode=SHARED;
|
||||
int remove = 0;
|
||||
int authoritative = -1;
|
||||
int flags = COMPLETE_AUTO_SPACE;
|
||||
|
||||
string_buffer_t short_opt;
|
||||
array_list_t gnu_opt, old_opt;
|
||||
wchar_t *comp=L"", *desc=L"", *condition=L"";
|
||||
|
||||
wchar_t *do_complete = 0;
|
||||
|
||||
array_list_t cmd;
|
||||
array_list_t path;
|
||||
|
||||
static int recursion_level=0;
|
||||
|
||||
al_init( &cmd );
|
||||
al_init( &path );
|
||||
sb_init( &short_opt );
|
||||
al_init( &gnu_opt );
|
||||
al_init( &old_opt );
|
||||
|
||||
argc = builtin_count_args( argv );
|
||||
|
||||
woptind=0;
|
||||
|
||||
while( res == 0 )
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"exclusive", no_argument, 0, 'x'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"no-files", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"require-parameter", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"path", required_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", required_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"short-option", required_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"long-option", required_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"old-option", required_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"description", required_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"arguments", required_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"erase", no_argument, 0, 'e'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthoritative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"authoritative", no_argument, 0, 'A'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"condition", required_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"do-complete", optional_argument, 0, 'C'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"a:c:p:s:l:o:d:frxeuAn:C::h",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
res = 1;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
result_mode |= EXCLUSIVE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
result_mode |= NO_FILES;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
result_mode |= NO_COMMON;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'c':
|
||||
{
|
||||
wchar_t *a = unescape( woptarg, 1);
|
||||
if( a )
|
||||
{
|
||||
al_push( (opt=='p'?&path:&cmd), a );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg );
|
||||
res = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd':
|
||||
desc = woptarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authoritative=0;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
authoritative=1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sb_append( &short_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
al_push( &gnu_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
al_push( &old_opt, woptarg );
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
comp = woptarg;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
remove = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
condition = woptarg;
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
do_complete = woptarg?woptarg:reader_get_buffer();
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help( argv[0], sb_out );
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
res = 1;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( !res )
|
||||
{
|
||||
if( condition && wcslen( condition ) )
|
||||
{
|
||||
if( parser_test( condition, 0, 0, 0 ) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
L"%ls: Condition '%ls' contained a syntax error\n",
|
||||
argv[0],
|
||||
condition );
|
||||
|
||||
parser_test( condition, 0, sb_err, argv[0] );
|
||||
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !res )
|
||||
{
|
||||
if( comp && wcslen( comp ) )
|
||||
{
|
||||
if( parser_test_args( comp, 0, 0 ) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
L"%ls: Completion '%ls' contained a syntax error\n",
|
||||
argv[0],
|
||||
comp );
|
||||
|
||||
parser_test_args( comp, sb_err, argv[0] );
|
||||
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !res )
|
||||
{
|
||||
if( do_complete )
|
||||
{
|
||||
array_list_t *comp;
|
||||
int i;
|
||||
|
||||
const wchar_t *prev_temporary_buffer = temporary_buffer;
|
||||
|
||||
wchar_t *token;
|
||||
|
||||
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
|
||||
|
||||
temporary_buffer = do_complete;
|
||||
|
||||
if( recursion_level < 1 )
|
||||
{
|
||||
recursion_level++;
|
||||
|
||||
comp = al_halloc( 0 );
|
||||
|
||||
complete( do_complete, comp );
|
||||
|
||||
for( i=0; i<al_get_count( comp ); i++ )
|
||||
{
|
||||
completion_t *next = (completion_t *)al_get( comp, i );
|
||||
wchar_t *prepend;
|
||||
|
||||
if( next->flags & COMPLETE_NO_CASE )
|
||||
{
|
||||
prepend = L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = token;
|
||||
}
|
||||
|
||||
|
||||
if( next->description )
|
||||
{
|
||||
sb_printf( sb_out, L"%ls%ls\t%ls\n", prepend, next->completion, next->description );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion );
|
||||
}
|
||||
}
|
||||
|
||||
halloc_free( comp );
|
||||
recursion_level--;
|
||||
}
|
||||
|
||||
temporary_buffer = prev_temporary_buffer;
|
||||
|
||||
}
|
||||
else if( woptind != argc )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Too many arguments\n" ),
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
res = 1;
|
||||
}
|
||||
else if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) )
|
||||
{
|
||||
/* No arguments specified, meaning we print the definitions of
|
||||
* all specified completions to stdout.*/
|
||||
complete_print( sb_out );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( remove )
|
||||
{
|
||||
builtin_complete_remove( &cmd,
|
||||
&path,
|
||||
(wchar_t *)short_opt.buff,
|
||||
&gnu_opt,
|
||||
&old_opt );
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_add( &cmd,
|
||||
&path,
|
||||
(wchar_t *)short_opt.buff,
|
||||
&gnu_opt,
|
||||
&old_opt,
|
||||
result_mode,
|
||||
authoritative,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
al_foreach( &cmd, &free );
|
||||
al_foreach( &path, &free );
|
||||
|
||||
al_destroy( &cmd );
|
||||
al_destroy( &path );
|
||||
sb_destroy( &short_opt );
|
||||
al_destroy( &gnu_opt );
|
||||
al_destroy( &old_opt );
|
||||
|
||||
return res;
|
||||
}
|
||||
626
builtin_complete.cpp
Normal file
626
builtin_complete.cpp
Normal file
@@ -0,0 +1,626 @@
|
||||
/** \file builtin_complete.c Functions defining the complete builtin
|
||||
|
||||
Functions used for implementing the complete builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "complete.h"
|
||||
#include "wgetopt.h"
|
||||
#include "parser.h"
|
||||
#include "reader.h"
|
||||
|
||||
|
||||
/**
|
||||
Internal storage for the builtin_complete_get_temporary_buffer() function.
|
||||
*/
|
||||
static const wchar_t *temporary_buffer;
|
||||
|
||||
/*
|
||||
builtin_complete_* are a set of rather silly looping functions that
|
||||
make sure that all the proper combinations of complete_add or
|
||||
complete_remove get called. This is needed since complete allows you
|
||||
to specify multiple switches on a single commandline, like 'complete
|
||||
-s a -s b -s c', but the complete_add function only accepts one
|
||||
short switch and one long switch.
|
||||
*/
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_add2(const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
const wcstring_list_t &gnu_opt,
|
||||
const wcstring_list_t &old_opt,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags)
|
||||
{
|
||||
size_t i;
|
||||
const wchar_t *s;
|
||||
|
||||
for (s=short_opt; *s; s++)
|
||||
{
|
||||
complete_add(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
}
|
||||
|
||||
for (i=0; i<gnu_opt.size(); i++)
|
||||
{
|
||||
complete_add(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
gnu_opt.at(i).c_str(),
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
}
|
||||
|
||||
for (i=0; i<old_opt.size(); i++)
|
||||
{
|
||||
complete_add(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
old_opt.at(i).c_str(),
|
||||
1,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
}
|
||||
|
||||
if (old_opt.empty() && gnu_opt.empty() && wcslen(short_opt) == 0)
|
||||
{
|
||||
complete_add(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_add(const wcstring_list_t &cmd,
|
||||
const wcstring_list_t &path,
|
||||
const wchar_t *short_opt,
|
||||
wcstring_list_t &gnu_opt,
|
||||
wcstring_list_t &old_opt,
|
||||
int result_mode,
|
||||
int authoritative,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags)
|
||||
{
|
||||
for (size_t i=0; i<cmd.size(); i++)
|
||||
{
|
||||
builtin_complete_add2(cmd.at(i).c_str(),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
|
||||
if (authoritative != -1)
|
||||
{
|
||||
complete_set_authoritative(cmd.at(i).c_str(),
|
||||
COMMAND,
|
||||
authoritative);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (size_t i=0; i<path.size(); i++)
|
||||
{
|
||||
builtin_complete_add2(path.at(i).c_str(),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
|
||||
if (authoritative != -1)
|
||||
{
|
||||
complete_set_authoritative(path.at(i).c_str(),
|
||||
PATH,
|
||||
authoritative);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove3(const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
const wcstring_list_t &long_opt)
|
||||
{
|
||||
for (size_t i=0; i<long_opt.size(); i++)
|
||||
{
|
||||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
long_opt.at(i).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove2(const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
const wchar_t *short_opt,
|
||||
const wcstring_list_t &gnu_opt,
|
||||
const wcstring_list_t &old_opt)
|
||||
{
|
||||
const wchar_t *s = (wchar_t *)short_opt;
|
||||
if (*s)
|
||||
{
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (old_opt.empty() && gnu_opt.empty())
|
||||
{
|
||||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
gnu_opt);
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
old_opt);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
gnu_opt);
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
old_opt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Silly function
|
||||
*/
|
||||
static void builtin_complete_remove(const wcstring_list_t &cmd,
|
||||
const wcstring_list_t &path,
|
||||
const wchar_t *short_opt,
|
||||
const wcstring_list_t &gnu_opt,
|
||||
const wcstring_list_t &old_opt)
|
||||
{
|
||||
for (size_t i=0; i<cmd.size(); i++)
|
||||
{
|
||||
builtin_complete_remove2(cmd.at(i).c_str(),
|
||||
COMMAND,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt);
|
||||
}
|
||||
|
||||
for (size_t i=0; i<path.size(); i++)
|
||||
{
|
||||
builtin_complete_remove2(path.at(i).c_str(),
|
||||
PATH,
|
||||
short_opt,
|
||||
gnu_opt,
|
||||
old_opt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *builtin_complete_get_temporary_buffer()
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
return temporary_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
The complete builtin. Used for specifying programmable
|
||||
tab-completions. Calls the functions in complete.c for any heavy
|
||||
lifting. Defined in builtin_complete.c
|
||||
*/
|
||||
static int builtin_complete(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
bool res=false;
|
||||
int argc=0;
|
||||
int result_mode=SHARED;
|
||||
int remove = 0;
|
||||
int authoritative = -1;
|
||||
int flags = COMPLETE_AUTO_SPACE;
|
||||
|
||||
wcstring short_opt;
|
||||
wcstring_list_t gnu_opt, old_opt;
|
||||
const wchar_t *comp=L"", *desc=L"", *condition=L"";
|
||||
|
||||
bool do_complete = false;
|
||||
wcstring do_complete_param;
|
||||
|
||||
wcstring_list_t cmd;
|
||||
wcstring_list_t path;
|
||||
|
||||
static int recursion_level=0;
|
||||
|
||||
argc = builtin_count_args(argv);
|
||||
|
||||
woptind=0;
|
||||
|
||||
while (! res)
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"exclusive", no_argument, 0, 'x'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"no-files", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"require-parameter", no_argument, 0, 'r'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"path", required_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", required_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"short-option", required_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"long-option", required_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"old-option", required_argument, 0, 'o'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"description", required_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"arguments", required_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"erase", no_argument, 0, 'e'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unauthoritative", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"authoritative", no_argument, 0, 'A'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"condition", required_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"do-complete", optional_argument, 0, 'C'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"a:c:p:s:l:o:d:frxeuAn:C::h",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
if (long_options[opt_index].flag != 0)
|
||||
break;
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
|
||||
res = true;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
result_mode |= EXCLUSIVE;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
result_mode |= NO_FILES;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
result_mode |= NO_COMMON;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'c':
|
||||
{
|
||||
wcstring tmp = woptarg;
|
||||
if (unescape_string(tmp, 1))
|
||||
{
|
||||
if (opt=='p')
|
||||
path.push_back(tmp);
|
||||
else
|
||||
cmd.push_back(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg);
|
||||
res = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd':
|
||||
desc = woptarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
authoritative=0;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
authoritative=1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
short_opt.append(woptarg);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
gnu_opt.push_back(woptarg);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
old_opt.push_back(woptarg);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
comp = woptarg;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
remove = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
condition = woptarg;
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
do_complete = true;
|
||||
do_complete_param = woptarg ? woptarg : reader_get_buffer();
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
res = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
if (condition && wcslen(condition))
|
||||
{
|
||||
if (parser.test(condition))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
L"%ls: Condition '%ls' contained a syntax error\n",
|
||||
argv[0],
|
||||
condition);
|
||||
|
||||
parser.test(condition, NULL, &stderr_buffer, argv[0]);
|
||||
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
if (comp && wcslen(comp))
|
||||
{
|
||||
if (parser.test_args(comp, 0, 0))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
L"%ls: Completion '%ls' contained a syntax error\n",
|
||||
argv[0],
|
||||
comp);
|
||||
|
||||
parser.test_args(comp, &stderr_buffer, argv[0]);
|
||||
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
if (do_complete)
|
||||
{
|
||||
const wchar_t *token;
|
||||
|
||||
parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, 0);
|
||||
|
||||
const wchar_t *prev_temporary_buffer = temporary_buffer;
|
||||
temporary_buffer = do_complete_param.c_str();
|
||||
|
||||
if (recursion_level < 1)
|
||||
{
|
||||
recursion_level++;
|
||||
|
||||
std::vector<completion_t> comp;
|
||||
complete(do_complete_param, comp, COMPLETION_REQUEST_DEFAULT);
|
||||
|
||||
for (size_t i=0; i< comp.size() ; i++)
|
||||
{
|
||||
const completion_t &next = comp.at(i);
|
||||
|
||||
const wchar_t *prepend;
|
||||
|
||||
if (next.flags & COMPLETE_REPLACES_TOKEN)
|
||||
{
|
||||
prepend = L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = token;
|
||||
}
|
||||
|
||||
|
||||
if (!(next.description).empty())
|
||||
{
|
||||
append_format(stdout_buffer, L"%ls%ls\t%ls\n", prepend, next.completion.c_str(), next.description.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stdout_buffer, L"%ls%ls\n", prepend, next.completion.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
recursion_level--;
|
||||
}
|
||||
|
||||
temporary_buffer = prev_temporary_buffer;
|
||||
|
||||
}
|
||||
else if (woptind != argc)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Too many arguments\n"),
|
||||
argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
res = true;
|
||||
}
|
||||
else if (cmd.empty() && path.empty())
|
||||
{
|
||||
/* No arguments specified, meaning we print the definitions of
|
||||
* all specified completions to stdout.*/
|
||||
complete_print(stdout_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (remove)
|
||||
{
|
||||
builtin_complete_remove(cmd,
|
||||
path,
|
||||
short_opt.c_str(),
|
||||
gnu_opt,
|
||||
old_opt);
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_complete_add(cmd,
|
||||
path,
|
||||
short_opt.c_str(),
|
||||
gnu_opt,
|
||||
old_opt,
|
||||
result_mode,
|
||||
authoritative,
|
||||
condition,
|
||||
comp,
|
||||
desc,
|
||||
flags);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return res ? 1 : 0;
|
||||
}
|
||||
348
builtin_jobs.c
348
builtin_jobs.c
@@ -1,348 +0,0 @@
|
||||
/** \file builtin_jobs.c
|
||||
Functions for executing the jobs builtin.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
|
||||
|
||||
/**
|
||||
Print modes for the jobs builtin
|
||||
*/
|
||||
enum
|
||||
{
|
||||
JOBS_DEFAULT, /**< Print lots of general info */
|
||||
JOBS_PRINT_PID, /**< Print pid of each process in job */
|
||||
JOBS_PRINT_COMMAND, /**< Print command name of each process in job */
|
||||
JOBS_PRINT_GROUP, /**< Print group id of job */
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
/**
|
||||
Calculates the cpu usage (in percent) of the specified job.
|
||||
*/
|
||||
static int cpu_use( job_t *j )
|
||||
{
|
||||
double u=0;
|
||||
process_t *p;
|
||||
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
struct timeval t;
|
||||
int jiffies;
|
||||
gettimeofday( &t, 0 );
|
||||
jiffies = proc_get_jiffies( p );
|
||||
|
||||
double t1 = 1000000.0*p->last_time.tv_sec+p->last_time.tv_usec;
|
||||
double t2 = 1000000.0*t.tv_sec+t.tv_usec;
|
||||
|
||||
/* fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n",
|
||||
t1, t2, jiffies, p->last_jiffies );
|
||||
*/
|
||||
|
||||
u += ((double)(jiffies-p->last_jiffies))/(t2-t1);
|
||||
}
|
||||
return u*1000000;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Print information about the specified job
|
||||
*/
|
||||
static void builtin_jobs_print( job_t *j, int mode, int header )
|
||||
{
|
||||
process_t *p;
|
||||
switch( mode )
|
||||
{
|
||||
case JOBS_DEFAULT:
|
||||
{
|
||||
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, _( L"Job\tGroup\t" ));
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_append( sb_out, _( L"CPU\t" ) );
|
||||
#endif
|
||||
sb_append( sb_out, _( L"State\tCommand\n" ) );
|
||||
}
|
||||
|
||||
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
||||
#endif
|
||||
sb_append( sb_out,
|
||||
job_is_stopped(j)?_(L"stopped"):_(L"running"),
|
||||
L"\t",
|
||||
j->command,
|
||||
L"\n",
|
||||
(void *)0 );
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_GROUP:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, _( L"Group\n" ));
|
||||
}
|
||||
sb_printf( sb_out, L"%d\n", j->pgid );
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_PID:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, _( L"Procces\n" ));
|
||||
}
|
||||
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", p->pid );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_COMMAND:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, _( L"Command\n" ));
|
||||
}
|
||||
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
sb_printf( sb_out, L"%ls\n", p->argv[0] );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c.
|
||||
*/
|
||||
static int builtin_jobs( wchar_t **argv )
|
||||
{
|
||||
int argc=0;
|
||||
int found=0;
|
||||
int mode=JOBS_DEFAULT;
|
||||
int print_last = 0;
|
||||
job_t *j;
|
||||
|
||||
argc = builtin_count_args( argv );
|
||||
woptind=0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"pid", no_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"group", no_argument, 0, 'g'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"last", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"pclgh",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
case 'p':
|
||||
mode=JOBS_PRINT_PID;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
mode=JOBS_PRINT_COMMAND;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
mode=JOBS_PRINT_GROUP;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
{
|
||||
print_last = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
builtin_print_help( argv[0], sb_out );
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Do not babble if not interactive
|
||||
*/
|
||||
if( builtin_out_redirect )
|
||||
{
|
||||
found=1;
|
||||
}
|
||||
|
||||
if( print_last )
|
||||
{
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
for( j=first_job; j; j=j->next )
|
||||
{
|
||||
if( (j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) )
|
||||
{
|
||||
builtin_jobs_print( j, mode, !found );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( woptind < argc )
|
||||
{
|
||||
int i;
|
||||
|
||||
found = 1;
|
||||
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
long pid;
|
||||
wchar_t *end;
|
||||
errno=0;
|
||||
pid=wcstol( argv[i], &end, 10 );
|
||||
if( errno || *end )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: '%ls' is not a job\n" ),
|
||||
argv[0],
|
||||
argv[i] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
j = job_get_from_pid( pid );
|
||||
|
||||
if( j && !job_is_completed( j ) )
|
||||
{
|
||||
builtin_jobs_print( j, mode, !found );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: No suitable job: %d\n" ),
|
||||
argv[0],
|
||||
pid );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( j= first_job; j; j=j->next )
|
||||
{
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
if( (j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) )
|
||||
{
|
||||
builtin_jobs_print( j, mode, !found );
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
sb_printf( sb_out,
|
||||
_( L"%ls: There are no jobs\n" ),
|
||||
argv[0] );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
351
builtin_jobs.cpp
Normal file
351
builtin_jobs.cpp
Normal file
@@ -0,0 +1,351 @@
|
||||
/** \file builtin_jobs.c
|
||||
Functions for executing the jobs builtin.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
|
||||
|
||||
/**
|
||||
Print modes for the jobs builtin
|
||||
*/
|
||||
enum
|
||||
{
|
||||
JOBS_DEFAULT, /**< Print lots of general info */
|
||||
JOBS_PRINT_PID, /**< Print pid of each process in job */
|
||||
JOBS_PRINT_COMMAND, /**< Print command name of each process in job */
|
||||
JOBS_PRINT_GROUP, /**< Print group id of job */
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
/**
|
||||
Calculates the cpu usage (in percent) of the specified job.
|
||||
*/
|
||||
static int cpu_use(const job_t *j)
|
||||
{
|
||||
double u=0;
|
||||
process_t *p;
|
||||
|
||||
for (p=j->first_process; p; p=p->next)
|
||||
{
|
||||
struct timeval t;
|
||||
int jiffies;
|
||||
gettimeofday(&t, 0);
|
||||
jiffies = proc_get_jiffies(p);
|
||||
|
||||
double t1 = 1000000.0*p->last_time.tv_sec+p->last_time.tv_usec;
|
||||
double t2 = 1000000.0*t.tv_sec+t.tv_usec;
|
||||
|
||||
/* fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n",
|
||||
t1, t2, jiffies, p->last_jiffies );
|
||||
*/
|
||||
|
||||
u += ((double)(jiffies-p->last_jiffies))/(t2-t1);
|
||||
}
|
||||
return u*1000000;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Print information about the specified job
|
||||
*/
|
||||
static void builtin_jobs_print(const job_t *j, int mode, int header)
|
||||
{
|
||||
process_t *p;
|
||||
switch (mode)
|
||||
{
|
||||
case JOBS_DEFAULT:
|
||||
{
|
||||
|
||||
if (header)
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
stdout_buffer.append(_(L"Job\tGroup\t"));
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
stdout_buffer.append(_(L"CPU\t"));
|
||||
#endif
|
||||
stdout_buffer.append(_(L"State\tCommand\n"));
|
||||
}
|
||||
|
||||
append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid);
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
append_format(stdout_buffer, L"%d%%\t", cpu_use(j));
|
||||
#endif
|
||||
stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running"));
|
||||
stdout_buffer.append(L"\t");
|
||||
stdout_buffer.append(j->command_wcstr());
|
||||
stdout_buffer.append(L"\n");
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_GROUP:
|
||||
{
|
||||
if (header)
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
stdout_buffer.append(_(L"Group\n"));
|
||||
}
|
||||
append_format(stdout_buffer, L"%d\n", j->pgid);
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_PID:
|
||||
{
|
||||
if (header)
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
stdout_buffer.append(_(L"Procces\n"));
|
||||
}
|
||||
|
||||
for (p=j->first_process; p; p=p->next)
|
||||
{
|
||||
append_format(stdout_buffer, L"%d\n", p->pid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_COMMAND:
|
||||
{
|
||||
if (header)
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
stdout_buffer.append(_(L"Command\n"));
|
||||
}
|
||||
|
||||
for (p=j->first_process; p; p=p->next)
|
||||
{
|
||||
append_format(stdout_buffer, L"%ls\n", p->argv0());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c.
|
||||
*/
|
||||
static int builtin_jobs(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
int argc=0;
|
||||
int found=0;
|
||||
int mode=JOBS_DEFAULT;
|
||||
int print_last = 0;
|
||||
const job_t *j;
|
||||
|
||||
argc = builtin_count_args(argv);
|
||||
woptind=0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"pid", no_argument, 0, 'p'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"command", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"group", no_argument, 0, 'g'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"last", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"pclgh",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
if (long_options[opt_index].flag != 0)
|
||||
break;
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
case 'p':
|
||||
mode=JOBS_PRINT_PID;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
mode=JOBS_PRINT_COMMAND;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
mode=JOBS_PRINT_GROUP;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
{
|
||||
print_last = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Do not babble if not interactive
|
||||
*/
|
||||
if (builtin_out_redirect)
|
||||
{
|
||||
found=1;
|
||||
}
|
||||
|
||||
if (print_last)
|
||||
{
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
job_iterator_t jobs;
|
||||
const job_t *j;
|
||||
while ((j = jobs.next()))
|
||||
{
|
||||
|
||||
if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j))
|
||||
{
|
||||
builtin_jobs_print(j, mode, !found);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (woptind < argc)
|
||||
{
|
||||
int i;
|
||||
|
||||
found = 1;
|
||||
|
||||
for (i=woptind; i<argc; i++)
|
||||
{
|
||||
int pid;
|
||||
wchar_t *end;
|
||||
errno=0;
|
||||
pid=fish_wcstoi(argv[i], &end, 10);
|
||||
if (errno || *end)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: '%ls' is not a job\n"),
|
||||
argv[0],
|
||||
argv[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
j = job_get_from_pid(pid);
|
||||
|
||||
if (j && !job_is_completed(j))
|
||||
{
|
||||
builtin_jobs_print(j, mode, !found);
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: No suitable job: %d\n"),
|
||||
argv[0],
|
||||
pid);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
job_iterator_t jobs;
|
||||
const job_t *j;
|
||||
while ((j = jobs.next()))
|
||||
{
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j))
|
||||
{
|
||||
builtin_jobs_print(j, mode, !found);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
append_format(stdout_buffer,
|
||||
_(L"%ls: There are no jobs\n"),
|
||||
argv[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
777
builtin_printf.cpp
Normal file
777
builtin_printf.cpp
Normal file
@@ -0,0 +1,777 @@
|
||||
/* printf - format and print data
|
||||
Copyright (C) 1990-2007 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/* Usage: printf format [argument...]
|
||||
|
||||
A front end to the printf function that lets it be used from the shell.
|
||||
|
||||
Backslash escapes:
|
||||
|
||||
\" = double quote
|
||||
\\ = backslash
|
||||
\a = alert (bell)
|
||||
\b = backspace
|
||||
\c = produce no further output
|
||||
\f = form feed
|
||||
\n = new line
|
||||
\r = carriage return
|
||||
\t = horizontal tab
|
||||
\v = vertical tab
|
||||
\ooo = octal number (ooo is 1 to 3 digits)
|
||||
\xhh = hexadecimal number (hhh is 1 to 2 digits)
|
||||
\uhhhh = 16-bit Unicode character (hhhh is 4 digits)
|
||||
\Uhhhhhhhh = 32-bit Unicode character (hhhhhhhh is 8 digits)
|
||||
|
||||
Additional directive:
|
||||
|
||||
%b = print an argument string, interpreting backslash escapes,
|
||||
except that octal escapes are of the form \0 or \0ooo.
|
||||
|
||||
The `format' argument is re-used as many times as necessary
|
||||
to convert all of the given arguments.
|
||||
|
||||
David MacKenzie <djm@gnu.ai.mit.edu> */
|
||||
|
||||
/* This file has been imported from source code of printf command in GNU Coreutils version 6.9 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
struct builtin_printf_state_t
|
||||
{
|
||||
/* The status of the operation */
|
||||
int exit_code;
|
||||
|
||||
/* Whether we should stop outputting. This gets set in the case of an error, and also with the \c escape. */
|
||||
bool early_exit;
|
||||
|
||||
builtin_printf_state_t() : exit_code(0), early_exit(false)
|
||||
{
|
||||
}
|
||||
|
||||
void verify_numeric(const wchar_t *s, const wchar_t *end, int errcode);
|
||||
|
||||
void print_direc(const wchar_t *start, size_t length, wchar_t conversion,
|
||||
bool have_field_width, int field_width,
|
||||
bool have_precision, int precision,
|
||||
wchar_t const *argument);
|
||||
|
||||
int print_formatted(const wchar_t *format, int argc, wchar_t **argv);
|
||||
|
||||
void fatal_error(const wchar_t *format, ...);
|
||||
|
||||
long print_esc(const wchar_t *escstart, bool octal_0);
|
||||
void print_esc_string(const wchar_t *str);
|
||||
void print_esc_char(wchar_t c);
|
||||
|
||||
void append_output(wchar_t c);
|
||||
void append_output(const wchar_t *c);
|
||||
void append_format_output(const wchar_t *fmt, ...);
|
||||
};
|
||||
|
||||
static bool is_octal_digit(wchar_t c)
|
||||
{
|
||||
return c != L'\0' && wcschr(L"01234567", c) != NULL;
|
||||
}
|
||||
|
||||
static bool is_hex_digit(wchar_t c)
|
||||
{
|
||||
return c != L'\0' && wcschr(L"0123456789ABCDEFabcdef", c) != NULL;
|
||||
}
|
||||
|
||||
static int hex_to_bin(const wchar_t &c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case L'0':
|
||||
return 0;
|
||||
case L'1':
|
||||
return 1;
|
||||
case L'2':
|
||||
return 2;
|
||||
case L'3':
|
||||
return 3;
|
||||
case L'4':
|
||||
return 4;
|
||||
case L'5':
|
||||
return 5;
|
||||
case L'6':
|
||||
return 6;
|
||||
case L'7':
|
||||
return 7;
|
||||
case L'8':
|
||||
return 8;
|
||||
case L'9':
|
||||
return 9;
|
||||
case L'a':
|
||||
case L'A':
|
||||
return 10;
|
||||
case L'b':
|
||||
case L'B':
|
||||
return 11;
|
||||
case L'c':
|
||||
case L'C':
|
||||
return 12;
|
||||
case L'd':
|
||||
case L'D':
|
||||
return 13;
|
||||
case L'e':
|
||||
case L'E':
|
||||
return 14;
|
||||
case L'f':
|
||||
case L'F':
|
||||
return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int octal_to_bin(wchar_t c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case L'0':
|
||||
return 0;
|
||||
case L'1':
|
||||
return 1;
|
||||
case L'2':
|
||||
return 2;
|
||||
case L'3':
|
||||
return 3;
|
||||
case L'4':
|
||||
return 4;
|
||||
case L'5':
|
||||
return 5;
|
||||
case L'6':
|
||||
return 6;
|
||||
case L'7':
|
||||
return 7;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* This message appears in N_() here rather than just in _() below because
|
||||
the sole use would have been in a #define. */
|
||||
static wchar_t const *const cfcc_msg =
|
||||
N_(L"warning: %ls: character(s) following character constant have been ignored");
|
||||
|
||||
double C_STRTOD(wchar_t const *nptr, wchar_t **endptr)
|
||||
{
|
||||
double r;
|
||||
|
||||
const wcstring saved_locale = wsetlocale(LC_NUMERIC, NULL);
|
||||
|
||||
if (!saved_locale.empty())
|
||||
{
|
||||
wsetlocale(LC_NUMERIC, L"C");
|
||||
}
|
||||
|
||||
r = wcstod(nptr, endptr);
|
||||
|
||||
if (!saved_locale.empty())
|
||||
{
|
||||
wsetlocale(LC_NUMERIC, saved_locale.c_str());
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline unsigned wchar_t to_uwchar_t(wchar_t ch)
|
||||
{
|
||||
return ch;
|
||||
}
|
||||
|
||||
void builtin_printf_state_t::fatal_error(const wchar_t *fmt, ...)
|
||||
{
|
||||
// Don't error twice
|
||||
if (early_exit)
|
||||
return;
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
wcstring errstr = vformat_string(fmt, va);
|
||||
va_end(va);
|
||||
stderr_buffer.append(errstr);
|
||||
if (! string_suffixes_string(L"\n", errstr))
|
||||
stderr_buffer.push_back(L'\n');
|
||||
|
||||
this->exit_code = STATUS_BUILTIN_ERROR;
|
||||
this->early_exit = true;
|
||||
}
|
||||
|
||||
void builtin_printf_state_t::append_output(wchar_t c)
|
||||
{
|
||||
// Don't output if we're done
|
||||
if (early_exit)
|
||||
return;
|
||||
|
||||
stdout_buffer.push_back(c);
|
||||
}
|
||||
|
||||
void builtin_printf_state_t::append_output(const wchar_t *c)
|
||||
{
|
||||
// Don't output if we're done
|
||||
if (early_exit)
|
||||
return;
|
||||
|
||||
stdout_buffer.append(c);
|
||||
}
|
||||
|
||||
void builtin_printf_state_t::append_format_output(const wchar_t *fmt, ...)
|
||||
{
|
||||
// Don't output if we're done
|
||||
if (early_exit)
|
||||
return;
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
append_formatv(stdout_buffer, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end, int errcode)
|
||||
{
|
||||
if (errcode != 0)
|
||||
{
|
||||
this->fatal_error(L"%ls: %s", s, strerror(errcode));
|
||||
}
|
||||
else if (*end)
|
||||
{
|
||||
if (s == end)
|
||||
this->fatal_error(_(L"%ls: expected a numeric value"), s);
|
||||
else
|
||||
this->fatal_error(_(L"%ls: value not completely converted"), s);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T raw_string_to_scalar_type(const wchar_t *s, wchar_t ** end);
|
||||
|
||||
// we use wcstoll instead of wcstoimax because FreeBSD 8 has busted wcstoumax and wcstoimax - see #626
|
||||
template<>
|
||||
intmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t ** end)
|
||||
{
|
||||
return wcstoll(s, end, 0);
|
||||
}
|
||||
|
||||
template<>
|
||||
uintmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t ** end)
|
||||
{
|
||||
return wcstoull(s, end, 0);
|
||||
}
|
||||
|
||||
template<>
|
||||
long double raw_string_to_scalar_type(const wchar_t *s, wchar_t ** end)
|
||||
{
|
||||
return C_STRTOD(s, end);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T string_to_scalar_type(const wchar_t *s, builtin_printf_state_t *state)
|
||||
{
|
||||
T val;
|
||||
if (*s == L'\"' || *s == L'\'')
|
||||
{
|
||||
unsigned wchar_t ch = *++s;
|
||||
val = ch;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t *end = NULL;
|
||||
errno = 0;
|
||||
val = raw_string_to_scalar_type<T>(s, &end);
|
||||
state->verify_numeric(s, end, errno);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Output a single-character \ escape. */
|
||||
|
||||
void builtin_printf_state_t::print_esc_char(wchar_t c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case L'a': /* Alert. */
|
||||
this->append_output(L'\a');
|
||||
break;
|
||||
case L'b': /* Backspace. */
|
||||
this->append_output(L'\b');
|
||||
break;
|
||||
case L'c': /* Cancel the rest of the output. */
|
||||
this->early_exit = true;
|
||||
break;
|
||||
case L'f': /* Form feed. */
|
||||
this->append_output(L'\f');
|
||||
break;
|
||||
case L'n': /* New line. */
|
||||
this->append_output(L'\n');
|
||||
break;
|
||||
case L'r': /* Carriage return. */
|
||||
this->append_output(L'\r');
|
||||
break;
|
||||
case L't': /* Horizontal tab. */
|
||||
this->append_output(L'\t');
|
||||
break;
|
||||
case L'v': /* Vertical tab. */
|
||||
this->append_output(L'\v');
|
||||
break;
|
||||
default:
|
||||
this->append_output(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a \ escape sequence starting at ESCSTART.
|
||||
Return the number of characters in the escape sequence
|
||||
besides the backslash.
|
||||
If OCTAL_0 is nonzero, octal escapes are of the form \0ooo, where o
|
||||
is an octal digit; otherwise they are of the form \ooo. */
|
||||
long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0)
|
||||
{
|
||||
const wchar_t *p = escstart + 1;
|
||||
int esc_value = 0; /* Value of \nnn escape. */
|
||||
int esc_length; /* Length of \nnn escape. */
|
||||
|
||||
if (*p == L'x')
|
||||
{
|
||||
/* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits. */
|
||||
for (esc_length = 0, ++p; esc_length < 2 && is_hex_digit(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hex_to_bin(*p);
|
||||
if (esc_length == 0)
|
||||
this->fatal_error(_(L"missing hexadecimal number in escape"));
|
||||
this->append_format_output(L"%lc", esc_value);
|
||||
}
|
||||
else if (is_octal_digit(*p))
|
||||
{
|
||||
/* Parse \0ooo (if octal_0 && *p == L'0') or \ooo (otherwise).
|
||||
Allow \ooo if octal_0 && *p != L'0'; this is an undocumented
|
||||
extension to POSIX that is compatible with Bash 2.05b. */
|
||||
for (esc_length = 0, p += octal_0 && *p == L'0'; esc_length < 3 && is_octal_digit(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octal_to_bin(*p);
|
||||
this->append_format_output(L"%c", esc_value);
|
||||
}
|
||||
else if (*p && wcschr(L"\"\\abcfnrtv", *p))
|
||||
print_esc_char(*p++);
|
||||
else if (*p == L'u' || *p == L'U')
|
||||
{
|
||||
wchar_t esc_char = *p;
|
||||
p++;
|
||||
uint32_t uni_value = 0;
|
||||
for (size_t esc_length = 0; esc_length < (esc_char == L'u' ? 4 : 8); esc_length++)
|
||||
{
|
||||
if (! is_hex_digit(*p))
|
||||
{
|
||||
/* Escape sequence must be done. Complain if we didn't get anything */
|
||||
if (esc_length == 0)
|
||||
{
|
||||
this->fatal_error(_(L"Missing hexadecimal number in Unicode escape"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
uni_value = uni_value * 16 + hex_to_bin(*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
/* PCA GNU printf respects the limitations described in ISO N717, about which universal characters "shall not" be specified. I believe this limitation is for the benefit of compilers; I see no reason to impose it in builtin_printf.
|
||||
|
||||
If __STDC_ISO_10646__ is defined, then it means wchar_t can and does hold Unicode code points, so just use that. If not defined, use the %lc printf conversion; this probably won't do anything good if your wide character set is not Unicode, but such platforms are exceedingly rare.
|
||||
*/
|
||||
if (uni_value > 0x10FFFF)
|
||||
{
|
||||
this->fatal_error(_(L"Unicode character out of range: \\%c%0*x"), esc_char, (esc_char == L'u' ? 4 : 8), uni_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(__STDC_ISO_10646__)
|
||||
this->append_output(uni_value);
|
||||
#else
|
||||
this->append_format_output(L"%lc", uni_value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->append_output(L'\\');
|
||||
if (*p)
|
||||
{
|
||||
this->append_output(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return p - escstart - 1;
|
||||
}
|
||||
|
||||
/* Print string STR, evaluating \ escapes. */
|
||||
|
||||
void builtin_printf_state_t::print_esc_string(const wchar_t *str)
|
||||
{
|
||||
for (; *str; str++)
|
||||
if (*str == L'\\')
|
||||
str += print_esc(str, true);
|
||||
else
|
||||
this->append_output(*str);
|
||||
}
|
||||
|
||||
/* Evaluate a printf conversion specification. START is the start of
|
||||
the directive, LENGTH is its length, and CONVERSION specifies the
|
||||
type of conversion. LENGTH does not include any length modifier or
|
||||
the conversion specifier itself. FIELD_WIDTH and PRECISION are the
|
||||
field width and precision for '*' values, if HAVE_FIELD_WIDTH and
|
||||
HAVE_PRECISION are true, respectively. ARGUMENT is the argument to
|
||||
be formatted. */
|
||||
|
||||
void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wchar_t conversion,
|
||||
bool have_field_width, int field_width,
|
||||
bool have_precision, int precision,
|
||||
wchar_t const *argument)
|
||||
{
|
||||
// Start with everything except the conversion specifier
|
||||
wcstring fmt(start, length);
|
||||
|
||||
/* Create a copy of the % directive, with an intmax_t-wide width modifier substituted for any existing integer length modifier. */
|
||||
switch (conversion)
|
||||
{
|
||||
case L'd':
|
||||
case L'i':
|
||||
case L'u':
|
||||
fmt.append(L"ll");
|
||||
break;
|
||||
case L'a':
|
||||
case L'e':
|
||||
case L'f':
|
||||
case L'g':
|
||||
case L'A':
|
||||
case L'E':
|
||||
case L'F':
|
||||
case L'G':
|
||||
fmt.append(L"L");
|
||||
break;
|
||||
case L's':
|
||||
fmt.append(L"l");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Append the conversion itself
|
||||
fmt.push_back(conversion);
|
||||
|
||||
switch (conversion)
|
||||
{
|
||||
case L'd':
|
||||
case L'i':
|
||||
{
|
||||
intmax_t arg = string_to_scalar_type<intmax_t>(argument, this);
|
||||
if (! have_field_width)
|
||||
{
|
||||
if (! have_precision)
|
||||
this->append_format_output(fmt.c_str(), arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! have_precision)
|
||||
this->append_format_output(fmt.c_str(), field_width, arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L'o':
|
||||
case L'u':
|
||||
case L'x':
|
||||
case L'X':
|
||||
{
|
||||
uintmax_t arg = string_to_scalar_type<uintmax_t>(argument, this);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
this->append_format_output(fmt.c_str(), arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
this->append_format_output(fmt.c_str(), field_width, arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L'a':
|
||||
case L'A':
|
||||
case L'e':
|
||||
case L'E':
|
||||
case L'f':
|
||||
case L'F':
|
||||
case L'g':
|
||||
case L'G':
|
||||
{
|
||||
long double arg = string_to_scalar_type<long double>(argument, this);
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
this->append_format_output(fmt.c_str(), arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), precision, arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
this->append_format_output(fmt.c_str(), field_width, arg);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), field_width, precision, arg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L'c':
|
||||
if (!have_field_width)
|
||||
this->append_format_output(fmt.c_str(), *argument);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), field_width, *argument);
|
||||
break;
|
||||
case L's':
|
||||
if (!have_field_width)
|
||||
{
|
||||
if (!have_precision)
|
||||
{
|
||||
this->append_format_output(fmt.c_str(), argument);
|
||||
}
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), precision, argument);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!have_precision)
|
||||
this->append_format_output(fmt.c_str(), field_width, argument);
|
||||
else
|
||||
this->append_format_output(fmt.c_str(), field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
arguments to any `%' directives.
|
||||
Return the number of elements of ARGV used. */
|
||||
|
||||
int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wchar_t **argv)
|
||||
{
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
const wchar_t *f; /* Pointer into `format'. */
|
||||
const wchar_t *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
bool have_field_width; /* True if FIELD_WIDTH is valid. */
|
||||
int field_width = 0; /* Arg to first '*'. */
|
||||
bool have_precision; /* True if PRECISION is valid. */
|
||||
int precision = 0; /* Arg to second '*'. */
|
||||
bool ok[UCHAR_MAX + 1] = { }; /* ok['x'] is true if %x is allowed. */
|
||||
|
||||
for (f = format; *f != L'\0'; ++f)
|
||||
{
|
||||
switch (*f)
|
||||
{
|
||||
case L'%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
have_field_width = have_precision = false;
|
||||
if (*f == L'%')
|
||||
{
|
||||
this->append_output(L'%');
|
||||
break;
|
||||
}
|
||||
if (*f == L'b')
|
||||
{
|
||||
/* FIXME: Field width and precision are not supported
|
||||
for %b, even though POSIX requires it. */
|
||||
if (argc > 0)
|
||||
{
|
||||
print_esc_string(*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E'] =
|
||||
ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o'] =
|
||||
ok['s'] = ok['u'] = ok['x'] = ok['X'] = true;
|
||||
|
||||
for (;; f++, direc_length++)
|
||||
{
|
||||
switch (*f)
|
||||
{
|
||||
case L'I':
|
||||
case L'\'':
|
||||
ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] =
|
||||
ok['o'] = ok['s'] = ok['x'] = ok['X'] = false;
|
||||
break;
|
||||
case '-':
|
||||
case '+':
|
||||
case ' ':
|
||||
break;
|
||||
case L'#':
|
||||
ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = false;
|
||||
break;
|
||||
case '0':
|
||||
ok['c'] = ok['s'] = false;
|
||||
break;
|
||||
default:
|
||||
goto no_more_flag_characters;
|
||||
}
|
||||
}
|
||||
no_more_flag_characters:
|
||||
;
|
||||
|
||||
if (*f == L'*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t width = string_to_scalar_type<intmax_t>(*argv, this);
|
||||
if (INT_MIN <= width && width <= INT_MAX)
|
||||
field_width = static_cast<int>(width);
|
||||
else
|
||||
this->fatal_error(_(L"invalid field width: %ls"), *argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
{
|
||||
field_width = 0;
|
||||
}
|
||||
have_field_width = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (iswdigit(*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == L'.')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
ok['c'] = false;
|
||||
if (*f == L'*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
intmax_t prec = string_to_scalar_type<intmax_t>(*argv, this);
|
||||
if (prec < 0)
|
||||
{
|
||||
/* A negative precision is taken as if the
|
||||
precision were omitted, so -1 is safe
|
||||
here even if prec < INT_MIN. */
|
||||
precision = -1;
|
||||
}
|
||||
else if (INT_MAX < prec)
|
||||
this->fatal_error(_(L"invalid precision: %ls"), *argv);
|
||||
else
|
||||
{
|
||||
precision = static_cast<int>(prec);
|
||||
}
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
{
|
||||
precision = 0;
|
||||
}
|
||||
have_precision = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (iswdigit(*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (*f == L'l' || *f == L'L' || *f == L'h' || *f == L'j' || *f == L't' || *f == L'z')
|
||||
++f;
|
||||
|
||||
{
|
||||
unsigned wchar_t conversion = *f;
|
||||
if (! ok[conversion])
|
||||
{
|
||||
this->fatal_error(_(L"%.*ls: invalid conversion specification"), (int)(f + 1 - direc_start), direc_start);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
print_direc(direc_start, direc_length, *f,
|
||||
have_field_width, field_width,
|
||||
have_precision, precision,
|
||||
(argc <= 0 ? L"" : (argc--, *argv++)));
|
||||
break;
|
||||
|
||||
case L'\\':
|
||||
f += print_esc(f, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
this->append_output(*f);
|
||||
}
|
||||
}
|
||||
return save_argc - argc;
|
||||
}
|
||||
|
||||
static int builtin_printf(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
builtin_printf_state_t state;
|
||||
|
||||
wchar_t *format;
|
||||
int args_used;
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
if (argc <= 1)
|
||||
{
|
||||
state.fatal_error(_(L"printf: not enough arguments"));
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
do
|
||||
{
|
||||
args_used = state.print_formatted(format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0 && ! state.early_exit);
|
||||
return state.exit_code;
|
||||
}
|
||||
879
builtin_set.c
879
builtin_set.c
@@ -1,879 +0,0 @@
|
||||
/** \file builtin_set.c Functions defining the set builtin
|
||||
|
||||
Functions used for implementing the set builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "env.h"
|
||||
#include "expand.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
/**
|
||||
Error message for invalid path operations
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_ERROR L"%ls: Could not add component %ls to %ls.\n"
|
||||
|
||||
/**
|
||||
Hint for invalid path operation with a colon
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
|
||||
|
||||
/**
|
||||
Error for mismatch between index count and elements
|
||||
*/
|
||||
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
|
||||
|
||||
/**
|
||||
Test if the specified variable should be subject to path validation
|
||||
*/
|
||||
static int is_path_variable( const wchar_t *env )
|
||||
{
|
||||
return contains( env,
|
||||
L"PATH",
|
||||
L"CDPATH" );
|
||||
}
|
||||
|
||||
/**
|
||||
Call env_set. If this is a path variable, e.g. PATH, validate the
|
||||
elements. On error, print a description of the problem to stderr.
|
||||
*/
|
||||
static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
||||
{
|
||||
string_buffer_t sb;
|
||||
int i;
|
||||
int retcode = 0;
|
||||
wchar_t *val_str=0;
|
||||
|
||||
if( is_path_variable( key ) )
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
for( i=0; i<al_get_count( val ); i++ )
|
||||
{
|
||||
int show_perror = 0;
|
||||
int show_hint = 0;
|
||||
|
||||
struct stat buff;
|
||||
wchar_t *dir = (wchar_t *)al_get( val, i );
|
||||
|
||||
if( wstat( dir, &buff ) )
|
||||
{
|
||||
error = 1;
|
||||
show_perror = 1;
|
||||
}
|
||||
|
||||
if( !( S_ISDIR(buff.st_mode) ) )
|
||||
{
|
||||
error = 1;
|
||||
|
||||
}
|
||||
|
||||
if( error )
|
||||
{
|
||||
wchar_t *colon;
|
||||
|
||||
sb_printf( sb_err,
|
||||
_(BUILTIN_SET_PATH_ERROR),
|
||||
L"set",
|
||||
dir,
|
||||
key );
|
||||
|
||||
colon = wcschr( dir, L':' );
|
||||
|
||||
if( colon && *(colon+1) )
|
||||
{
|
||||
show_hint = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( show_perror )
|
||||
{
|
||||
builtin_wperror( L"set" );
|
||||
}
|
||||
|
||||
if( show_hint )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(BUILTIN_SET_PATH_HINT),
|
||||
L"set",
|
||||
key,
|
||||
key,
|
||||
wcschr( dir, L':' )+1);
|
||||
}
|
||||
|
||||
if( error )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( error )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sb_init( &sb );
|
||||
|
||||
if( al_get_count( val ) )
|
||||
{
|
||||
for( i=0; i<al_get_count( val ); i++ )
|
||||
{
|
||||
wchar_t *next =(wchar_t *)al_get( val, i );
|
||||
sb_append( &sb, next?next:L"" );
|
||||
if( i<al_get_count( val )-1 )
|
||||
{
|
||||
sb_append( &sb, ARRAY_SEP_STR );
|
||||
}
|
||||
}
|
||||
val_str = (wchar_t *)sb.buff;
|
||||
|
||||
}
|
||||
|
||||
switch( env_set( key, val_str, scope | ENV_USER ) )
|
||||
{
|
||||
case ENV_PERM:
|
||||
{
|
||||
sb_printf( sb_err, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key );
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
|
||||
case ENV_INVALID:
|
||||
{
|
||||
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sb_destroy( &sb );
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/**
|
||||
Extract indexes from a destination argument of the form name[index1 index2...]
|
||||
|
||||
\param indexes the list to insert the new indexes into
|
||||
\param src the source string to parse
|
||||
\param name the name of the element. Return null if the name in \c src does not match this name
|
||||
\param var_count the number of elements in the array to parse.
|
||||
|
||||
\return the total number of indexes parsed, or -1 on error
|
||||
*/
|
||||
static int parse_index( array_list_t *indexes,
|
||||
const wchar_t *src,
|
||||
const wchar_t *name,
|
||||
int var_count )
|
||||
{
|
||||
int len;
|
||||
|
||||
int count = 0;
|
||||
const wchar_t *src_orig = src;
|
||||
|
||||
if (src == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
if (*src != L'[')
|
||||
{
|
||||
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = src-src_orig;
|
||||
|
||||
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
|
||||
L"set",
|
||||
name,
|
||||
len,
|
||||
src_orig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
src++;
|
||||
|
||||
while (iswspace(*src))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
while (*src != L']')
|
||||
{
|
||||
wchar_t *end;
|
||||
|
||||
long l_ind;
|
||||
|
||||
errno = 0;
|
||||
|
||||
l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if( end==src || errno )
|
||||
{
|
||||
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( l_ind < 0 )
|
||||
{
|
||||
l_ind = var_count+l_ind+1;
|
||||
}
|
||||
|
||||
al_push_long(indexes, l_ind);
|
||||
src = end;
|
||||
count++;
|
||||
while (iswspace(*src)) src++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Update a list \c list by writing copies (using wcsdup) of the
|
||||
values specified by \c values to the indexes specified by \c
|
||||
indexes. The previous entries at the specidied position will be
|
||||
free'd.
|
||||
|
||||
\return 0 if the operation was successfull, non-zero otherwise
|
||||
*/
|
||||
static int update_values( array_list_t *list,
|
||||
array_list_t *indexes,
|
||||
array_list_t *values )
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Replace values where needed */
|
||||
for( i = 0; i < al_get_count(indexes); i++ )
|
||||
{
|
||||
/*
|
||||
The '- 1' below is because the indices in fish are
|
||||
one-based, but the array_list_t uses zero-based indices
|
||||
*/
|
||||
long ind = al_get_long(indexes, i) - 1;
|
||||
void *new = (void *) al_get(values, i);
|
||||
if( ind < 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
free((void *) al_get(list, ind));
|
||||
al_set(list, ind, new != 0 ? wcsdup(new) : wcsdup(L""));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Return 1 if an array list of longs contains the specified
|
||||
value, 0 otherwise
|
||||
*/
|
||||
static int al_contains_long( array_list_t *list,
|
||||
long val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < al_get_count(list); i++)
|
||||
{
|
||||
long current = al_get_long(list, i);
|
||||
if( current != 0 && current == val )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Erase from a list values at specified indexes
|
||||
*/
|
||||
static void erase_values(array_list_t *list, array_list_t *indexes)
|
||||
{
|
||||
long i;
|
||||
array_list_t result;
|
||||
|
||||
al_init(&result);
|
||||
|
||||
for (i = 0; i < al_get_count(list); i++)
|
||||
{
|
||||
if (!al_contains_long(indexes, i + 1))
|
||||
{
|
||||
al_push(&result, al_get(list, i));
|
||||
}
|
||||
else
|
||||
{
|
||||
free( (void *)al_get(list, i));
|
||||
}
|
||||
}
|
||||
|
||||
al_truncate(list,0);
|
||||
al_push_all( list, &result );
|
||||
al_destroy(&result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Print the names of all environment variables in the scope, with or without values,
|
||||
with or without escaping
|
||||
*/
|
||||
static void print_variables(int include_values, int esc, int scope)
|
||||
{
|
||||
array_list_t names;
|
||||
int i;
|
||||
|
||||
al_init( &names );
|
||||
env_get_names( &names, scope );
|
||||
|
||||
sort_list( &names );
|
||||
|
||||
for( i = 0; i < al_get_count(&names); i++ )
|
||||
{
|
||||
wchar_t *key = (wchar_t *)al_get( &names, i );
|
||||
wchar_t *e_key = esc ? escape(key, 0) : wcsdup(key);
|
||||
|
||||
sb_append(sb_out, e_key);
|
||||
|
||||
if( include_values )
|
||||
{
|
||||
wchar_t *value = env_get(key);
|
||||
wchar_t *e_value;
|
||||
if( value )
|
||||
{
|
||||
int shorten = 0;
|
||||
|
||||
if( wcslen( value ) > 64 )
|
||||
{
|
||||
shorten = 1;
|
||||
value = wcsndup( value, 60 );
|
||||
if( !value )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
}
|
||||
|
||||
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
|
||||
|
||||
sb_append(sb_out, L" ", e_value, (void *)0);
|
||||
free(e_value);
|
||||
|
||||
if( shorten )
|
||||
{
|
||||
sb_append(sb_out, L"\u2026");
|
||||
free( value );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sb_append(sb_out, L"\n");
|
||||
free(e_key);
|
||||
}
|
||||
al_destroy(&names);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The set builtin. Creates, updates and erases environment variables
|
||||
and environemnt variable arrays.
|
||||
*/
|
||||
static int builtin_set( wchar_t **argv )
|
||||
{
|
||||
|
||||
/**
|
||||
Variables used for parsing the argument list
|
||||
*/
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"export", no_argument, 0, 'x'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"global", no_argument, 0, 'g'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"local", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"erase", no_argument, 0, 'e'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"names", no_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"unexport", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"universal", no_argument, 0, 'U'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"query", no_argument, 0, 'q'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
const wchar_t *short_options = L"+xglenuUqh";
|
||||
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
/*
|
||||
Flags to set the work mode
|
||||
*/
|
||||
int local = 0, global = 0, export = 0;
|
||||
int erase = 0, list = 0, unexport=0;
|
||||
int universal = 0, query=0;
|
||||
|
||||
|
||||
/*
|
||||
Variables used for performing the actual work
|
||||
*/
|
||||
wchar_t *dest = 0;
|
||||
int retcode=0;
|
||||
int scope;
|
||||
int slice=0;
|
||||
int i;
|
||||
|
||||
wchar_t *bad_char;
|
||||
|
||||
|
||||
/* Parse options to obtain the requested operation and the modifiers */
|
||||
woptind = 0;
|
||||
while (1)
|
||||
{
|
||||
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
|
||||
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch(c)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
erase = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
list = 1;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
export = 1;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
local = 1;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
global = 1;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
unexport = 1;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
universal = 1;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
query = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help( argv[0], sb_out );
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Ok, all arguments have been parsed, let's validate them
|
||||
*/
|
||||
|
||||
/*
|
||||
If we are checking the existance of a variable (-q) we can not
|
||||
also specify scope
|
||||
*/
|
||||
|
||||
if( query && (erase || list || global || local || universal || export || unexport ) )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* We can't both list and erase varaibles */
|
||||
if( erase && list )
|
||||
{
|
||||
sb_printf(sb_err,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Variables can only have one scope
|
||||
*/
|
||||
if( local + global + universal > 1 )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_GLOCAL,
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Variables can only have one export status
|
||||
*/
|
||||
if( export && unexport )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_EXPUNEXP,
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate the scope value for variable assignement
|
||||
*/
|
||||
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (export ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
|
||||
|
||||
if( query )
|
||||
{
|
||||
/*
|
||||
Query mode. Return the number of variables that do not exist
|
||||
out of the specified variables.
|
||||
*/
|
||||
int i;
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
wchar_t *arg = argv[i];
|
||||
int slice=0;
|
||||
|
||||
if( !(dest = wcsdup(arg)))
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if( wcschr( dest, L'[' ) )
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr( dest, L'[' )=0;
|
||||
}
|
||||
|
||||
if( slice )
|
||||
{
|
||||
array_list_t indexes;
|
||||
array_list_t result;
|
||||
int j;
|
||||
|
||||
al_init( &result );
|
||||
al_init( &indexes );
|
||||
|
||||
tokenize_variable_array( env_get( dest ), &result );
|
||||
|
||||
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
for( j=0; j<al_get_count( &indexes ); j++ )
|
||||
{
|
||||
long idx = al_get_long( &indexes, j );
|
||||
if( idx < 1 || idx > al_get_count( &result ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !env_exist( arg, scope ) )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
|
||||
free( dest );
|
||||
|
||||
}
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if( list )
|
||||
{
|
||||
/* Maybe we should issue an error if there are any other arguments? */
|
||||
print_variables(0, 0, scope);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( woptind == argc )
|
||||
{
|
||||
/*
|
||||
Print values of variables
|
||||
*/
|
||||
|
||||
if( erase )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Erase needs a variable name\n%ls\n"),
|
||||
argv[0] );
|
||||
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
print_variables( 1, 1, scope );
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if( !(dest = wcsdup(argv[woptind])))
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if( wcschr( dest, L'[' ) )
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr( dest, L'[' )=0;
|
||||
}
|
||||
|
||||
if( !wcslen( dest ) )
|
||||
{
|
||||
free( dest );
|
||||
sb_printf( sb_err, BUILTIN_ERR_VARNAME_ZERO, argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( (bad_char = wcsvarname( dest ) ) )
|
||||
{
|
||||
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
free( dest );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( slice && erase && (scope != ENV_USER) )
|
||||
{
|
||||
free( dest );
|
||||
sb_printf( sb_err, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
set assignment can work in two modes, either using slices or
|
||||
using the whole array. We detect which mode is used here.
|
||||
*/
|
||||
|
||||
if( slice )
|
||||
{
|
||||
|
||||
/*
|
||||
Slice mode
|
||||
*/
|
||||
int idx_count, val_count;
|
||||
array_list_t values;
|
||||
array_list_t indexes;
|
||||
array_list_t result;
|
||||
|
||||
al_init(&values);
|
||||
al_init(&indexes);
|
||||
al_init(&result);
|
||||
|
||||
tokenize_variable_array( env_get(dest), &result );
|
||||
|
||||
for( ; woptind<argc; woptind++ )
|
||||
{
|
||||
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
val_count = argc-woptind-1;
|
||||
idx_count = al_get_count( &indexes );
|
||||
|
||||
if( !erase )
|
||||
{
|
||||
if( val_count < idx_count )
|
||||
{
|
||||
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
if( val_count == idx_count )
|
||||
{
|
||||
woptind++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !retcode )
|
||||
{
|
||||
/*
|
||||
Slice indexes have been calculated, do the actual work
|
||||
*/
|
||||
|
||||
if( erase )
|
||||
{
|
||||
erase_values(&result, &indexes);
|
||||
my_env_set( dest, &result, scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
array_list_t value;
|
||||
al_init(&value);
|
||||
|
||||
while( woptind < argc )
|
||||
{
|
||||
al_push(&value, argv[woptind++]);
|
||||
}
|
||||
|
||||
if( update_values( &result,
|
||||
&indexes,
|
||||
&value ) )
|
||||
{
|
||||
sb_printf( sb_err, L"%ls: ", argv[0] );
|
||||
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
|
||||
sb_append( sb_err, L"\n" );
|
||||
}
|
||||
|
||||
my_env_set(dest,
|
||||
&result,
|
||||
scope);
|
||||
|
||||
al_destroy( &value );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
al_foreach( &result, &free );
|
||||
al_destroy( &result );
|
||||
|
||||
al_destroy(&indexes);
|
||||
al_destroy(&values);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
woptind++;
|
||||
|
||||
/*
|
||||
No slicing
|
||||
*/
|
||||
if( erase )
|
||||
{
|
||||
if( woptind != argc )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Values cannot be specfied with erase\n"),
|
||||
argv[0] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
retcode = env_remove( dest, scope );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array_list_t val;
|
||||
al_init( &val );
|
||||
|
||||
for( i=woptind; i<argc; i++ )
|
||||
{
|
||||
al_push( &val, argv[i] );
|
||||
}
|
||||
|
||||
retcode = my_env_set( dest, &val, scope );
|
||||
|
||||
al_destroy( &val );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
free( dest );
|
||||
|
||||
return retcode;
|
||||
|
||||
}
|
||||
|
||||
811
builtin_set.cpp
Normal file
811
builtin_set.cpp
Normal file
@@ -0,0 +1,811 @@
|
||||
/** \file builtin_set.c Functions defining the set builtin
|
||||
|
||||
Functions used for implementing the set builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "wutil.h"
|
||||
#include "builtin.h"
|
||||
#include "env.h"
|
||||
#include "expand.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
#include "proc.h"
|
||||
#include "parser.h"
|
||||
|
||||
/* We know about these buffers */
|
||||
extern wcstring stdout_buffer, stderr_buffer;
|
||||
|
||||
/**
|
||||
Error message for invalid path operations
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_ERROR L"%ls: Warning: path component %ls may not be valid in %ls.\n"
|
||||
|
||||
/**
|
||||
Hint for invalid path operation with a colon
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
|
||||
|
||||
/**
|
||||
Error for mismatch between index count and elements
|
||||
*/
|
||||
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
|
||||
|
||||
/**
|
||||
Test if the specified variable should be subject to path validation
|
||||
*/
|
||||
static int is_path_variable(const wchar_t *env)
|
||||
{
|
||||
return contains(env, L"PATH", L"CDPATH");
|
||||
}
|
||||
|
||||
/**
|
||||
Call env_set. If this is a path variable, e.g. PATH, validate the
|
||||
elements. On error, print a description of the problem to stderr.
|
||||
*/
|
||||
static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope)
|
||||
{
|
||||
size_t i;
|
||||
int retcode = 0;
|
||||
const wchar_t *val_str=NULL;
|
||||
|
||||
if (is_path_variable(key))
|
||||
{
|
||||
/* Fix for https://github.com/fish-shell/fish-shell/issues/199 . Return success if any path setting succeeds. */
|
||||
bool any_success = false;
|
||||
|
||||
/* Don't bother validating (or complaining about) values that are already present */
|
||||
wcstring_list_t existing_values;
|
||||
const env_var_t existing_variable = env_get_string(key);
|
||||
if (! existing_variable.missing_or_empty())
|
||||
tokenize_variable_array(existing_variable, existing_values);
|
||||
|
||||
for (i=0; i< val.size() ; i++)
|
||||
{
|
||||
const wcstring &dir = val.at(i);
|
||||
if (list_contains_string(existing_values, dir))
|
||||
{
|
||||
any_success = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool show_perror = false;
|
||||
int show_hint = 0;
|
||||
bool error = false;
|
||||
|
||||
struct stat buff;
|
||||
if (wstat(dir, &buff))
|
||||
{
|
||||
error = true;
|
||||
show_perror = true;
|
||||
}
|
||||
|
||||
if (!(S_ISDIR(buff.st_mode)))
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (!error)
|
||||
{
|
||||
any_success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stderr_buffer, _(BUILTIN_SET_PATH_ERROR), L"set", dir.c_str(), key);
|
||||
const wchar_t *colon = wcschr(dir.c_str(), L':');
|
||||
|
||||
if (colon && *(colon+1))
|
||||
{
|
||||
show_hint = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (show_perror)
|
||||
{
|
||||
builtin_wperror(L"set");
|
||||
}
|
||||
|
||||
if (show_hint)
|
||||
{
|
||||
append_format(stderr_buffer, _(BUILTIN_SET_PATH_HINT), L"set", key, key, wcschr(dir.c_str(), L':')+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Fail at setting the path if we tried to set it to something non-empty, but it wound up empty. */
|
||||
if (! val.empty() && ! any_success)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wcstring sb;
|
||||
if (! val.empty())
|
||||
{
|
||||
for (i=0; i< val.size() ; i++)
|
||||
{
|
||||
sb.append(val[i]);
|
||||
if (i<val.size() - 1)
|
||||
{
|
||||
sb.append(ARRAY_SEP_STR);
|
||||
}
|
||||
}
|
||||
val_str = sb.c_str();
|
||||
}
|
||||
|
||||
switch (env_set(key, val_str, scope | ENV_USER))
|
||||
{
|
||||
case ENV_PERM:
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key);
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
|
||||
case ENV_INVALID:
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set");
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Extract indexes from a destination argument of the form name[index1 index2...]
|
||||
|
||||
\param indexes the list to insert the new indexes into
|
||||
\param src the source string to parse
|
||||
\param name the name of the element. Return null if the name in \c src does not match this name
|
||||
\param var_count the number of elements in the array to parse.
|
||||
|
||||
\return the total number of indexes parsed, or -1 on error
|
||||
*/
|
||||
static int parse_index(std::vector<long> &indexes,
|
||||
const wchar_t *src,
|
||||
const wchar_t *name,
|
||||
size_t var_count)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
int count = 0;
|
||||
const wchar_t *src_orig = src;
|
||||
|
||||
if (src == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
if (*src != L'[')
|
||||
{
|
||||
append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), L"set");
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = src-src_orig;
|
||||
|
||||
if ((wcsncmp(src_orig, name, len)!=0) || (wcslen(name) != (len)))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
|
||||
L"set",
|
||||
name,
|
||||
len,
|
||||
src_orig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
src++;
|
||||
|
||||
while (iswspace(*src))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
while (*src != L']')
|
||||
{
|
||||
wchar_t *end;
|
||||
|
||||
long l_ind;
|
||||
|
||||
errno = 0;
|
||||
|
||||
l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if (end==src || errno)
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (l_ind < 0)
|
||||
{
|
||||
l_ind = var_count+l_ind+1;
|
||||
}
|
||||
|
||||
src = end;
|
||||
if (*src==L'.' && *(src+1)==L'.')
|
||||
{
|
||||
src+=2;
|
||||
long l_ind2 = wcstol(src, &end, 10);
|
||||
if (end==src || errno)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
src = end;
|
||||
|
||||
if (l_ind2 < 0)
|
||||
{
|
||||
l_ind2 = var_count+l_ind2+1;
|
||||
}
|
||||
int direction = l_ind2<l_ind ? -1 : 1 ;
|
||||
for (long jjj = l_ind; jjj*direction <= l_ind2*direction; jjj+=direction)
|
||||
{
|
||||
// debug(0, L"Expand range [set]: %i\n", jjj);
|
||||
indexes.push_back(jjj);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
indexes.push_back(l_ind);
|
||||
count++;
|
||||
}
|
||||
while (iswspace(*src)) src++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int update_values(wcstring_list_t &list,
|
||||
std::vector<long> &indexes,
|
||||
wcstring_list_t &values)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* Replace values where needed */
|
||||
for (i = 0; i < indexes.size(); i++)
|
||||
{
|
||||
/*
|
||||
The '- 1' below is because the indices in fish are
|
||||
one-based, but the vector uses zero-based indices
|
||||
*/
|
||||
long ind = indexes[i] - 1;
|
||||
const wcstring newv = values[ i ];
|
||||
if (ind < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if ((size_t)ind >= list.size())
|
||||
{
|
||||
list.resize(ind+1);
|
||||
}
|
||||
|
||||
// free((void *) al_get(list, ind));
|
||||
list[ ind ] = newv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Erase from a list of wcstring values at specified indexes
|
||||
*/
|
||||
static void erase_values(wcstring_list_t &list, const std::vector<long> &indexes)
|
||||
{
|
||||
// Make a set of indexes.
|
||||
// This both sorts them into ascending order and removes duplicates.
|
||||
const std::set<long> indexes_set(indexes.begin(), indexes.end());
|
||||
|
||||
// Now walk the set backwards, so we encounter larger indexes first, and remove elements at the given (1-based) indexes.
|
||||
std::set<long>::const_reverse_iterator iter;
|
||||
for (iter = indexes_set.rbegin(); iter != indexes_set.rend(); ++iter)
|
||||
{
|
||||
long val = *iter;
|
||||
if (val > 0 && (size_t)val <= list.size())
|
||||
{
|
||||
// One-based indexing!
|
||||
list.erase(list.begin() + val - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Print the names of all environment variables in the scope, with or without shortening,
|
||||
with or without values, with or without escaping
|
||||
*/
|
||||
static void print_variables(int include_values, int esc, bool shorten_ok, int scope)
|
||||
{
|
||||
wcstring_list_t names = env_get_names(scope);
|
||||
sort(names.begin(), names.end());
|
||||
|
||||
for (size_t i = 0; i < names.size(); i++)
|
||||
{
|
||||
const wcstring key = names.at(i);
|
||||
const wcstring e_key = escape_string(key, 0);
|
||||
|
||||
stdout_buffer.append(e_key);
|
||||
|
||||
if (include_values)
|
||||
{
|
||||
env_var_t value = env_get_string(key);
|
||||
if (!value.missing())
|
||||
{
|
||||
int shorten = 0;
|
||||
|
||||
if (shorten_ok && value.length() > 64)
|
||||
{
|
||||
shorten = 1;
|
||||
value.resize(60);
|
||||
}
|
||||
|
||||
wcstring e_value = esc ? expand_escape_variable(value) : value;
|
||||
|
||||
stdout_buffer.append(L" ");
|
||||
stdout_buffer.append(e_value);
|
||||
|
||||
if (shorten)
|
||||
{
|
||||
stdout_buffer.push_back(ellipsis_char);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
stdout_buffer.append(L"\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The set builtin. Creates, updates and erases environment variables
|
||||
and environemnt variable arrays.
|
||||
*/
|
||||
static int builtin_set(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
/** Variables used for parsing the argument list */
|
||||
const struct woption long_options[] =
|
||||
{
|
||||
{ L"export", no_argument, 0, 'x' },
|
||||
{ L"global", no_argument, 0, 'g' },
|
||||
{ L"local", no_argument, 0, 'l' },
|
||||
{ L"erase", no_argument, 0, 'e' },
|
||||
{ L"names", no_argument, 0, 'n' },
|
||||
{ L"unexport", no_argument, 0, 'u' },
|
||||
{ L"universal", no_argument, 0, 'U' },
|
||||
{ L"long", no_argument, 0, 'L' },
|
||||
{ L"query", no_argument, 0, 'q' },
|
||||
{ L"help", no_argument, 0, 'h' },
|
||||
{ 0, 0, 0, 0 }
|
||||
} ;
|
||||
|
||||
const wchar_t *short_options = L"+xglenuULqh";
|
||||
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
/*
|
||||
Flags to set the work mode
|
||||
*/
|
||||
int local = 0, global = 0, exportv = 0;
|
||||
int erase = 0, list = 0, unexport=0;
|
||||
int universal = 0, query=0;
|
||||
bool shorten_ok = true;
|
||||
bool preserve_incoming_failure_exit_status = true;
|
||||
const int incoming_exit_status = proc_get_last_status();
|
||||
|
||||
/*
|
||||
Variables used for performing the actual work
|
||||
*/
|
||||
wchar_t *dest = 0;
|
||||
int retcode=0;
|
||||
int scope;
|
||||
int slice=0;
|
||||
int i;
|
||||
|
||||
wchar_t *bad_char;
|
||||
|
||||
|
||||
/* Parse options to obtain the requested operation and the modifiers */
|
||||
woptind = 0;
|
||||
while (1)
|
||||
{
|
||||
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
|
||||
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
erase = 1;
|
||||
preserve_incoming_failure_exit_status = false;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
list = 1;
|
||||
preserve_incoming_failure_exit_status = false;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
exportv = 1;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
local = 1;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
global = 1;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
unexport = 1;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
universal = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
shorten_ok = false;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
query = 1;
|
||||
preserve_incoming_failure_exit_status = false;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
|
||||
case '?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Ok, all arguments have been parsed, let's validate them
|
||||
*/
|
||||
|
||||
/*
|
||||
If we are checking the existance of a variable (-q) we can not
|
||||
also specify scope
|
||||
*/
|
||||
|
||||
if (query && (erase || list))
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* We can't both list and erase varaibles */
|
||||
if (erase && list)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_COMBO,
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Variables can only have one scope
|
||||
*/
|
||||
if (local + global + universal > 1)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_GLOCAL,
|
||||
argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Variables can only have one export status
|
||||
*/
|
||||
if (exportv && unexport)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_EXPUNEXP,
|
||||
argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate the scope value for variable assignement
|
||||
*/
|
||||
scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER;
|
||||
|
||||
if (query)
|
||||
{
|
||||
/*
|
||||
Query mode. Return the number of variables that do not exist
|
||||
out of the specified variables.
|
||||
*/
|
||||
int i;
|
||||
for (i=woptind; i<argc; i++)
|
||||
{
|
||||
wchar_t *arg = argv[i];
|
||||
int slice=0;
|
||||
|
||||
if (!(dest = wcsdup(arg)))
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if (wcschr(dest, L'['))
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr(dest, L'[')=0;
|
||||
}
|
||||
|
||||
if (slice)
|
||||
{
|
||||
std::vector<long> indexes;
|
||||
wcstring_list_t result;
|
||||
size_t j;
|
||||
|
||||
env_var_t dest_str = env_get_string(dest);
|
||||
if (! dest_str.missing())
|
||||
tokenize_variable_array(dest_str, result);
|
||||
|
||||
if (!parse_index(indexes, arg, dest, result.size()))
|
||||
{
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
for (j=0; j < indexes.size() ; j++)
|
||||
{
|
||||
long idx = indexes[j];
|
||||
if (idx < 1 || (size_t)idx > result.size())
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!env_exist(arg, scope))
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
}
|
||||
|
||||
free(dest);
|
||||
|
||||
}
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if (list)
|
||||
{
|
||||
/* Maybe we should issue an error if there are any other arguments? */
|
||||
print_variables(0, 0, shorten_ok, scope);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (woptind == argc)
|
||||
{
|
||||
/*
|
||||
Print values of variables
|
||||
*/
|
||||
|
||||
if (erase)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Erase needs a variable name\n"),
|
||||
argv[0]);
|
||||
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
retcode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
print_variables(1, 1, shorten_ok, scope);
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if (!(dest = wcsdup(argv[woptind])))
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
if (wcschr(dest, L'['))
|
||||
{
|
||||
slice = 1;
|
||||
*wcschr(dest, L'[')=0;
|
||||
}
|
||||
|
||||
if (!wcslen(dest))
|
||||
{
|
||||
free(dest);
|
||||
append_format(stderr_buffer, BUILTIN_ERR_VARNAME_ZERO, argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((bad_char = wcsvarname(dest)))
|
||||
{
|
||||
append_format(stderr_buffer, BUILTIN_ERR_VARCHAR, argv[0], *bad_char);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
free(dest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (slice && erase && (scope != ENV_USER))
|
||||
{
|
||||
free(dest);
|
||||
append_format(stderr_buffer, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
set assignment can work in two modes, either using slices or
|
||||
using the whole array. We detect which mode is used here.
|
||||
*/
|
||||
|
||||
if (slice)
|
||||
{
|
||||
|
||||
/*
|
||||
Slice mode
|
||||
*/
|
||||
size_t idx_count, val_count;
|
||||
wcstring_list_t values;
|
||||
std::vector<long> indexes;
|
||||
wcstring_list_t result;
|
||||
|
||||
const env_var_t dest_str = env_get_string(dest);
|
||||
if (! dest_str.missing())
|
||||
tokenize_variable_array(dest_str, result);
|
||||
|
||||
for (; woptind<argc; woptind++)
|
||||
{
|
||||
if (!parse_index(indexes, argv[woptind], dest, result.size()))
|
||||
{
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
retcode = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
val_count = argc-woptind-1;
|
||||
idx_count = indexes.size();
|
||||
|
||||
if (!erase)
|
||||
{
|
||||
if (val_count < idx_count)
|
||||
{
|
||||
append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
retcode=1;
|
||||
break;
|
||||
}
|
||||
if (val_count == idx_count)
|
||||
{
|
||||
woptind++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!retcode)
|
||||
{
|
||||
/*
|
||||
Slice indexes have been calculated, do the actual work
|
||||
*/
|
||||
|
||||
if (erase)
|
||||
{
|
||||
erase_values(result, indexes);
|
||||
my_env_set(dest, result, scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
wcstring_list_t value;
|
||||
|
||||
while (woptind < argc)
|
||||
{
|
||||
value.push_back(argv[woptind++]);
|
||||
}
|
||||
|
||||
if (update_values(result,
|
||||
indexes,
|
||||
value))
|
||||
{
|
||||
append_format(stderr_buffer, L"%ls: ", argv[0]);
|
||||
append_format(stderr_buffer, ARRAY_BOUNDS_ERR);
|
||||
stderr_buffer.push_back(L'\n');
|
||||
}
|
||||
|
||||
my_env_set(dest, result, scope);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
woptind++;
|
||||
|
||||
/*
|
||||
No slicing
|
||||
*/
|
||||
if (erase)
|
||||
{
|
||||
if (woptind != argc)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Values cannot be specfied with erase\n"),
|
||||
argv[0]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
retcode=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
retcode = env_remove(dest, scope);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wcstring_list_t val;
|
||||
for (i=woptind; i<argc; i++)
|
||||
val.push_back(argv[i]);
|
||||
retcode = my_env_set(dest, val, scope);
|
||||
}
|
||||
}
|
||||
|
||||
free(dest);
|
||||
|
||||
if (retcode == STATUS_BUILTIN_OK && preserve_incoming_failure_exit_status)
|
||||
retcode = incoming_exit_status;
|
||||
return retcode;
|
||||
|
||||
}
|
||||
|
||||
243
builtin_set_color.cpp
Normal file
243
builtin_set_color.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
/** \file builtin_set_color.cpp Functions defining the set_color builtin
|
||||
|
||||
Functions used for implementing the set_color builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include "builtin.h"
|
||||
#include "color.h"
|
||||
#include "output.h"
|
||||
|
||||
#if HAVE_NCURSES_H
|
||||
#include <ncurses.h>
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_TERM_H
|
||||
#include <term.h>
|
||||
#elif HAVE_NCURSES_TERM_H
|
||||
#include <ncurses/term.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* We know about these buffers */
|
||||
extern wcstring stdout_buffer, stderr_buffer;
|
||||
|
||||
/**
|
||||
Error message for invalid path operations
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_ERROR L"%ls: Warning: path component %ls may not be valid in %ls.\n"
|
||||
|
||||
/**
|
||||
Hint for invalid path operation with a colon
|
||||
*/
|
||||
#define BUILTIN_SET_PATH_HINT L"%ls: Did you mean 'set %ls $%ls %ls'?\n"
|
||||
|
||||
/**
|
||||
Error for mismatch between index count and elements
|
||||
*/
|
||||
#define BUILTIN_SET_ARG_COUNT L"%ls: The number of variable indexes does not match the number of values\n"
|
||||
|
||||
static void print_colors(void)
|
||||
{
|
||||
const wcstring_list_t result = rgb_color_t::named_color_names();
|
||||
size_t i;
|
||||
for (i=0; i < result.size(); i++)
|
||||
{
|
||||
stdout_buffer.append(result.at(i));
|
||||
stdout_buffer.push_back(L'\n');
|
||||
}
|
||||
}
|
||||
|
||||
/* function we set as the output writer */
|
||||
static std::string builtin_set_color_output;
|
||||
static int set_color_builtin_outputter(char c)
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
builtin_set_color_output.push_back(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
set_color builtin
|
||||
*/
|
||||
static int builtin_set_color(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
/** Variables used for parsing the argument list */
|
||||
const struct woption long_options[] =
|
||||
{
|
||||
{ L"background", required_argument, 0, 'b'},
|
||||
{ L"help", no_argument, 0, 'h' },
|
||||
{ L"bold", no_argument, 0, 'o' },
|
||||
{ L"underline", no_argument, 0, 'u' },
|
||||
{ L"version", no_argument, 0, 'v' },
|
||||
{ L"print-colors", no_argument, 0, 'c' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
const wchar_t *short_options = L"b:hvocu";
|
||||
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
const wchar_t *bgcolor = NULL;
|
||||
bool bold = false, underline=false;
|
||||
int errret;
|
||||
|
||||
/* Parse options to obtain the requested operation and the modifiers */
|
||||
woptind = 0;
|
||||
while (1)
|
||||
{
|
||||
int c = wgetopt_long(argc, argv, short_options, long_options, 0);
|
||||
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
bgcolor = woptarg;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return STATUS_BUILTIN_OK;
|
||||
|
||||
case 'o':
|
||||
bold = true;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
underline = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
print_colors();
|
||||
return STATUS_BUILTIN_OK;
|
||||
|
||||
case '?':
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remaining argument is foreground color */
|
||||
const wchar_t *fgcolor = NULL;
|
||||
if (woptind < argc)
|
||||
{
|
||||
if (woptind + 1 == argc)
|
||||
{
|
||||
fgcolor = argv[woptind];
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Too many arguments\n"),
|
||||
argv[0]);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (fgcolor == NULL && bgcolor == NULL && !bold && !underline)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
_(L"%ls: Expected an argument\n"),
|
||||
argv[0]);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
const rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : L"");
|
||||
if (fgcolor && fg.is_none())
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], fgcolor);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
|
||||
if (bgcolor && bg.is_none())
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
/* Make sure that the term exists */
|
||||
if (cur_term == NULL && setupterm(0, STDOUT_FILENO, &errret) == ERR)
|
||||
{
|
||||
append_format(stderr_buffer, _(L"%ls: Could not set up terminal\n"), argv[0]);
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
Test if we have at least basic support for setting fonts, colors
|
||||
and related bits - otherwise just give up...
|
||||
*/
|
||||
if (! exit_attribute_mode)
|
||||
{
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Save old output function so we can restore it */
|
||||
int (* const saved_writer_func)(char) = output_get_writer();
|
||||
|
||||
/* Set our output function, which writes to a std::string */
|
||||
builtin_set_color_output.clear();
|
||||
output_set_writer(set_color_builtin_outputter);
|
||||
|
||||
if (bold)
|
||||
{
|
||||
if (enter_bold_mode)
|
||||
writembs(tparm(enter_bold_mode));
|
||||
}
|
||||
|
||||
if (underline)
|
||||
{
|
||||
if (enter_underline_mode)
|
||||
writembs(enter_underline_mode);
|
||||
}
|
||||
|
||||
if (bgcolor != NULL)
|
||||
{
|
||||
if (bg.is_normal())
|
||||
{
|
||||
write_background_color(0);
|
||||
writembs(tparm(exit_attribute_mode));
|
||||
}
|
||||
}
|
||||
|
||||
if (fgcolor != NULL)
|
||||
{
|
||||
if (fg.is_normal())
|
||||
{
|
||||
write_foreground_color(0);
|
||||
writembs(tparm(exit_attribute_mode));
|
||||
}
|
||||
else
|
||||
{
|
||||
write_foreground_color(index_for_color(fg));
|
||||
}
|
||||
}
|
||||
|
||||
if (bgcolor != NULL)
|
||||
{
|
||||
if (! bg.is_normal())
|
||||
{
|
||||
write_background_color(index_for_color(bg));
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore saved writer function */
|
||||
output_set_writer(saved_writer_func);
|
||||
|
||||
/* Output the collected string */
|
||||
std::string local_output;
|
||||
std::swap(builtin_set_color_output, local_output);
|
||||
stdout_buffer.append(str2wcstring(local_output));
|
||||
|
||||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
970
builtin_test.cpp
Normal file
970
builtin_test.cpp
Normal file
@@ -0,0 +1,970 @@
|
||||
/** \file builtin_test.cpp Functions defining the test builtin
|
||||
|
||||
Functions used for implementing the test builtin.
|
||||
Implemented from scratch (yes, really) by way of IEEE 1003.1 as reference.
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "builtin.h"
|
||||
#include "wutil.h"
|
||||
#include "proc.h"
|
||||
#include <sys/stat.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
BUILTIN_TEST_SUCCESS = STATUS_BUILTIN_OK,
|
||||
BUILTIN_TEST_FAIL = STATUS_BUILTIN_ERROR
|
||||
};
|
||||
|
||||
|
||||
int builtin_test(parser_t &parser, wchar_t **argv);
|
||||
|
||||
static const wchar_t * const condstr[] =
|
||||
{
|
||||
L"!", L"&&", L"||", L"==", L"!=", L"<", L">", L"-nt", L"-ot", L"-ef", L"-eq",
|
||||
L"-ne", L"-lt", L"-gt", L"-le", L"-ge", L"=~"
|
||||
};
|
||||
|
||||
namespace test_expressions
|
||||
{
|
||||
|
||||
enum token_t
|
||||
{
|
||||
test_unknown, // arbitrary string
|
||||
|
||||
test_bang, // "!", inverts sense
|
||||
|
||||
test_filetype_b, // "-b", for block special files
|
||||
test_filetype_c, // "-c" for character special files
|
||||
test_filetype_d, // "-d" for directories
|
||||
test_filetype_e, // "-e" for files that exist
|
||||
test_filetype_f, // "-f" for for regular files
|
||||
test_filetype_g, // "-g" for set-group-id
|
||||
test_filetype_h, // "-h" for symbolic links
|
||||
test_filetype_L, // "-L", same as -h
|
||||
test_filetype_p, // "-p", for FIFO
|
||||
test_filetype_S, // "-S", socket
|
||||
|
||||
test_filesize_s, // "-s", size greater than zero
|
||||
|
||||
test_filedesc_t, // "-t", whether the fd is associated with a terminal
|
||||
|
||||
test_fileperm_r, // "-r", read permission
|
||||
test_fileperm_u, // "-u", whether file is setuid
|
||||
test_fileperm_w, // "-w", whether file write permission is allowed
|
||||
test_fileperm_x, // "-x", whether file execute/search is allowed
|
||||
|
||||
test_string_n, // "-n", non-empty string
|
||||
test_string_z, // "-z", true if length of string is 0
|
||||
test_string_equal, // "=", true if strings are identical
|
||||
test_string_not_equal, // "!=", true if strings are not identical
|
||||
|
||||
test_number_equal, // "-eq", true if numbers are equal
|
||||
test_number_not_equal, // "-ne", true if numbers are not equal
|
||||
test_number_greater, // "-gt", true if first number is larger than second
|
||||
test_number_greater_equal, // "-ge", true if first number is at least second
|
||||
test_number_lesser, // "-lt", true if first number is smaller than second
|
||||
test_number_lesser_equal, // "-le", true if first number is at most second
|
||||
|
||||
test_combine_and, // "-a", true if left and right are both true
|
||||
test_combine_or, // "-o", true if either left or right is true
|
||||
|
||||
test_paren_open, // "(", open paren
|
||||
test_paren_close, // ")", close paren
|
||||
};
|
||||
|
||||
static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, const wcstring &right, wcstring_list_t &errors);
|
||||
static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, wcstring_list_t &errors);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
UNARY_PRIMARY = 1 << 0,
|
||||
BINARY_PRIMARY = 1 << 1
|
||||
};
|
||||
|
||||
static const struct token_info_t
|
||||
{
|
||||
token_t tok;
|
||||
const wchar_t *string;
|
||||
unsigned int flags;
|
||||
} token_infos[] =
|
||||
{
|
||||
{test_unknown, L"", 0},
|
||||
{test_bang, L"!", 0},
|
||||
{test_filetype_b, L"-b", UNARY_PRIMARY},
|
||||
{test_filetype_c, L"-c", UNARY_PRIMARY},
|
||||
{test_filetype_d, L"-d", UNARY_PRIMARY},
|
||||
{test_filetype_e, L"-e", UNARY_PRIMARY},
|
||||
{test_filetype_f, L"-f", UNARY_PRIMARY},
|
||||
{test_filetype_g, L"-g", UNARY_PRIMARY},
|
||||
{test_filetype_h, L"-h", UNARY_PRIMARY},
|
||||
{test_filetype_L, L"-L", UNARY_PRIMARY},
|
||||
{test_filetype_p, L"-p", UNARY_PRIMARY},
|
||||
{test_filetype_S, L"-S", UNARY_PRIMARY},
|
||||
{test_filesize_s, L"-s", UNARY_PRIMARY},
|
||||
{test_filedesc_t, L"-t", UNARY_PRIMARY},
|
||||
{test_fileperm_r, L"-r", UNARY_PRIMARY},
|
||||
{test_fileperm_u, L"-u", UNARY_PRIMARY},
|
||||
{test_fileperm_w, L"-w", UNARY_PRIMARY},
|
||||
{test_fileperm_x, L"-x", UNARY_PRIMARY},
|
||||
{test_string_n, L"-n", UNARY_PRIMARY},
|
||||
{test_string_z, L"-z", UNARY_PRIMARY},
|
||||
{test_string_equal, L"=", BINARY_PRIMARY},
|
||||
{test_string_not_equal, L"!=", BINARY_PRIMARY},
|
||||
{test_number_equal, L"-eq", BINARY_PRIMARY},
|
||||
{test_number_not_equal, L"-ne", BINARY_PRIMARY},
|
||||
{test_number_greater, L"-gt", BINARY_PRIMARY},
|
||||
{test_number_greater_equal, L"-ge", BINARY_PRIMARY},
|
||||
{test_number_lesser, L"-lt", BINARY_PRIMARY},
|
||||
{test_number_lesser_equal, L"-le", BINARY_PRIMARY},
|
||||
{test_combine_and, L"-a", 0},
|
||||
{test_combine_or, L"-o", 0},
|
||||
{test_paren_open, L"(", 0},
|
||||
{test_paren_close, L")", 0}
|
||||
};
|
||||
|
||||
const token_info_t *token_for_string(const wcstring &str)
|
||||
{
|
||||
for (size_t i=0; i < sizeof token_infos / sizeof *token_infos; i++)
|
||||
{
|
||||
if (str == token_infos[i].string)
|
||||
{
|
||||
return &token_infos[i];
|
||||
}
|
||||
}
|
||||
return &token_infos[0]; //unknown
|
||||
}
|
||||
|
||||
|
||||
/* Grammar.
|
||||
|
||||
<expr> = <combining_expr>
|
||||
|
||||
<combining_expr> = <unary_expr> and/or <combining_expr> |
|
||||
<unary_expr>
|
||||
|
||||
<unary_expr> = bang <unary_expr> |
|
||||
<primary>
|
||||
|
||||
<primary> = <unary_primary> arg |
|
||||
arg <binary_primary> arg |
|
||||
'(' <expr> ')'
|
||||
|
||||
*/
|
||||
|
||||
class expression;
|
||||
class test_parser
|
||||
{
|
||||
private:
|
||||
wcstring_list_t strings;
|
||||
wcstring_list_t errors;
|
||||
|
||||
expression *error(const wchar_t *fmt, ...);
|
||||
void add_error(const wchar_t *fmt, ...);
|
||||
|
||||
const wcstring &arg(unsigned int idx)
|
||||
{
|
||||
return strings.at(idx);
|
||||
}
|
||||
|
||||
public:
|
||||
test_parser(const wcstring_list_t &val) : strings(val)
|
||||
{ }
|
||||
|
||||
expression *parse_expression(unsigned int start, unsigned int end);
|
||||
expression *parse_3_arg_expression(unsigned int start, unsigned int end);
|
||||
expression *parse_4_arg_expression(unsigned int start, unsigned int end);
|
||||
expression *parse_combining_expression(unsigned int start, unsigned int end);
|
||||
expression *parse_unary_expression(unsigned int start, unsigned int end);
|
||||
|
||||
expression *parse_primary(unsigned int start, unsigned int end);
|
||||
expression *parse_parenthentical(unsigned int start, unsigned int end);
|
||||
expression *parse_unary_primary(unsigned int start, unsigned int end);
|
||||
expression *parse_binary_primary(unsigned int start, unsigned int end);
|
||||
expression *parse_just_a_string(unsigned int start, unsigned int end);
|
||||
|
||||
static expression *parse_args(const wcstring_list_t &args, wcstring &err);
|
||||
};
|
||||
|
||||
struct range_t
|
||||
{
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
|
||||
range_t(unsigned s, unsigned e) : start(s), end(e) { }
|
||||
};
|
||||
|
||||
|
||||
/* Base class for expressions */
|
||||
class expression
|
||||
{
|
||||
protected:
|
||||
expression(token_t what, range_t where) : token(what), range(where) { }
|
||||
|
||||
public:
|
||||
const token_t token;
|
||||
range_t range;
|
||||
|
||||
virtual ~expression() { }
|
||||
|
||||
// evaluate returns true if the expression is true (i.e. BUILTIN_TEST_SUCCESS)
|
||||
virtual bool evaluate(wcstring_list_t &errors) = 0;
|
||||
};
|
||||
|
||||
typedef std::auto_ptr<expression> expr_ref_t;
|
||||
|
||||
/* Single argument like -n foo or "just a string" */
|
||||
class unary_primary : public expression
|
||||
{
|
||||
public:
|
||||
wcstring arg;
|
||||
unary_primary(token_t tok, range_t where, const wcstring &what) : expression(tok, where), arg(what) { }
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
/* Two argument primary like foo != bar */
|
||||
class binary_primary : public expression
|
||||
{
|
||||
public:
|
||||
wcstring arg_left;
|
||||
wcstring arg_right;
|
||||
|
||||
binary_primary(token_t tok, range_t where, const wcstring &left, const wcstring &right) : expression(tok, where), arg_left(left), arg_right(right)
|
||||
{ }
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
/* Unary operator like bang */
|
||||
class unary_operator : public expression
|
||||
{
|
||||
public:
|
||||
expr_ref_t subject;
|
||||
unary_operator(token_t tok, range_t where, expr_ref_t &exp) : expression(tok, where), subject(exp) { }
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
/* Combining expression. Contains a list of AND or OR expressions. It takes more than two so that we don't have to worry about precedence in the parser. */
|
||||
class combining_expression : public expression
|
||||
{
|
||||
public:
|
||||
const std::vector<expression *> subjects;
|
||||
const std::vector<token_t> combiners;
|
||||
|
||||
combining_expression(token_t tok, range_t where, const std::vector<expression *> &exprs, const std::vector<token_t> &combs) : expression(tok, where), subjects(exprs), combiners(combs)
|
||||
{
|
||||
/* We should have one more subject than combiner */
|
||||
assert(subjects.size() == combiners.size() + 1);
|
||||
}
|
||||
|
||||
/* We are responsible for destroying our expressions */
|
||||
virtual ~combining_expression()
|
||||
{
|
||||
for (size_t i=0; i < subjects.size(); i++)
|
||||
{
|
||||
delete subjects[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
/* Parenthetical expression */
|
||||
class parenthetical_expression : public expression
|
||||
{
|
||||
public:
|
||||
expr_ref_t contents;
|
||||
parenthetical_expression(token_t tok, range_t where, expr_ref_t &expr) : expression(tok, where), contents(expr) { }
|
||||
|
||||
virtual bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
void test_parser::add_error(const wchar_t *fmt, ...)
|
||||
{
|
||||
assert(fmt != NULL);
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
this->errors.push_back(vformat_string(fmt, va));
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
expression *test_parser::error(const wchar_t *fmt, ...)
|
||||
{
|
||||
assert(fmt != NULL);
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
this->errors.push_back(vformat_string(fmt, va));
|
||||
va_end(va);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
expression *test_parser::parse_unary_expression(unsigned int start, unsigned int end)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
token_t tok = token_for_string(arg(start))->tok;
|
||||
if (tok == test_bang)
|
||||
{
|
||||
expr_ref_t subject(parse_unary_expression(start + 1, end));
|
||||
if (subject.get())
|
||||
{
|
||||
return new unary_operator(tok, range_t(start, subject->range.end), subject);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return parse_primary(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse a combining expression (AND, OR) */
|
||||
expression *test_parser::parse_combining_expression(unsigned int start, unsigned int end)
|
||||
{
|
||||
if (start >= end)
|
||||
return NULL;
|
||||
|
||||
std::vector<expression *> subjects;
|
||||
std::vector<token_t> combiners;
|
||||
unsigned int idx = start;
|
||||
bool first = true;
|
||||
|
||||
while (idx < end)
|
||||
{
|
||||
|
||||
if (! first)
|
||||
{
|
||||
/* This is not the first expression, so we expect a combiner. */
|
||||
token_t combiner = token_for_string(arg(idx))->tok;
|
||||
if (combiner != test_combine_and && combiner != test_combine_or)
|
||||
{
|
||||
/* Not a combiner, we're done */
|
||||
this->errors.insert(this->errors.begin(), format_string(L"Expected a combining operator like '-a' at index %u", idx));
|
||||
break;
|
||||
}
|
||||
combiners.push_back(combiner);
|
||||
idx++;
|
||||
}
|
||||
|
||||
/* Parse another expression */
|
||||
expression *expr = parse_unary_expression(idx, end);
|
||||
if (! expr)
|
||||
{
|
||||
add_error(L"Missing argument at index %u", idx);
|
||||
if (! first)
|
||||
{
|
||||
/* Clean up the dangling combiner, since it never got its right hand expression */
|
||||
combiners.pop_back();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Go to the end of this expression */
|
||||
idx = expr->range.end;
|
||||
subjects.push_back(expr);
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (! subjects.empty())
|
||||
{
|
||||
/* Our new expression takes ownership of all expressions we created. The token we pass is irrelevant. */
|
||||
return new combining_expression(test_combine_and, range_t(start, idx), subjects, combiners);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No subjects */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
expression *test_parser::parse_unary_primary(unsigned int start, unsigned int end)
|
||||
{
|
||||
/* We need two arguments */
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
if (start + 1 >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start + 1);
|
||||
}
|
||||
|
||||
/* All our unary primaries are prefix, so the operator is at start. */
|
||||
const token_info_t *info = token_for_string(arg(start));
|
||||
if (!(info->flags & UNARY_PRIMARY))
|
||||
return NULL;
|
||||
|
||||
return new unary_primary(info->tok, range_t(start, start + 2), arg(start + 1));
|
||||
}
|
||||
|
||||
expression *test_parser::parse_just_a_string(unsigned int start, unsigned int end)
|
||||
{
|
||||
/* Handle a string as a unary primary that is not a token of any other type.
|
||||
e.g. 'test foo -a bar' should evaluate to true
|
||||
We handle this with a unary primary of test_string_n
|
||||
*/
|
||||
|
||||
/* We need one arguments */
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
|
||||
const token_info_t *info = token_for_string(arg(start));
|
||||
if (info->tok != test_unknown)
|
||||
{
|
||||
return error(L"Unexpected argument type at index %u", start);
|
||||
}
|
||||
|
||||
/* This is hackish; a nicer way to implement this would be with a "just a string" expression type */
|
||||
return new unary_primary(test_string_n, range_t(start, start + 1), arg(start));
|
||||
}
|
||||
|
||||
#if 0
|
||||
expression *test_parser::parse_unary_primary(unsigned int start, unsigned int end)
|
||||
{
|
||||
/* We need either one or two arguments */
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
|
||||
/* The index of the argument to the unary primary */
|
||||
unsigned int arg_idx;
|
||||
|
||||
/* All our unary primaries are prefix, so any operator is at start. But it also may just be a string, with no operator. */
|
||||
const token_info_t *info = token_for_string(arg(start));
|
||||
if (info->flags & UNARY_PRIMARY)
|
||||
{
|
||||
/* We have an operator. Skip the operator argument */
|
||||
arg_idx = start + 1;
|
||||
|
||||
/* We have some freedom here...do we allow other tokens for the argument to operate on?
|
||||
For example, should 'test -n =' work? I say yes. So no typechecking on the next token. */
|
||||
|
||||
}
|
||||
else if (info->tok == test_unknown)
|
||||
{
|
||||
/* "Just a string. */
|
||||
arg_idx = start;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Here we don't allow arbitrary tokens as "just a string." I.e. 'test = -a =' should have a parse error. We could relax this at some point. */
|
||||
return error(L"Parse error at argument index %u", start);
|
||||
}
|
||||
|
||||
/* Verify we have the argument we want, i.e. test -n should fail to parse */
|
||||
if (arg_idx >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", arg_idx);
|
||||
}
|
||||
|
||||
return new unary_primary(info->tok, range_t(start, arg_idx + 1), arg(arg_idx));
|
||||
}
|
||||
#endif
|
||||
|
||||
expression *test_parser::parse_binary_primary(unsigned int start, unsigned int end)
|
||||
{
|
||||
/* We need three arguments */
|
||||
for (unsigned int idx = start; idx < start + 3; idx++)
|
||||
{
|
||||
if (idx >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", idx);
|
||||
}
|
||||
}
|
||||
|
||||
/* All our binary primaries are infix, so the operator is at start + 1. */
|
||||
const token_info_t *info = token_for_string(arg(start + 1));
|
||||
if (!(info->flags & BINARY_PRIMARY))
|
||||
return NULL;
|
||||
|
||||
return new binary_primary(info->tok, range_t(start, start + 3), arg(start), arg(start + 2));
|
||||
}
|
||||
|
||||
expression *test_parser::parse_parenthentical(unsigned int start, unsigned int end)
|
||||
{
|
||||
/* We need at least three arguments: open paren, argument, close paren */
|
||||
if (start + 3 >= end)
|
||||
return NULL;
|
||||
|
||||
/* Must start with an open expression */
|
||||
const token_info_t *open_paren = token_for_string(arg(start));
|
||||
if (open_paren->tok != test_paren_open)
|
||||
return NULL;
|
||||
|
||||
/* Parse a subexpression */
|
||||
expression *subexr_ptr = parse_expression(start + 1, end);
|
||||
if (! subexr_ptr)
|
||||
return NULL;
|
||||
expr_ref_t subexpr(subexr_ptr);
|
||||
|
||||
/* Parse a close paren */
|
||||
unsigned close_index = subexpr->range.end;
|
||||
assert(close_index <= end);
|
||||
if (close_index == end)
|
||||
{
|
||||
return error(L"Missing close paren at index %u", close_index);
|
||||
}
|
||||
const token_info_t *close_paren = token_for_string(arg(close_index));
|
||||
if (close_paren->tok != test_paren_close)
|
||||
{
|
||||
return error(L"Expected close paren at index %u", close_index);
|
||||
}
|
||||
|
||||
/* Success */
|
||||
return new parenthetical_expression(test_paren_open, range_t(start, close_index+1), subexpr);
|
||||
}
|
||||
|
||||
expression *test_parser::parse_primary(unsigned int start, unsigned int end)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
|
||||
expression *expr = NULL;
|
||||
if (! expr) expr = parse_parenthentical(start, end);
|
||||
if (! expr) expr = parse_unary_primary(start, end);
|
||||
if (! expr) expr = parse_binary_primary(start, end);
|
||||
if (! expr) expr = parse_just_a_string(start, end);
|
||||
return expr;
|
||||
}
|
||||
|
||||
// See IEEE 1003.1 breakdown of the behavior for different parameter counts
|
||||
expression *test_parser::parse_3_arg_expression(unsigned int start, unsigned int end)
|
||||
{
|
||||
assert(end - start == 3);
|
||||
expression *result = NULL;
|
||||
|
||||
const token_info_t *center_token = token_for_string(arg(start + 1));
|
||||
if (center_token->flags & BINARY_PRIMARY)
|
||||
{
|
||||
result = parse_binary_primary(start, end);
|
||||
}
|
||||
else if (center_token->tok == test_combine_and || center_token->tok == test_combine_or)
|
||||
{
|
||||
expr_ref_t left(parse_unary_expression(start, start + 1));
|
||||
expr_ref_t right(parse_unary_expression(start + 2, start + 3));
|
||||
if (left.get() && right.get())
|
||||
{
|
||||
// Transfer ownership to the vector of subjects
|
||||
std::vector<token_t> combiners(1, center_token->tok);
|
||||
std::vector<expression *> subjects;
|
||||
subjects.push_back(left.release());
|
||||
subjects.push_back(right.release());
|
||||
result = new combining_expression(center_token->tok, range_t(start, end), subjects, combiners);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = parse_unary_expression(start, end);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
expression *test_parser::parse_4_arg_expression(unsigned int start, unsigned int end)
|
||||
{
|
||||
assert(end - start == 4);
|
||||
expression *result = NULL;
|
||||
|
||||
token_t first_token = token_for_string(arg(start))->tok;
|
||||
if (first_token == test_bang)
|
||||
{
|
||||
expr_ref_t subject(parse_3_arg_expression(start + 1, end));
|
||||
if (subject.get())
|
||||
{
|
||||
result = new unary_operator(first_token, range_t(start, subject->range.end), subject);
|
||||
}
|
||||
}
|
||||
else if (first_token == test_paren_open)
|
||||
{
|
||||
result = parse_parenthentical(start, end);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = parse_combining_expression(start, end);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
expression *test_parser::parse_expression(unsigned int start, unsigned int end)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
return error(L"Missing argument at index %u", start);
|
||||
}
|
||||
|
||||
unsigned int argc = end - start;
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
assert(0); //should have been caught by the above test
|
||||
return NULL;
|
||||
|
||||
case 1:
|
||||
{
|
||||
return error(L"Missing argument at index %u", start + 1);
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return parse_unary_expression(start, end);
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
return parse_3_arg_expression(start, end);
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
return parse_4_arg_expression(start, end);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return parse_combining_expression(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expression *test_parser::parse_args(const wcstring_list_t &args, wcstring &err)
|
||||
{
|
||||
/* Empty list and one-arg list should be handled by caller */
|
||||
assert(args.size() > 1);
|
||||
|
||||
test_parser parser(args);
|
||||
expression *result = parser.parse_expression(0, (unsigned int)args.size());
|
||||
|
||||
/* Handle errors */
|
||||
bool errored = false;
|
||||
for (size_t i = 0; i < parser.errors.size(); i++)
|
||||
{
|
||||
err.append(L"test: ");
|
||||
err.append(parser.errors.at(i));
|
||||
err.push_back(L'\n');
|
||||
errored = true;
|
||||
// For now we only show the first error
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
/* It's also an error if there are any unused arguments. This is not detected by parse_expression() */
|
||||
assert(result->range.end <= args.size());
|
||||
if (result->range.end < args.size())
|
||||
{
|
||||
if (err.empty())
|
||||
{
|
||||
append_format(err, L"test: unexpected argument at index %lu: '%ls'\n", (unsigned long)result->range.end, args.at(result->range.end).c_str());
|
||||
}
|
||||
errored = true;
|
||||
|
||||
delete result;
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool unary_primary::evaluate(wcstring_list_t &errors)
|
||||
{
|
||||
return unary_primary_evaluate(token, arg, errors);
|
||||
}
|
||||
|
||||
bool binary_primary::evaluate(wcstring_list_t &errors)
|
||||
{
|
||||
return binary_primary_evaluate(token, arg_left, arg_right, errors);
|
||||
}
|
||||
|
||||
bool unary_operator::evaluate(wcstring_list_t &errors)
|
||||
{
|
||||
switch (token)
|
||||
{
|
||||
case test_bang:
|
||||
assert(subject.get());
|
||||
return ! subject->evaluate(errors);
|
||||
default:
|
||||
errors.push_back(format_string(L"Unknown token type in %s", __func__));
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool combining_expression::evaluate(wcstring_list_t &errors)
|
||||
{
|
||||
switch (token)
|
||||
{
|
||||
case test_combine_and:
|
||||
case test_combine_or:
|
||||
{
|
||||
/* One-element case */
|
||||
if (subjects.size() == 1)
|
||||
return subjects.at(0)->evaluate(errors);
|
||||
|
||||
/* Evaluate our lists, remembering that AND has higher precedence than OR. We can visualize this as a sequence of OR expressions of AND expressions. */
|
||||
assert(combiners.size() + 1 == subjects.size());
|
||||
assert(! subjects.empty());
|
||||
|
||||
size_t idx = 0, max = subjects.size();
|
||||
bool or_result = false;
|
||||
while (idx < max)
|
||||
{
|
||||
if (or_result)
|
||||
{
|
||||
/* Short circuit */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Evaluate a stream of AND starting at given subject index. It may only have one element. */
|
||||
bool and_result = true;
|
||||
for (; idx < max; idx++)
|
||||
{
|
||||
/* Evaluate it, short-circuiting */
|
||||
and_result = and_result && subjects.at(idx)->evaluate(errors);
|
||||
|
||||
/* If the combiner at this index (which corresponding to how we combine with the next subject) is not AND, then exit the loop */
|
||||
if (idx + 1 < max && combiners.at(idx) != test_combine_and)
|
||||
{
|
||||
idx++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* OR it in */
|
||||
or_result = or_result || and_result;
|
||||
}
|
||||
return or_result;
|
||||
}
|
||||
|
||||
default:
|
||||
errors.push_back(format_string(L"Unknown token type in %s", __func__));
|
||||
return BUILTIN_TEST_FAIL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool parenthetical_expression::evaluate(wcstring_list_t &errors)
|
||||
{
|
||||
return contents->evaluate(errors);
|
||||
}
|
||||
|
||||
/* IEEE 1003.1 says nothing about what it means for two strings to be "algebraically equal". For example, should we interpret 0x10 as 0, 10, or 16? Here we use only base 10 and use wcstoll, which allows for leading + and -, and leading whitespace. This matches bash. */
|
||||
static bool parse_number(const wcstring &arg, long long *out)
|
||||
{
|
||||
const wchar_t *str = arg.c_str();
|
||||
wchar_t *endptr = NULL;
|
||||
*out = wcstoll(str, &endptr, 10);
|
||||
return endptr && *endptr == L'\0';
|
||||
}
|
||||
|
||||
static bool binary_primary_evaluate(test_expressions::token_t token, const wcstring &left, const wcstring &right, wcstring_list_t &errors)
|
||||
{
|
||||
using namespace test_expressions;
|
||||
long long left_num, right_num;
|
||||
switch (token)
|
||||
{
|
||||
case test_string_equal:
|
||||
return left == right;
|
||||
|
||||
case test_string_not_equal:
|
||||
return left != right;
|
||||
|
||||
case test_number_equal:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num == right_num;
|
||||
|
||||
case test_number_not_equal:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num != right_num;
|
||||
|
||||
case test_number_greater:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num > right_num;
|
||||
|
||||
case test_number_greater_equal:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num >= right_num;
|
||||
|
||||
case test_number_lesser:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num < right_num;
|
||||
|
||||
case test_number_lesser_equal:
|
||||
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num <= right_num;
|
||||
|
||||
default:
|
||||
errors.push_back(format_string(L"Unknown token type in %s", __func__));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool unary_primary_evaluate(test_expressions::token_t token, const wcstring &arg, wcstring_list_t &errors)
|
||||
{
|
||||
using namespace test_expressions;
|
||||
struct stat buf;
|
||||
long long num;
|
||||
switch (token)
|
||||
{
|
||||
case test_filetype_b: // "-b", for block special files
|
||||
return !wstat(arg, &buf) && S_ISBLK(buf.st_mode);
|
||||
|
||||
case test_filetype_c: // "-c" for character special files
|
||||
return !wstat(arg, &buf) && S_ISCHR(buf.st_mode);
|
||||
|
||||
case test_filetype_d: // "-d" for directories
|
||||
return !wstat(arg, &buf) && S_ISDIR(buf.st_mode);
|
||||
|
||||
case test_filetype_e: // "-e" for files that exist
|
||||
return !wstat(arg, &buf);
|
||||
|
||||
case test_filetype_f: // "-f" for for regular files
|
||||
return !wstat(arg, &buf) && S_ISREG(buf.st_mode);
|
||||
|
||||
case test_filetype_g: // "-g" for set-group-id
|
||||
return !wstat(arg, &buf) && (S_ISGID & buf.st_mode);
|
||||
|
||||
case test_filetype_h: // "-h" for symbolic links
|
||||
case test_filetype_L: // "-L", same as -h
|
||||
return !lwstat(arg, &buf) && S_ISLNK(buf.st_mode);
|
||||
|
||||
case test_filetype_p: // "-p", for FIFO
|
||||
return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode);
|
||||
|
||||
case test_filetype_S: // "-S", socket
|
||||
return !wstat(arg, &buf) && S_ISSOCK(buf.st_mode);
|
||||
|
||||
case test_filesize_s: // "-s", size greater than zero
|
||||
return !wstat(arg, &buf) && buf.st_size > 0;
|
||||
|
||||
case test_filedesc_t: // "-t", whether the fd is associated with a terminal
|
||||
return parse_number(arg, &num) && num == (int)num && isatty((int)num);
|
||||
|
||||
case test_fileperm_r: // "-r", read permission
|
||||
return !waccess(arg, R_OK);
|
||||
|
||||
case test_fileperm_u: // "-u", whether file is setuid
|
||||
return !wstat(arg, &buf) && (S_ISUID & buf.st_mode);
|
||||
|
||||
case test_fileperm_w: // "-w", whether file write permission is allowed
|
||||
return !waccess(arg, W_OK);
|
||||
|
||||
case test_fileperm_x: // "-x", whether file execute/search is allowed
|
||||
return !waccess(arg, X_OK);
|
||||
|
||||
case test_string_n: // "-n", non-empty string
|
||||
return ! arg.empty();
|
||||
|
||||
case test_string_z: // "-z", true if length of string is 0
|
||||
return arg.empty();
|
||||
|
||||
default:
|
||||
errors.push_back(format_string(L"Unknown token type in %s", __func__));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Evaluate a conditional expression given the arguments.
|
||||
* If fromtest is set, the caller is the test or [ builtin;
|
||||
* with the pointer giving the name of the command.
|
||||
* for POSIX conformance this supports a more limited range
|
||||
* of functionality.
|
||||
*
|
||||
* Return status is the final shell status, i.e. 0 for true,
|
||||
* 1 for false and 2 for error.
|
||||
*/
|
||||
int builtin_test(parser_t &parser, wchar_t **argv)
|
||||
{
|
||||
using namespace test_expressions;
|
||||
|
||||
/* The first argument should be the name of the command ('test') */
|
||||
if (! argv[0])
|
||||
return BUILTIN_TEST_FAIL;
|
||||
|
||||
/* Whether we are invoked with bracket '[' or not */
|
||||
const bool is_bracket = ! wcscmp(argv[0], L"[");
|
||||
|
||||
size_t argc = 0;
|
||||
while (argv[argc + 1])
|
||||
argc++;
|
||||
|
||||
/* If we're bracket, the last argument ought to be ]; we ignore it. Note that argc is the number of arguments after the command name; thus argv[argc] is the last argument. */
|
||||
if (is_bracket)
|
||||
{
|
||||
if (! wcscmp(argv[argc], L"]"))
|
||||
{
|
||||
/* Ignore the closing bracketp */
|
||||
argc--;
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_show_error(L"[: the last argument must be ']'\n");
|
||||
return BUILTIN_TEST_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Collect the arguments into a list */
|
||||
const wcstring_list_t args(argv + 1, argv + 1 + argc);
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// Per 1003.1, exit false
|
||||
return BUILTIN_TEST_FAIL;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
// Per 1003.1, exit true if the arg is non-empty
|
||||
return args.at(0).empty() ? BUILTIN_TEST_FAIL : BUILTIN_TEST_SUCCESS;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Try parsing. If expr is not nil, we are responsible for deleting it.
|
||||
wcstring err;
|
||||
expression *expr = test_parser::parse_args(args, err);
|
||||
if (! expr)
|
||||
{
|
||||
#if 0
|
||||
printf("Oops! test was given args:\n");
|
||||
for (size_t i=0; i < argc; i++)
|
||||
{
|
||||
printf("\t%ls\n", args.at(i).c_str());
|
||||
}
|
||||
printf("and returned parse error: %ls\n", err.c_str());
|
||||
#endif
|
||||
builtin_show_error(err);
|
||||
return BUILTIN_TEST_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
wcstring_list_t eval_errors;
|
||||
bool result = expr->evaluate(eval_errors);
|
||||
if (! eval_errors.empty())
|
||||
{
|
||||
printf("test returned eval errors:\n");
|
||||
for (size_t i=0; i < eval_errors.size(); i++)
|
||||
{
|
||||
printf("\t%ls\n", eval_errors.at(i).c_str());
|
||||
}
|
||||
}
|
||||
delete expr;
|
||||
return result ? BUILTIN_TEST_SUCCESS : BUILTIN_TEST_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
516
builtin_ulimit.c
516
builtin_ulimit.c
@@ -1,516 +0,0 @@
|
||||
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
||||
|
||||
Functions used for implementing the ulimit builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
|
||||
|
||||
/**
|
||||
Struct describing a resource limit
|
||||
*/
|
||||
struct resource_t
|
||||
{
|
||||
/**
|
||||
Resource id
|
||||
*/
|
||||
int resource;
|
||||
/**
|
||||
Description of resource
|
||||
*/
|
||||
const wchar_t *desc;
|
||||
/**
|
||||
Switch used on commandline to specify resource
|
||||
*/
|
||||
wchar_t switch_char;
|
||||
/**
|
||||
The implicit multiplier used when setting getting values
|
||||
*/
|
||||
int multiplier;
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Array of resource_t structs, describing all known resource types.
|
||||
*/
|
||||
static const struct resource_t resource_arr[] =
|
||||
{
|
||||
{
|
||||
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_DATA, L"Maximum size of a process’s data segment", L'd', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_FSIZE, L"Maximum size of files created by the shell", L'f', 1024
|
||||
}
|
||||
,
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
{
|
||||
RLIMIT_MEMLOCK, L"Maximum size that may be locked into memory", L'l', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
#ifdef RLIMIT_RSS
|
||||
{
|
||||
RLIMIT_RSS, L"Maximum resident set size", L'm', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
{
|
||||
RLIMIT_NOFILE, L"Maximum number of open file descriptors", L'n', 1
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_STACK, L"Maximum stack size", L's', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_CPU, L"Maximum amount of cpu time in seconds", L't', 1
|
||||
}
|
||||
,
|
||||
#ifdef RLIMIT_NPROC
|
||||
{
|
||||
RLIMIT_NPROC, L"Maximum number of processes available to a single user", L'u', 1
|
||||
}
|
||||
,
|
||||
#endif
|
||||
#ifdef RLIMIT_AS
|
||||
{
|
||||
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Get the implicit multiplication factor for the specified resource limit
|
||||
*/
|
||||
static int get_multiplier( int what )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; resource_arr[i].desc; i++ )
|
||||
{
|
||||
if( resource_arr[i].resource == what )
|
||||
{
|
||||
return resource_arr[i].multiplier;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
Return the value for the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static rlim_t get( int resource, int hard )
|
||||
{
|
||||
struct rlimit ls;
|
||||
|
||||
getrlimit( resource, &ls );
|
||||
|
||||
return hard ? ls.rlim_max:ls.rlim_cur;
|
||||
}
|
||||
|
||||
/**
|
||||
Print the value of the specified resource limit
|
||||
*/
|
||||
static void print( int resource, int hard )
|
||||
{
|
||||
rlim_t l = get( resource, hard );
|
||||
|
||||
if( l == RLIM_INFINITY )
|
||||
sb_append( sb_out, L"unlimited\n" );
|
||||
else
|
||||
sb_printf( sb_out, L"%d\n", l / get_multiplier( resource ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Print values of all resource limits
|
||||
*/
|
||||
static void print_all( int hard )
|
||||
{
|
||||
int i;
|
||||
int w=0;
|
||||
|
||||
for( i=0; resource_arr[i].desc; i++ )
|
||||
{
|
||||
w=maxi( w, my_wcswidth(resource_arr[i].desc));
|
||||
}
|
||||
|
||||
for( i=0; resource_arr[i].desc; i++ )
|
||||
{
|
||||
struct rlimit ls;
|
||||
rlim_t l;
|
||||
getrlimit( resource_arr[i].resource, &ls );
|
||||
l = hard ? ls.rlim_max:ls.rlim_cur;
|
||||
|
||||
wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
|
||||
|
||||
sb_printf( sb_out,
|
||||
L"%-*ls %10ls-%lc) ",
|
||||
w,
|
||||
resource_arr[i].desc,
|
||||
unit,
|
||||
resource_arr[i].switch_char);
|
||||
|
||||
if( l == RLIM_INFINITY )
|
||||
{
|
||||
sb_append( sb_out, L"unlimited\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", l/get_multiplier(resource_arr[i].resource) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the description for the specified resource limit
|
||||
*/
|
||||
static const wchar_t *get_desc( int what )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; resource_arr[i].desc; i++ )
|
||||
{
|
||||
if( resource_arr[i].resource == what )
|
||||
{
|
||||
return resource_arr[i].desc;
|
||||
}
|
||||
}
|
||||
return L"Not a resource";
|
||||
}
|
||||
|
||||
/**
|
||||
Set the new value of the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static int set( int resource, int hard, int soft, rlim_t value )
|
||||
{
|
||||
struct rlimit ls;
|
||||
getrlimit( resource, &ls );
|
||||
|
||||
if( hard )
|
||||
{
|
||||
ls.rlim_max = value;
|
||||
}
|
||||
|
||||
if( soft )
|
||||
{
|
||||
ls.rlim_cur = value;
|
||||
|
||||
/*
|
||||
Do not attempt to set the soft limit higher than the hard limit
|
||||
*/
|
||||
if( ( value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY ) ||
|
||||
( value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
|
||||
{
|
||||
ls.rlim_cur = ls.rlim_max;
|
||||
}
|
||||
}
|
||||
|
||||
if( setrlimit( resource, &ls ) )
|
||||
{
|
||||
if( errno == EPERM )
|
||||
sb_printf( sb_err, L"ulimit: Permission denied when changing resource of type '%ls'\n", get_desc( resource ) );
|
||||
else
|
||||
builtin_wperror( L"ulimit" );
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
The ulimit builtin, used for setting resource limits. Defined in
|
||||
builtin_ulimit.c.
|
||||
*/
|
||||
static int builtin_ulimit( wchar_t ** argv )
|
||||
{
|
||||
int hard=0;
|
||||
int soft=0;
|
||||
|
||||
int what = RLIMIT_FSIZE;
|
||||
int report_all = 0;
|
||||
|
||||
int argc = builtin_count_args( argv );
|
||||
|
||||
woptind=0;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"all", no_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"hard", no_argument, 0, 'H'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"soft", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"core-size", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"data-size", no_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"file-size", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"lock-size", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"resident-set-size", no_argument, 0, 'm'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"file-descriptor-count", no_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"stack-size", no_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cpu-time", no_argument, 0, 't'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"process-count", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"virtual-memory-size", no_argument, 0, 'v'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"aHScdflmnstuvh",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
break;
|
||||
|
||||
switch( opt )
|
||||
{
|
||||
case 0:
|
||||
if(long_options[opt_index].flag != 0)
|
||||
break;
|
||||
sb_printf( sb_err,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
|
||||
return 1;
|
||||
|
||||
case L'a':
|
||||
report_all=1;
|
||||
break;
|
||||
|
||||
case L'H':
|
||||
hard=1;
|
||||
break;
|
||||
|
||||
case L'S':
|
||||
soft=1;
|
||||
break;
|
||||
|
||||
case L'c':
|
||||
what=RLIMIT_CORE;
|
||||
break;
|
||||
|
||||
case L'd':
|
||||
what=RLIMIT_DATA;
|
||||
break;
|
||||
|
||||
case L'f':
|
||||
what=RLIMIT_FSIZE;
|
||||
break;
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
case L'l':
|
||||
what=RLIMIT_MEMLOCK;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_RSS
|
||||
case L'm':
|
||||
what=RLIMIT_RSS;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case L'n':
|
||||
what=RLIMIT_NOFILE;
|
||||
break;
|
||||
|
||||
case L's':
|
||||
what=RLIMIT_STACK;
|
||||
break;
|
||||
|
||||
case L't':
|
||||
what=RLIMIT_CPU;
|
||||
break;
|
||||
|
||||
#ifdef RLIMIT_NPROC
|
||||
case L'u':
|
||||
what=RLIMIT_NPROC;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_AS
|
||||
case L'v':
|
||||
what=RLIMIT_AS;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case L'h':
|
||||
builtin_print_help( argv[0], sb_out );
|
||||
return 0;
|
||||
|
||||
case L'?':
|
||||
builtin_unknown_option( argv[0], argv[woptind-1] );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( report_all )
|
||||
{
|
||||
if( argc - woptind == 0 )
|
||||
{
|
||||
print_all( hard );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch( argc - woptind )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/*
|
||||
Show current limit value
|
||||
*/
|
||||
print( what, hard );
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
/*
|
||||
Change current limit value
|
||||
*/
|
||||
rlim_t new_limit;
|
||||
wchar_t *end;
|
||||
|
||||
/*
|
||||
Set both hard and soft limits if nothing else was specified
|
||||
*/
|
||||
if( !(hard+soft) )
|
||||
{
|
||||
hard=soft=1;
|
||||
}
|
||||
|
||||
if( wcscasecmp( argv[woptind], L"unlimited" )==0)
|
||||
{
|
||||
new_limit = RLIM_INFINITY;
|
||||
}
|
||||
else if( wcscasecmp( argv[woptind], L"hard" )==0)
|
||||
{
|
||||
new_limit = get( what, 1 );
|
||||
}
|
||||
else if( wcscasecmp( argv[woptind], L"soft" )==0)
|
||||
{
|
||||
new_limit = get( what, soft );
|
||||
}
|
||||
else
|
||||
{
|
||||
errno=0;
|
||||
new_limit = wcstol( argv[woptind], &end, 10 );
|
||||
if( errno || *end )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
L"%ls: Invalid limit '%ls'\n",
|
||||
argv[0],
|
||||
argv[woptind] );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
new_limit *= get_multiplier( what );
|
||||
}
|
||||
|
||||
return set( what, hard, soft, new_limit );
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
sb_append( sb_err,
|
||||
argv[0],
|
||||
L": Too many arguments\n",
|
||||
(void *)0 );
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
512
builtin_ulimit.cpp
Normal file
512
builtin_ulimit.cpp
Normal file
@@ -0,0 +1,512 @@
|
||||
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
||||
|
||||
Functions used for implementing the ulimit builtin.
|
||||
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "fallback.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
#include "wgetopt.h"
|
||||
|
||||
|
||||
/**
|
||||
Struct describing a resource limit
|
||||
*/
|
||||
struct resource_t
|
||||
{
|
||||
/**
|
||||
Resource id
|
||||
*/
|
||||
int resource;
|
||||
/**
|
||||
Description of resource
|
||||
*/
|
||||
const wchar_t *desc;
|
||||
/**
|
||||
Switch used on commandline to specify resource
|
||||
*/
|
||||
wchar_t switch_char;
|
||||
/**
|
||||
The implicit multiplier used when setting getting values
|
||||
*/
|
||||
int multiplier;
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Array of resource_t structs, describing all known resource types.
|
||||
*/
|
||||
static const struct resource_t resource_arr[] =
|
||||
{
|
||||
{
|
||||
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_DATA, L"Maximum size of a process’s data segment", L'd', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_FSIZE, L"Maximum size of files created by the shell", L'f', 1024
|
||||
}
|
||||
,
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
{
|
||||
RLIMIT_MEMLOCK, L"Maximum size that may be locked into memory", L'l', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
#ifdef RLIMIT_RSS
|
||||
{
|
||||
RLIMIT_RSS, L"Maximum resident set size", L'm', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
{
|
||||
RLIMIT_NOFILE, L"Maximum number of open file descriptors", L'n', 1
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_STACK, L"Maximum stack size", L's', 1024
|
||||
}
|
||||
,
|
||||
{
|
||||
RLIMIT_CPU, L"Maximum amount of cpu time in seconds", L't', 1
|
||||
}
|
||||
,
|
||||
#ifdef RLIMIT_NPROC
|
||||
{
|
||||
RLIMIT_NPROC, L"Maximum number of processes available to a single user", L'u', 1
|
||||
}
|
||||
,
|
||||
#endif
|
||||
#ifdef RLIMIT_AS
|
||||
{
|
||||
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
|
||||
}
|
||||
,
|
||||
#endif
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
Get the implicit multiplication factor for the specified resource limit
|
||||
*/
|
||||
static int get_multiplier(int what)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; resource_arr[i].desc; i++)
|
||||
{
|
||||
if (resource_arr[i].resource == what)
|
||||
{
|
||||
return resource_arr[i].multiplier;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
Return the value for the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static rlim_t get(int resource, int hard)
|
||||
{
|
||||
struct rlimit ls;
|
||||
|
||||
getrlimit(resource, &ls);
|
||||
|
||||
return hard ? ls.rlim_max:ls.rlim_cur;
|
||||
}
|
||||
|
||||
/**
|
||||
Print the value of the specified resource limit
|
||||
*/
|
||||
static void print(int resource, int hard)
|
||||
{
|
||||
rlim_t l = get(resource, hard);
|
||||
|
||||
if (l == RLIM_INFINITY)
|
||||
stdout_buffer.append(L"unlimited\n");
|
||||
else
|
||||
append_format(stdout_buffer, L"%d\n", l / get_multiplier(resource));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Print values of all resource limits
|
||||
*/
|
||||
static void print_all(int hard)
|
||||
{
|
||||
int i;
|
||||
int w=0;
|
||||
|
||||
for (i=0; resource_arr[i].desc; i++)
|
||||
{
|
||||
w=maxi(w, my_wcswidth(resource_arr[i].desc));
|
||||
}
|
||||
|
||||
for (i=0; resource_arr[i].desc; i++)
|
||||
{
|
||||
struct rlimit ls;
|
||||
rlim_t l;
|
||||
getrlimit(resource_arr[i].resource, &ls);
|
||||
l = hard ? ls.rlim_max:ls.rlim_cur;
|
||||
|
||||
const wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
|
||||
|
||||
append_format(stdout_buffer,
|
||||
L"%-*ls %10ls-%lc) ",
|
||||
w,
|
||||
resource_arr[i].desc,
|
||||
unit,
|
||||
resource_arr[i].switch_char);
|
||||
|
||||
if (l == RLIM_INFINITY)
|
||||
{
|
||||
stdout_buffer.append(L"unlimited\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
append_format(stdout_buffer, L"%d\n", l/get_multiplier(resource_arr[i].resource));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the description for the specified resource limit
|
||||
*/
|
||||
static const wchar_t *get_desc(int what)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; resource_arr[i].desc; i++)
|
||||
{
|
||||
if (resource_arr[i].resource == what)
|
||||
{
|
||||
return resource_arr[i].desc;
|
||||
}
|
||||
}
|
||||
return L"Not a resource";
|
||||
}
|
||||
|
||||
/**
|
||||
Set the new value of the specified resource limit. This function
|
||||
does _not_ multiply the limit value by the multiplier constant used
|
||||
by the commandline ulimit.
|
||||
*/
|
||||
static int set(int resource, int hard, int soft, rlim_t value)
|
||||
{
|
||||
struct rlimit ls;
|
||||
getrlimit(resource, &ls);
|
||||
|
||||
if (hard)
|
||||
{
|
||||
ls.rlim_max = value;
|
||||
}
|
||||
|
||||
if (soft)
|
||||
{
|
||||
ls.rlim_cur = value;
|
||||
|
||||
/*
|
||||
Do not attempt to set the soft limit higher than the hard limit
|
||||
*/
|
||||
if ((value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY) ||
|
||||
(value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
|
||||
{
|
||||
ls.rlim_cur = ls.rlim_max;
|
||||
}
|
||||
}
|
||||
|
||||
if (setrlimit(resource, &ls))
|
||||
{
|
||||
if (errno == EPERM)
|
||||
append_format(stderr_buffer, L"ulimit: Permission denied when changing resource of type '%ls'\n", get_desc(resource));
|
||||
else
|
||||
builtin_wperror(L"ulimit");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
The ulimit builtin, used for setting resource limits. Defined in
|
||||
builtin_ulimit.c.
|
||||
*/
|
||||
static int builtin_ulimit(parser_t &parser, wchar_t ** argv)
|
||||
{
|
||||
int hard=0;
|
||||
int soft=0;
|
||||
|
||||
int what = RLIMIT_FSIZE;
|
||||
int report_all = 0;
|
||||
|
||||
int argc = builtin_count_args(argv);
|
||||
|
||||
woptind=0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
static const struct woption
|
||||
long_options[] =
|
||||
{
|
||||
{
|
||||
L"all", no_argument, 0, 'a'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"hard", no_argument, 0, 'H'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"soft", no_argument, 0, 'S'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"core-size", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"data-size", no_argument, 0, 'd'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"file-size", no_argument, 0, 'f'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"lock-size", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"resident-set-size", no_argument, 0, 'm'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"file-descriptor-count", no_argument, 0, 'n'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"stack-size", no_argument, 0, 's'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"cpu-time", no_argument, 0, 't'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"process-count", no_argument, 0, 'u'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"virtual-memory-size", no_argument, 0, 'v'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"help", no_argument, 0, 'h'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
int opt_index = 0;
|
||||
|
||||
int opt = wgetopt_long(argc,
|
||||
argv,
|
||||
L"aHScdflmnstuvh",
|
||||
long_options,
|
||||
&opt_index);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
if (long_options[opt_index].flag != 0)
|
||||
break;
|
||||
append_format(stderr_buffer,
|
||||
BUILTIN_ERR_UNKNOWN,
|
||||
argv[0],
|
||||
long_options[opt_index].name);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
|
||||
return 1;
|
||||
|
||||
case L'a':
|
||||
report_all=1;
|
||||
break;
|
||||
|
||||
case L'H':
|
||||
hard=1;
|
||||
break;
|
||||
|
||||
case L'S':
|
||||
soft=1;
|
||||
break;
|
||||
|
||||
case L'c':
|
||||
what=RLIMIT_CORE;
|
||||
break;
|
||||
|
||||
case L'd':
|
||||
what=RLIMIT_DATA;
|
||||
break;
|
||||
|
||||
case L'f':
|
||||
what=RLIMIT_FSIZE;
|
||||
break;
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
case L'l':
|
||||
what=RLIMIT_MEMLOCK;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_RSS
|
||||
case L'm':
|
||||
what=RLIMIT_RSS;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case L'n':
|
||||
what=RLIMIT_NOFILE;
|
||||
break;
|
||||
|
||||
case L's':
|
||||
what=RLIMIT_STACK;
|
||||
break;
|
||||
|
||||
case L't':
|
||||
what=RLIMIT_CPU;
|
||||
break;
|
||||
|
||||
#ifdef RLIMIT_NPROC
|
||||
case L'u':
|
||||
what=RLIMIT_NPROC;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef RLIMIT_AS
|
||||
case L'v':
|
||||
what=RLIMIT_AS;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case L'h':
|
||||
builtin_print_help(parser, argv[0], stdout_buffer);
|
||||
return 0;
|
||||
|
||||
case L'?':
|
||||
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (report_all)
|
||||
{
|
||||
if (argc - woptind == 0)
|
||||
{
|
||||
print_all(hard);
|
||||
}
|
||||
else
|
||||
{
|
||||
stderr_buffer.append(argv[0]);
|
||||
stderr_buffer.append(L": Too many arguments\n");
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (argc - woptind)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/*
|
||||
Show current limit value
|
||||
*/
|
||||
print(what, hard);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
/*
|
||||
Change current limit value
|
||||
*/
|
||||
rlim_t new_limit;
|
||||
wchar_t *end;
|
||||
|
||||
/*
|
||||
Set both hard and soft limits if nothing else was specified
|
||||
*/
|
||||
if (!(hard+soft))
|
||||
{
|
||||
hard=soft=1;
|
||||
}
|
||||
|
||||
if (wcscasecmp(argv[woptind], L"unlimited")==0)
|
||||
{
|
||||
new_limit = RLIM_INFINITY;
|
||||
}
|
||||
else if (wcscasecmp(argv[woptind], L"hard")==0)
|
||||
{
|
||||
new_limit = get(what, 1);
|
||||
}
|
||||
else if (wcscasecmp(argv[woptind], L"soft")==0)
|
||||
{
|
||||
new_limit = get(what, soft);
|
||||
}
|
||||
else
|
||||
{
|
||||
errno=0;
|
||||
new_limit = wcstol(argv[woptind], &end, 10);
|
||||
if (errno || *end)
|
||||
{
|
||||
append_format(stderr_buffer,
|
||||
L"%ls: Invalid limit '%ls'\n",
|
||||
argv[0],
|
||||
argv[woptind]);
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
new_limit *= get_multiplier(what);
|
||||
}
|
||||
|
||||
return set(what, hard, soft, new_limit);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
stderr_buffer.append(argv[0]);
|
||||
stderr_buffer.append(L": Too many arguments\n");
|
||||
builtin_print_help(parser, argv[0], stderr_buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
365
color.cpp
Normal file
365
color.cpp
Normal file
@@ -0,0 +1,365 @@
|
||||
/** \file color.cpp Color class implementation
|
||||
*/
|
||||
|
||||
#include "color.h"
|
||||
#include "fallback.h"
|
||||
|
||||
bool rgb_color_t::try_parse_special(const wcstring &special)
|
||||
{
|
||||
bzero(&data, sizeof data);
|
||||
const wchar_t *name = special.c_str();
|
||||
if (! wcscasecmp(name, L"normal"))
|
||||
{
|
||||
this->type = type_normal;
|
||||
}
|
||||
else if (! wcscasecmp(name, L"reset"))
|
||||
{
|
||||
this->type = type_reset;
|
||||
}
|
||||
else if (! wcscasecmp(name, L"ignore"))
|
||||
{
|
||||
this->type = type_ignore;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->type = type_none;
|
||||
}
|
||||
return this->type != type_none;
|
||||
}
|
||||
|
||||
static int parse_hex_digit(wchar_t x)
|
||||
{
|
||||
switch (x)
|
||||
{
|
||||
case L'0':
|
||||
return 0x0;
|
||||
case L'1':
|
||||
return 0x1;
|
||||
case L'2':
|
||||
return 0x2;
|
||||
case L'3':
|
||||
return 0x3;
|
||||
case L'4':
|
||||
return 0x4;
|
||||
case L'5':
|
||||
return 0x5;
|
||||
case L'6':
|
||||
return 0x6;
|
||||
case L'7':
|
||||
return 0x7;
|
||||
case L'8':
|
||||
return 0x8;
|
||||
case L'9':
|
||||
return 0x9;
|
||||
case L'a':
|
||||
case L'A':
|
||||
return 0xA;
|
||||
case L'b':
|
||||
case L'B':
|
||||
return 0xB;
|
||||
case L'c':
|
||||
case L'C':
|
||||
return 0xC;
|
||||
case L'd':
|
||||
case L'D':
|
||||
return 0xD;
|
||||
case L'e':
|
||||
case L'E':
|
||||
return 0xE;
|
||||
case L'f':
|
||||
case L'F':
|
||||
return 0xF;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long squared_difference(long p1, long p2)
|
||||
{
|
||||
unsigned long diff = (unsigned long)labs(p1 - p2);
|
||||
return diff * diff;
|
||||
}
|
||||
|
||||
static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *colors, size_t color_count)
|
||||
{
|
||||
long r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
unsigned long best_distance = (unsigned long)(-1);
|
||||
unsigned char best_index = (unsigned char)(-1);
|
||||
for (unsigned char idx = 0; idx < color_count; idx++)
|
||||
{
|
||||
uint32_t color = colors[idx];
|
||||
long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF, test_b = (color >> 0) & 0xFF;
|
||||
unsigned long distance = squared_difference(r, test_r) + squared_difference(g, test_g) + squared_difference(b, test_b);
|
||||
if (distance <= best_distance)
|
||||
{
|
||||
best_index = idx;
|
||||
best_distance = distance;
|
||||
}
|
||||
}
|
||||
return best_index;
|
||||
|
||||
}
|
||||
|
||||
bool rgb_color_t::try_parse_rgb(const wcstring &name)
|
||||
{
|
||||
bzero(&data, sizeof data);
|
||||
/* We support the following style of rgb formats (case insensitive):
|
||||
#FA3
|
||||
#F3A035
|
||||
FA3
|
||||
F3A035
|
||||
*/
|
||||
|
||||
size_t digit_idx = 0, len = name.size();
|
||||
|
||||
/* Skip any leading # */
|
||||
if (len > 0 && name.at(0) == L'#')
|
||||
digit_idx++;
|
||||
|
||||
bool success = false;
|
||||
size_t i;
|
||||
if (len - digit_idx == 3)
|
||||
{
|
||||
// type FA3
|
||||
for (i=0; i < 3; i++)
|
||||
{
|
||||
int val = parse_hex_digit(name.at(digit_idx++));
|
||||
if (val < 0) break;
|
||||
data.rgb[i] = val*16+val;
|
||||
}
|
||||
success = (i == 3);
|
||||
}
|
||||
else if (len - digit_idx == 6)
|
||||
{
|
||||
// type F3A035
|
||||
for (i=0; i < 3; i++)
|
||||
{
|
||||
int hi = parse_hex_digit(name.at(digit_idx++));
|
||||
int lo = parse_hex_digit(name.at(digit_idx++));
|
||||
if (lo < 0 || hi < 0) break;
|
||||
data.rgb[i] = hi*16+lo;
|
||||
}
|
||||
success = (i == 3);
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
this->type = type_rgb;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
struct named_color_t
|
||||
{
|
||||
const wchar_t * name;
|
||||
unsigned char idx;
|
||||
unsigned char rgb[3];
|
||||
};
|
||||
|
||||
static const named_color_t named_colors[11] =
|
||||
{
|
||||
{L"black", 0, {0, 0, 0}},
|
||||
{L"red", 1, {0xFF, 0, 0}},
|
||||
{L"green", 2, {0, 0xFF, 0}},
|
||||
{L"brown", 3, {0x72, 0x50, 0}},
|
||||
{L"yellow", 3, {0xFF, 0xFF, 0}},
|
||||
{L"blue", 4, {0, 0, 0xFF}},
|
||||
{L"magenta", 5, {0xFF, 0, 0xFF}},
|
||||
{L"purple", 5, {0xFF, 0, 0xFF}},
|
||||
{L"cyan", 6, {0, 0xFF, 0xFF}},
|
||||
{L"white", 7, {0xFF, 0xFF, 0xFF}},
|
||||
{L"normal", 8, {0xFF, 0xFF, 0XFF}}
|
||||
};
|
||||
|
||||
wcstring_list_t rgb_color_t::named_color_names(void)
|
||||
{
|
||||
size_t count = sizeof named_colors / sizeof *named_colors;
|
||||
wcstring_list_t result;
|
||||
result.reserve(count);
|
||||
for (size_t i=0; i < count; i++)
|
||||
{
|
||||
result.push_back(named_colors[i].name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool rgb_color_t::try_parse_named(const wcstring &str)
|
||||
{
|
||||
bzero(&data, sizeof data);
|
||||
size_t max = sizeof named_colors / sizeof *named_colors;
|
||||
for (size_t idx=0; idx < max; idx++)
|
||||
{
|
||||
if (0 == wcscasecmp(str.c_str(), named_colors[idx].name))
|
||||
{
|
||||
data.name_idx = named_colors[idx].idx;
|
||||
this->type = type_named;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const wchar_t *name_for_color_idx(unsigned char idx)
|
||||
{
|
||||
size_t max = sizeof named_colors / sizeof *named_colors;
|
||||
for (size_t i=0; i < max; i++)
|
||||
{
|
||||
if (named_colors[i].idx == idx)
|
||||
{
|
||||
return named_colors[i].name;
|
||||
}
|
||||
}
|
||||
return L"unknown";
|
||||
}
|
||||
|
||||
rgb_color_t::rgb_color_t(unsigned char t, unsigned char i) : type(t), flags(), data()
|
||||
{
|
||||
data.name_idx = i;
|
||||
}
|
||||
|
||||
rgb_color_t rgb_color_t::normal()
|
||||
{
|
||||
return rgb_color_t(type_normal);
|
||||
}
|
||||
rgb_color_t rgb_color_t::reset()
|
||||
{
|
||||
return rgb_color_t(type_reset);
|
||||
}
|
||||
rgb_color_t rgb_color_t::ignore()
|
||||
{
|
||||
return rgb_color_t(type_ignore);
|
||||
}
|
||||
rgb_color_t rgb_color_t::none()
|
||||
{
|
||||
return rgb_color_t(type_none);
|
||||
}
|
||||
rgb_color_t rgb_color_t::white()
|
||||
{
|
||||
return rgb_color_t(type_named, 7);
|
||||
}
|
||||
rgb_color_t rgb_color_t::black()
|
||||
{
|
||||
return rgb_color_t(type_named, 0);
|
||||
}
|
||||
|
||||
static unsigned char term8_color_for_rgb(const unsigned char rgb[3])
|
||||
{
|
||||
const uint32_t kColors[] =
|
||||
{
|
||||
0x000000, //Black
|
||||
0xFF0000, //Red
|
||||
0x00FF00, //Green
|
||||
0xFFFF00, //Yellow
|
||||
0x0000FF, //Blue
|
||||
0xFF00FF, //Magenta
|
||||
0x00FFFF, //Cyan
|
||||
0xFFFFFF, //White
|
||||
};
|
||||
return convert_color(rgb, kColors, sizeof kColors / sizeof *kColors);
|
||||
}
|
||||
|
||||
static unsigned char term256_color_for_rgb(const unsigned char rgb[3])
|
||||
{
|
||||
const uint32_t kColors[240] =
|
||||
{
|
||||
0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f,
|
||||
0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, 0x008787, 0x0087af,
|
||||
0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff,
|
||||
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f,
|
||||
0x00ff87, 0x00ffaf, 0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af,
|
||||
0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f, 0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff,
|
||||
0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff, 0x5faf00, 0x5faf5f,
|
||||
0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af,
|
||||
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff,
|
||||
0x870000, 0x87005f, 0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f,
|
||||
0x875f87, 0x875faf, 0x875fd7, 0x875fff, 0x878700, 0x87875f, 0x878787, 0x8787af,
|
||||
0x8787d7, 0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf, 0x87afd7, 0x87afff,
|
||||
0x87d700, 0x87d75f, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f,
|
||||
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af,
|
||||
0xaf00d7, 0xaf00ff, 0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff,
|
||||
0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af, 0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f,
|
||||
0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f, 0xafd787, 0xafd7af,
|
||||
0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
|
||||
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f,
|
||||
0xd75f87, 0xd75faf, 0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af,
|
||||
0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f, 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff,
|
||||
0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, 0xd7ff00, 0xd7ff5f,
|
||||
0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
|
||||
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff,
|
||||
0xff8700, 0xff875f, 0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f,
|
||||
0xffaf87, 0xffafaf, 0xffafd7, 0xffafff, 0xffd700, 0xffd75f, 0xffd787, 0xffd7af,
|
||||
0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff,
|
||||
0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
|
||||
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
|
||||
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
|
||||
};
|
||||
return 16 + convert_color(rgb, kColors, sizeof kColors / sizeof *kColors);
|
||||
}
|
||||
|
||||
unsigned char rgb_color_t::to_term256_index() const
|
||||
{
|
||||
assert(type == type_rgb);
|
||||
return term256_color_for_rgb(data.rgb);
|
||||
}
|
||||
|
||||
unsigned char rgb_color_t::to_name_index() const
|
||||
{
|
||||
assert(type == type_named || type == type_rgb);
|
||||
if (type == type_named)
|
||||
{
|
||||
return data.name_idx;
|
||||
}
|
||||
else if (type == type_rgb)
|
||||
{
|
||||
return term8_color_for_rgb(data.rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an error */
|
||||
return (unsigned char)(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void rgb_color_t::parse(const wcstring &str)
|
||||
{
|
||||
bool success = false;
|
||||
if (! success) success = try_parse_special(str);
|
||||
if (! success) success = try_parse_named(str);
|
||||
if (! success) success = try_parse_rgb(str);
|
||||
if (! success)
|
||||
{
|
||||
bzero(this->data.rgb, sizeof this->data.rgb);
|
||||
this->type = type_none;
|
||||
}
|
||||
}
|
||||
|
||||
rgb_color_t::rgb_color_t(const wcstring &str)
|
||||
{
|
||||
this->parse(str);
|
||||
}
|
||||
|
||||
rgb_color_t::rgb_color_t(const std::string &str)
|
||||
{
|
||||
this->parse(str2wcstring(str));
|
||||
}
|
||||
|
||||
wcstring rgb_color_t::description() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case type_none:
|
||||
return L"none";
|
||||
case type_named:
|
||||
return format_string(L"named(%d: %ls)", (int)data.name_idx, name_for_color_idx(data.name_idx));
|
||||
case type_rgb:
|
||||
return format_string(L"rgb(0x%02x%02x%02x)", data.rgb[0], data.rgb[1], data.rgb[2]);
|
||||
case type_reset:
|
||||
return L"reset";
|
||||
case type_normal:
|
||||
return L"normal";
|
||||
case type_ignore:
|
||||
return L"ignore";
|
||||
default:
|
||||
abort();
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
177
color.h
Normal file
177
color.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/** \file color.h Color class.
|
||||
*/
|
||||
#ifndef FISH_COLOR_H
|
||||
#define FISH_COLOR_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/* A type that represents a color. We work hard to keep it at a size of 4 bytes. */
|
||||
class rgb_color_t
|
||||
{
|
||||
|
||||
/* Types */
|
||||
enum
|
||||
{
|
||||
type_none,
|
||||
type_named,
|
||||
type_rgb,
|
||||
type_normal,
|
||||
type_reset,
|
||||
type_ignore
|
||||
};
|
||||
unsigned char type:4;
|
||||
|
||||
/* Flags */
|
||||
enum
|
||||
{
|
||||
flag_bold = 1 << 0,
|
||||
flag_underline = 1 << 1
|
||||
};
|
||||
unsigned char flags:4;
|
||||
|
||||
union
|
||||
{
|
||||
unsigned char name_idx; //0-10
|
||||
unsigned char rgb[3];
|
||||
} data;
|
||||
|
||||
/** Try parsing a special color name like "normal" */
|
||||
bool try_parse_special(const wcstring &str);
|
||||
|
||||
/** Try parsing an rgb color like "#F0A030" */
|
||||
bool try_parse_rgb(const wcstring &str);
|
||||
|
||||
/** Try parsing an explicit color name like "magenta" */
|
||||
bool try_parse_named(const wcstring &str);
|
||||
|
||||
/* Parsing entry point */
|
||||
void parse(const wcstring &str);
|
||||
|
||||
/** Private constructor */
|
||||
explicit rgb_color_t(unsigned char t, unsigned char i=0);
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor of type none */
|
||||
explicit rgb_color_t() : type(type_none), flags(), data() {}
|
||||
|
||||
/** Parse a color from a string */
|
||||
explicit rgb_color_t(const wcstring &str);
|
||||
explicit rgb_color_t(const std::string &str);
|
||||
|
||||
/** Returns white */
|
||||
static rgb_color_t white();
|
||||
|
||||
/** Returns black */
|
||||
static rgb_color_t black();
|
||||
|
||||
/** Returns the reset special color */
|
||||
static rgb_color_t reset();
|
||||
|
||||
/** Returns the normal special color */
|
||||
static rgb_color_t normal();
|
||||
|
||||
/** Returns the ignore special color */
|
||||
static rgb_color_t ignore();
|
||||
|
||||
/** Returns the none special color */
|
||||
static rgb_color_t none();
|
||||
|
||||
/** Returns whether the color is the ignore special color */
|
||||
bool is_ignore(void) const
|
||||
{
|
||||
return type == type_ignore;
|
||||
}
|
||||
|
||||
/** Returns whether the color is the normal special color */
|
||||
bool is_normal(void) const
|
||||
{
|
||||
return type == type_normal;
|
||||
}
|
||||
|
||||
/** Returns whether the color is the reset special color */
|
||||
bool is_reset(void) const
|
||||
{
|
||||
return type == type_reset;
|
||||
}
|
||||
|
||||
/** Returns whether the color is the none special color */
|
||||
bool is_none(void) const
|
||||
{
|
||||
return type == type_none;
|
||||
}
|
||||
|
||||
/** Returns whether the color is a named color (like "magenta") */
|
||||
bool is_named(void) const
|
||||
{
|
||||
return type == type_named;
|
||||
}
|
||||
|
||||
/** Returns whether the color is specified via RGB components */
|
||||
bool is_rgb(void) const
|
||||
{
|
||||
return type == type_rgb;
|
||||
}
|
||||
|
||||
/** Returns whether the color is special, that is, not rgb or named */
|
||||
bool is_special(void) const
|
||||
{
|
||||
return type != type_named && type != type_rgb;
|
||||
}
|
||||
|
||||
/** Returns a description of the color */
|
||||
wcstring description() const;
|
||||
|
||||
/** Returns the name index for the given color. Requires that the color be named or RGB. */
|
||||
unsigned char to_name_index() const;
|
||||
|
||||
/** Returns the term256 index for the given color. Requires that the color be named or RGB. */
|
||||
unsigned char to_term256_index() const;
|
||||
|
||||
/** Returns whether the color is bold */
|
||||
bool is_bold() const
|
||||
{
|
||||
return !!(flags & flag_bold);
|
||||
}
|
||||
|
||||
/** Set whether the color is bold */
|
||||
void set_bold(bool x)
|
||||
{
|
||||
if (x) flags |= flag_bold;
|
||||
else flags &= ~flag_bold;
|
||||
}
|
||||
|
||||
/** Returns whether the color is underlined */
|
||||
bool is_underline() const
|
||||
{
|
||||
return !!(flags & flag_underline);
|
||||
}
|
||||
|
||||
/** Set whether the color is underlined */
|
||||
void set_underline(bool x)
|
||||
{
|
||||
if (x) flags |= flag_underline;
|
||||
else flags &= ~flag_underline;
|
||||
}
|
||||
|
||||
/** Compare two colors for equality */
|
||||
bool operator==(const rgb_color_t &other) const
|
||||
{
|
||||
return type == other.type && ! memcmp(&data, &other.data, sizeof data);
|
||||
}
|
||||
|
||||
/** Compare two colors for inequality */
|
||||
bool operator!=(const rgb_color_t &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
/** Returns the names of all named colors */
|
||||
static wcstring_list_t named_color_names(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
2302
common.cpp
Normal file
2302
common.cpp
Normal file
File diff suppressed because it is too large
Load Diff
531
common.h
531
common.h
@@ -12,9 +12,28 @@
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <termios.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
Avoid writing the type name twice in a common "static_cast-initialization".
|
||||
Caveat: This doesn't work with type names containing commas!
|
||||
*/
|
||||
#define CAST_INIT(type, dst, src) type dst = static_cast<type >(src)
|
||||
|
||||
class completion_t;
|
||||
|
||||
/* Common string type */
|
||||
typedef std::wstring wcstring;
|
||||
typedef std::vector<wcstring> wcstring_list_t;
|
||||
|
||||
/**
|
||||
Maximum number of bytes used by a single utf-8 character
|
||||
*/
|
||||
@@ -50,15 +69,27 @@
|
||||
*/
|
||||
#define UNESCAPE_INCOMPLETE 2
|
||||
|
||||
/**
|
||||
Escape all characters, including magic characters like the semicolon
|
||||
*/
|
||||
#define ESCAPE_ALL 1
|
||||
/**
|
||||
Do not try to use 'simplified' quoted escapes, and do not use empty quotes as the empty string
|
||||
*/
|
||||
#define ESCAPE_NO_QUOTED 2
|
||||
/* Flags for the escape() and escape_string() functions */
|
||||
enum
|
||||
{
|
||||
/** Escape all characters, including magic characters like the semicolon */
|
||||
ESCAPE_ALL = 1 << 0,
|
||||
|
||||
/** Do not try to use 'simplified' quoted escapes, and do not use empty quotes as the empty string */
|
||||
ESCAPE_NO_QUOTED = 1 << 1,
|
||||
|
||||
/** Do not escape tildes */
|
||||
ESCAPE_NO_TILDE = 1 << 2
|
||||
};
|
||||
typedef unsigned int escape_flags_t;
|
||||
|
||||
/**
|
||||
Helper macro for errors
|
||||
*/
|
||||
#define VOMIT_ON_FAILURE(a) do { if (0 != (a)) { int err = errno; fprintf(stderr, "%s failed on line %d in file %s: %d (%s)\n", #a, __LINE__, __FILE__, err, strerror(err)); abort(); }} while (0)
|
||||
|
||||
/** Exits without invoking destructors (via _exit), useful for code after fork. */
|
||||
void exit_without_destructors(int code) __attribute__((noreturn));
|
||||
|
||||
/**
|
||||
Save the shell mode on startup so we can restore them on exit
|
||||
@@ -71,6 +102,9 @@ extern struct termios shell_modes;
|
||||
*/
|
||||
extern wchar_t ellipsis_char;
|
||||
|
||||
/* Character representing an omitted newline at the end of text */
|
||||
extern wchar_t omitted_newline_char;
|
||||
|
||||
/**
|
||||
The verbosity level of fish. If a call to debug has a severity
|
||||
level higher than \c debug_level, it will not be printed.
|
||||
@@ -86,19 +120,19 @@ extern char *profile;
|
||||
Name of the current program. Should be set at startup. Used by the
|
||||
debug function.
|
||||
*/
|
||||
extern wchar_t *program_name;
|
||||
extern const wchar_t *program_name;
|
||||
|
||||
/**
|
||||
This macro is used to check that an input argument is not null. It
|
||||
is a bit lika a non-fatal form of assert. Instead of exit-ing on
|
||||
failiure, the current function is ended at once. The second
|
||||
parameter is the return value of the current function on failiure.
|
||||
failure, the current function is ended at once. The second
|
||||
parameter is the return value of the current function on failure.
|
||||
*/
|
||||
#define CHECK( arg, retval ) \
|
||||
if( !(arg) ) \
|
||||
if (!(arg)) \
|
||||
{ \
|
||||
debug( 0, \
|
||||
_( L"function %s called with null value for argument %s. " ), \
|
||||
"function %s called with null value for argument %s. ", \
|
||||
__func__, \
|
||||
#arg ); \
|
||||
bugreport(); \
|
||||
@@ -111,12 +145,12 @@ extern wchar_t *program_name;
|
||||
*/
|
||||
#define FATAL_EXIT() \
|
||||
{ \
|
||||
int exit_read_count;char exit_read_buff; \
|
||||
char exit_read_buff; \
|
||||
show_stackframe(); \
|
||||
exit_read_count=read( 0, &exit_read_buff, 1 ); \
|
||||
exit( 1 ); \
|
||||
read( 0, &exit_read_buff, 1 ); \
|
||||
exit_without_destructors( 1 ); \
|
||||
} \
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Exit program at once, leaving an error message about running out of memory.
|
||||
@@ -124,8 +158,8 @@ extern wchar_t *program_name;
|
||||
#define DIE_MEM() \
|
||||
{ \
|
||||
fwprintf( stderr, \
|
||||
L"fish: Out of memory on line %d of file %s, shutting down fish\n", \
|
||||
__LINE__, \
|
||||
L"fish: Out of memory on line %ld of file %s, shutting down fish\n", \
|
||||
(long)__LINE__, \
|
||||
__FILE__ ); \
|
||||
FATAL_EXIT(); \
|
||||
}
|
||||
@@ -134,11 +168,11 @@ extern wchar_t *program_name;
|
||||
Check if signals are blocked. If so, print an error message and
|
||||
return from the function performing this check.
|
||||
*/
|
||||
#define CHECK_BLOCK( retval ) \
|
||||
if( signal_is_blocked() ) \
|
||||
#define CHECK_BLOCK(retval) \
|
||||
if (signal_is_blocked()) \
|
||||
{ \
|
||||
debug( 0, \
|
||||
_( L"function %s called while blocking signals. " ), \
|
||||
"function %s called while blocking signals. ", \
|
||||
__func__); \
|
||||
bugreport(); \
|
||||
show_stackframe(); \
|
||||
@@ -157,63 +191,38 @@ extern wchar_t *program_name;
|
||||
#define N_(wstr) wstr
|
||||
|
||||
/**
|
||||
Check if the specified stringelement is a part of the specified string list
|
||||
Check if the specified string element is a part of the specified string list
|
||||
*/
|
||||
#define contains( str,... ) contains_internal( str, __VA_ARGS__, (void *)0 )
|
||||
/**
|
||||
Concatenate all the specified strings into a single newly allocated one
|
||||
*/
|
||||
#define wcsdupcat( str,... ) wcsdupcat_internal( str, __VA_ARGS__, (void *)0 )
|
||||
#define contains( str,... ) contains_internal( str, __VA_ARGS__, NULL )
|
||||
|
||||
/**
|
||||
Print a stack trace to stderr
|
||||
*/
|
||||
void show_stackframe();
|
||||
|
||||
/**
|
||||
Take an array_list_t containing wide strings and converts them to a
|
||||
single null-terminated wchar_t **. The array is allocated using
|
||||
malloc, and needs to be fred's by the caller.
|
||||
*/
|
||||
wchar_t **list_to_char_arr( array_list_t *l );
|
||||
|
||||
/**
|
||||
Read a line from the stream f into the buffer buff of length len. If
|
||||
buff is to small, it will be reallocated, and both buff and len will
|
||||
be updated to reflect this. Returns the number of bytes read or -1
|
||||
on failiure.
|
||||
Read a line from the stream f into the string. Returns
|
||||
the number of bytes read or -1 on failure.
|
||||
|
||||
If the carriage return character is encountered, it is
|
||||
ignored. fgetws() considers the line to end if reading the file
|
||||
results in either a newline (L'\n') character, the null (L'\\0')
|
||||
character or the end of file (WEOF) character.
|
||||
*/
|
||||
int fgetws2( wchar_t **buff, int *len, FILE *f );
|
||||
int fgetws2(wcstring *s, FILE *f);
|
||||
|
||||
|
||||
/**
|
||||
Sorts an array_list of wide strings according to the
|
||||
wcsfilecmp-function from the util library
|
||||
*/
|
||||
void sort_list( array_list_t *comp );
|
||||
Returns a wide character string equivalent of the
|
||||
specified multibyte character string
|
||||
|
||||
/**
|
||||
Returns a newly allocated wide character string equivalent of the
|
||||
specified multibyte character string
|
||||
|
||||
This function encodes illegal character sequences in a reversible
|
||||
way using the private use area.
|
||||
*/
|
||||
wchar_t *str2wcs( const char *in );
|
||||
|
||||
/**
|
||||
Converts the narrow character string \c in into it's wide
|
||||
equivalent, stored in \c out. \c out must have enough space to fit
|
||||
the entire string.
|
||||
|
||||
This function encodes illegal character sequences in a reversible
|
||||
way using the private use area.
|
||||
*/
|
||||
wchar_t *str2wcs_internal( const char *in, wchar_t *out );
|
||||
This function encodes illegal character sequences in a reversible
|
||||
way using the private use area.
|
||||
*/
|
||||
wcstring str2wcstring(const char *in);
|
||||
wcstring str2wcstring(const char *in, size_t len);
|
||||
wcstring str2wcstring(const std::string &in);
|
||||
|
||||
/**
|
||||
Returns a newly allocated multibyte character string equivalent of
|
||||
@@ -222,40 +231,291 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out );
|
||||
This function decodes illegal character sequences in a reversible
|
||||
way using the private use area.
|
||||
*/
|
||||
char *wcs2str( const wchar_t *in );
|
||||
char *wcs2str(const wchar_t *in);
|
||||
char *wcs2str(const wcstring &in);
|
||||
std::string wcs2string(const wcstring &input);
|
||||
|
||||
/** Test if a string prefixes another. Returns true if a is a prefix of b */
|
||||
bool string_prefixes_string(const wcstring &proposed_prefix, const wcstring &value);
|
||||
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value);
|
||||
|
||||
/** Test if a string is a suffix of another */
|
||||
bool string_suffixes_string(const wcstring &proposed_suffix, const wcstring &value);
|
||||
bool string_suffixes_string(const wchar_t *proposed_suffix, const wcstring &value);
|
||||
|
||||
|
||||
/** Test if a string prefixes another without regard to case. Returns true if a is a prefix of b */
|
||||
bool string_prefixes_string_case_insensitive(const wcstring &proposed_prefix, const wcstring &value);
|
||||
|
||||
/** Test if a list contains a string using a linear search. */
|
||||
bool list_contains_string(const wcstring_list_t &list, const wcstring &str);
|
||||
|
||||
|
||||
void assert_is_main_thread(const char *who);
|
||||
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)
|
||||
#define ASSERT_IS_MAIN_THREAD() ASSERT_IS_MAIN_THREAD_TRAMPOLINE(__FUNCTION__)
|
||||
|
||||
void assert_is_background_thread(const char *who);
|
||||
#define ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(x) assert_is_background_thread(x)
|
||||
#define ASSERT_IS_BACKGROUND_THREAD() ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(__FUNCTION__)
|
||||
|
||||
/* Useful macro for asserting that a lock is locked. This doesn't check whether this thread locked it, which it would be nice if it did, but here it is anyways. */
|
||||
void assert_is_locked(void *mutex, const char *who, const char *caller);
|
||||
#define ASSERT_IS_LOCKED(x) assert_is_locked((void *)(&x), #x, __FUNCTION__)
|
||||
|
||||
/** Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer. */
|
||||
wcstring format_size(long long sz);
|
||||
|
||||
/** Version of format_size that does not allocate memory. */
|
||||
void format_size_safe(char buff[128], unsigned long long sz);
|
||||
|
||||
/** Our crappier versions of debug which is guaranteed to not allocate any memory, or do anything other than call write(). This is useful after a call to fork() with threads. */
|
||||
void debug_safe(int level, const char *msg, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL, const char *param5 = NULL, const char *param6 = NULL, const char *param7 = NULL, const char *param8 = NULL, const char *param9 = NULL, const char *param10 = NULL, const char *param11 = NULL, const char *param12 = NULL);
|
||||
|
||||
/** Writes out a long safely */
|
||||
void format_long_safe(char buff[128], long val);
|
||||
void format_long_safe(wchar_t buff[128], long val);
|
||||
|
||||
|
||||
template<typename T>
|
||||
T from_string(const wcstring &x)
|
||||
{
|
||||
T result;
|
||||
std::wstringstream stream(x);
|
||||
stream >> result;
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T from_string(const std::string &x)
|
||||
{
|
||||
T result = T();
|
||||
std::stringstream stream(x);
|
||||
stream >> result;
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wcstring to_string(const T &x)
|
||||
{
|
||||
std::wstringstream stream;
|
||||
stream << x;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
/* wstringstream is a huge memory pig. Let's provide some specializations where we can. */
|
||||
template<>
|
||||
inline wcstring to_string(const long &x)
|
||||
{
|
||||
wchar_t buff[128];
|
||||
format_long_safe(buff, x);
|
||||
return wcstring(buff);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool from_string(const std::string &x)
|
||||
{
|
||||
return ! x.empty() && strchr("YTyt1", x.at(0));
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool from_string(const wcstring &x)
|
||||
{
|
||||
return ! x.empty() && wcschr(L"YTyt1", x.at(0));
|
||||
}
|
||||
|
||||
template<>
|
||||
inline wcstring to_string(const int &x)
|
||||
{
|
||||
return to_string(static_cast<long>(x));
|
||||
}
|
||||
|
||||
wchar_t **make_null_terminated_array(const wcstring_list_t &lst);
|
||||
char **make_null_terminated_array(const std::vector<std::string> &lst);
|
||||
|
||||
/* Helper class for managing a null-terminated array of null-terminated strings (of some char type) */
|
||||
template <typename CharType_t>
|
||||
class null_terminated_array_t
|
||||
{
|
||||
CharType_t **array;
|
||||
|
||||
/* No assignment or copying */
|
||||
void operator=(null_terminated_array_t rhs);
|
||||
null_terminated_array_t(const null_terminated_array_t &);
|
||||
|
||||
typedef std::vector<std::basic_string<CharType_t> > string_list_t;
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
size_t len = 0;
|
||||
if (array != NULL)
|
||||
{
|
||||
while (array[len] != NULL)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void free(void)
|
||||
{
|
||||
::free((void *)array);
|
||||
array = NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
null_terminated_array_t() : array(NULL) { }
|
||||
null_terminated_array_t(const string_list_t &argv) : array(make_null_terminated_array(argv))
|
||||
{
|
||||
}
|
||||
|
||||
~null_terminated_array_t()
|
||||
{
|
||||
this->free();
|
||||
}
|
||||
|
||||
void set(const string_list_t &argv)
|
||||
{
|
||||
this->free();
|
||||
this->array = make_null_terminated_array(argv);
|
||||
}
|
||||
|
||||
const CharType_t * const *get() const
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
this->free();
|
||||
}
|
||||
};
|
||||
|
||||
/* Helper function to convert from a null_terminated_array_t<wchar_t> to a null_terminated_array_t<char_t> */
|
||||
void convert_wide_array_to_narrow(const null_terminated_array_t<wchar_t> &arr, null_terminated_array_t<char> *output);
|
||||
|
||||
/* Helper class to cache a narrow version of a wcstring in a malloc'd buffer, so that we can read it after fork() */
|
||||
class narrow_string_rep_t
|
||||
{
|
||||
private:
|
||||
const char *str;
|
||||
|
||||
/* No copying */
|
||||
narrow_string_rep_t &operator=(const narrow_string_rep_t &);
|
||||
narrow_string_rep_t(const narrow_string_rep_t &x);
|
||||
|
||||
public:
|
||||
~narrow_string_rep_t()
|
||||
{
|
||||
free((void *)str);
|
||||
}
|
||||
|
||||
narrow_string_rep_t() : str(NULL) {}
|
||||
|
||||
void set(const wcstring &s)
|
||||
{
|
||||
free((void *)str);
|
||||
str = wcs2str(s.c_str());
|
||||
}
|
||||
|
||||
const char *get() const
|
||||
{
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
bool is_forked_child();
|
||||
|
||||
/* Basic scoped lock class */
|
||||
class scoped_lock
|
||||
{
|
||||
pthread_mutex_t *lock_obj;
|
||||
bool locked;
|
||||
|
||||
/* No copying */
|
||||
scoped_lock &operator=(const scoped_lock &);
|
||||
scoped_lock(const scoped_lock &);
|
||||
|
||||
public:
|
||||
void lock(void);
|
||||
void unlock(void);
|
||||
scoped_lock(pthread_mutex_t &mutex);
|
||||
~scoped_lock();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Converts the wide character string \c in into it's narrow
|
||||
equivalent, stored in \c out. \c out must have enough space to fit
|
||||
the entire string.
|
||||
A scoped manager to save the current value of some variable, and optionally
|
||||
set it to a new value. On destruction it restores the variable to its old
|
||||
value.
|
||||
|
||||
This function decodes illegal character sequences in a reversible
|
||||
way using the private use area.
|
||||
This can be handy when there are multiple code paths to exit a block.
|
||||
*/
|
||||
char *wcs2str_internal( const wchar_t *in, char *out );
|
||||
template <typename T>
|
||||
class scoped_push
|
||||
{
|
||||
T * const ref;
|
||||
T saved_value;
|
||||
bool restored;
|
||||
|
||||
public:
|
||||
scoped_push(T *r): ref(r), saved_value(*r), restored(false)
|
||||
{
|
||||
}
|
||||
|
||||
scoped_push(T *r, const T &new_value) : ref(r), saved_value(*r), restored(false)
|
||||
{
|
||||
*r = new_value;
|
||||
}
|
||||
|
||||
~scoped_push()
|
||||
{
|
||||
restore();
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
if (!restored)
|
||||
{
|
||||
std::swap(*ref, saved_value);
|
||||
restored = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Wrapper around wcstok */
|
||||
class wcstokenizer
|
||||
{
|
||||
wchar_t *buffer, *str, *state;
|
||||
const wcstring sep;
|
||||
|
||||
/* No copying */
|
||||
wcstokenizer &operator=(const wcstokenizer &);
|
||||
wcstokenizer(const wcstokenizer &);
|
||||
|
||||
public:
|
||||
wcstokenizer(const wcstring &s, const wcstring &separator);
|
||||
bool next(wcstring &result);
|
||||
~wcstokenizer();
|
||||
};
|
||||
|
||||
/**
|
||||
Appends a path component, with a / if necessary
|
||||
*/
|
||||
void append_path_component(wcstring &path, const wcstring &component);
|
||||
|
||||
wcstring format_string(const wchar_t *format, ...);
|
||||
wcstring vformat_string(const wchar_t *format, va_list va_orig);
|
||||
void append_format(wcstring &str, const wchar_t *format, ...);
|
||||
void append_formatv(wcstring &str, const wchar_t *format, va_list ap);
|
||||
|
||||
/**
|
||||
Returns a newly allocated wide character string array equivalent of
|
||||
the specified multibyte character string array
|
||||
*/
|
||||
char **wcsv2strv( const wchar_t **in );
|
||||
|
||||
/**
|
||||
Returns a newly allocated multibyte character string array equivalent of the specified wide character string array
|
||||
*/
|
||||
wchar_t **strv2wcsv( const char **in );
|
||||
|
||||
|
||||
/**
|
||||
Returns a newly allocated concatenation of the specified wide
|
||||
character strings. The last argument must be a null pointer.
|
||||
*/
|
||||
__sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
|
||||
|
||||
/**
|
||||
Test if the given string is a valid variable name
|
||||
*/
|
||||
|
||||
char **wcsv2strv(const wchar_t * const *in);
|
||||
|
||||
/**
|
||||
Test if the given string is a valid variable name.
|
||||
@@ -263,7 +523,7 @@ __sentinel wchar_t *wcsdupcat_internal( const wchar_t *a, ... );
|
||||
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
||||
*/
|
||||
|
||||
wchar_t *wcsvarname( const wchar_t *str );
|
||||
wchar_t *wcsvarname(const wchar_t *str);
|
||||
|
||||
|
||||
/**
|
||||
@@ -272,7 +532,7 @@ wchar_t *wcsvarname( const wchar_t *str );
|
||||
\return null if this is a valid name, and a pointer to the first invalid character otherwise
|
||||
*/
|
||||
|
||||
wchar_t *wcsfuncname( const wchar_t *str );
|
||||
const wchar_t *wcsfuncname(const wchar_t *str);
|
||||
|
||||
/**
|
||||
Test if the given string is valid in a variable name
|
||||
@@ -280,13 +540,13 @@ wchar_t *wcsfuncname( const wchar_t *str );
|
||||
\return 1 if this is a valid name, 0 otherwise
|
||||
*/
|
||||
|
||||
int wcsvarchr( wchar_t chr );
|
||||
int wcsvarchr(wchar_t chr);
|
||||
|
||||
|
||||
/**
|
||||
A wcswidth workalike. Fish uses this since the regular wcswidth seems flaky.
|
||||
*/
|
||||
int my_wcswidth( const wchar_t *c );
|
||||
int my_wcswidth(const wchar_t *c);
|
||||
|
||||
/**
|
||||
This functions returns the end of the quoted substring beginning at
|
||||
@@ -295,7 +555,7 @@ int my_wcswidth( const wchar_t *c );
|
||||
|
||||
\param in the position of the opening quote
|
||||
*/
|
||||
wchar_t *quote_end( const wchar_t *in );
|
||||
wchar_t *quote_end(const wchar_t *in);
|
||||
|
||||
/**
|
||||
A call to this function will reset the error counter. Some
|
||||
@@ -313,7 +573,7 @@ void error_reset();
|
||||
the user is using a Unicode character set, and if so, use the
|
||||
unicode ellipsis character as ellipsis, instead of '$'.
|
||||
*/
|
||||
const wchar_t *wsetlocale( int category, const wchar_t *locale );
|
||||
wcstring wsetlocale(int category, const wchar_t *locale);
|
||||
|
||||
/**
|
||||
Checks if \c needle is included in the list of strings specified. A warning is printed if needle is zero.
|
||||
@@ -322,20 +582,27 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale );
|
||||
|
||||
\return zero if needle is not found, of if needle is null, non-zero otherwise
|
||||
*/
|
||||
__sentinel int contains_internal( const wchar_t *needle, ... );
|
||||
__sentinel bool contains_internal(const wchar_t *needle, ...);
|
||||
__sentinel bool contains_internal(const wcstring &needle, ...);
|
||||
|
||||
/**
|
||||
Call read while blocking the SIGCHLD signal. Should only be called
|
||||
if you _know_ there is data available for reading, or the program
|
||||
will hang until there is data.
|
||||
*/
|
||||
int read_blocked(int fd, void *buf, size_t count);
|
||||
long read_blocked(int fd, void *buf, size_t count);
|
||||
|
||||
/**
|
||||
Loop a write request while failiure is non-critical. Return -1 and set errno
|
||||
Loop a write request while failure is non-critical. Return -1 and set errno
|
||||
in case of critical error.
|
||||
*/
|
||||
ssize_t write_loop(int fd, char *buff, size_t count);
|
||||
ssize_t write_loop(int fd, const char *buff, size_t count);
|
||||
|
||||
/**
|
||||
Loop a read request while failure is non-critical. Return -1 and set errno
|
||||
in case of critical error.
|
||||
*/
|
||||
ssize_t read_loop(int fd, void *buff, size_t count);
|
||||
|
||||
|
||||
/**
|
||||
@@ -356,7 +623,8 @@ ssize_t write_loop(int fd, char *buff, size_t count);
|
||||
|
||||
will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that program_name is 'fish'.
|
||||
*/
|
||||
void debug( int level, const wchar_t *msg, ... );
|
||||
void debug(int level, const char *msg, ...);
|
||||
void debug(int level, const wchar_t *msg, ...);
|
||||
|
||||
/**
|
||||
Replace special characters with backslash escape sequences. Newline is
|
||||
@@ -367,7 +635,8 @@ void debug( int level, const wchar_t *msg, ... );
|
||||
\return The escaped string, or 0 if there is not enough memory
|
||||
*/
|
||||
|
||||
wchar_t *escape( const wchar_t *in, int escape_all );
|
||||
wchar_t *escape(const wchar_t *in, escape_flags_t flags);
|
||||
wcstring escape_string(const wcstring &in, escape_flags_t flags);
|
||||
|
||||
/**
|
||||
Expand backslashed escapes and substitute them with their unescaped
|
||||
@@ -380,19 +649,12 @@ wchar_t *escape( const wchar_t *in, int escape_all );
|
||||
an invalid sequence is specified, 0 is returned.
|
||||
|
||||
*/
|
||||
wchar_t *unescape( const wchar_t * in,
|
||||
int escape_special );
|
||||
wchar_t *unescape(const wchar_t * in,
|
||||
int escape_special);
|
||||
|
||||
bool unescape_string(wcstring &str,
|
||||
int escape_special);
|
||||
|
||||
/**
|
||||
Attempt to acquire a lock based on a lockfile, waiting LOCKPOLLINTERVAL
|
||||
milliseconds between polls and timing out after timeout seconds,
|
||||
thereafter forcibly attempting to obtain the lock if force is non-zero.
|
||||
Returns 1 on success, 0 on failure.
|
||||
To release the lock the lockfile must be unlinked.
|
||||
A unique temporary file named by appending characters to the lockfile name
|
||||
is used; any pre-existing file of the same name is subject to deletion.
|
||||
*/
|
||||
int acquire_lock_file( const char *lockfile, const int timeout, int force );
|
||||
|
||||
/**
|
||||
Returns the width of the terminal window, so that not all
|
||||
@@ -416,23 +678,20 @@ int common_get_height();
|
||||
saving it in an internal variable used by common_get_wisth and
|
||||
common_get_height().
|
||||
*/
|
||||
void common_handle_winch( int signal );
|
||||
void common_handle_winch(int signal);
|
||||
|
||||
/**
|
||||
Write paragraph of output to the specified stringbuffer, and redo
|
||||
the linebreaks to fit the current screen.
|
||||
*/
|
||||
void write_screen( const wchar_t *msg, string_buffer_t *buff );
|
||||
void write_screen(const wcstring &msg, wcstring &buff);
|
||||
|
||||
/**
|
||||
Tokenize the specified string into the specified array_list_t.
|
||||
Each new element is allocated using malloc and must be freed by the
|
||||
caller.
|
||||
|
||||
Tokenize the specified string into the specified wcstring_list_t.
|
||||
\param val the input string. The contents of this string is not changed.
|
||||
\param out the list in which to place the elements.
|
||||
*/
|
||||
void tokenize_variable_array( const wchar_t *val, array_list_t *out );
|
||||
void tokenize_variable_array(const wcstring &val, wcstring_list_t &out);
|
||||
|
||||
/**
|
||||
Make sure the specified direcotry exists. If needed, try to create
|
||||
@@ -440,19 +699,13 @@ void tokenize_variable_array( const wchar_t *val, array_list_t *out );
|
||||
|
||||
\return 0 if, at the time of function return the directory exists, -1 otherwise.
|
||||
*/
|
||||
int create_directory( wchar_t *d );
|
||||
int create_directory(const wcstring &d);
|
||||
|
||||
/**
|
||||
Print a short message about how to file a bug report to stderr
|
||||
*/
|
||||
void bugreport();
|
||||
|
||||
/**
|
||||
Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer.
|
||||
*/
|
||||
void sb_format_size( string_buffer_t *sb,
|
||||
long long sz );
|
||||
|
||||
/**
|
||||
Return the number of seconds from the UNIX epoch, with subsecond
|
||||
precision. This function uses the gettimeofday function, and will
|
||||
@@ -462,6 +715,34 @@ void sb_format_size( string_buffer_t *sb,
|
||||
*/
|
||||
double timef();
|
||||
|
||||
/**
|
||||
Call the following function early in main to set the main thread.
|
||||
This is our replacement for pthread_main_np().
|
||||
*/
|
||||
void set_main_thread();
|
||||
bool is_main_thread();
|
||||
|
||||
/** Configures thread assertions for testing */
|
||||
void configure_thread_assertions_for_testing();
|
||||
|
||||
/** Set up a guard to complain if we try to do certain things (like take a lock) after calling fork */
|
||||
void setup_fork_guards(void);
|
||||
|
||||
/** Save the value of tcgetpgrp so we can restore it on exit */
|
||||
void save_term_foreground_process_group(void);
|
||||
void restore_term_foreground_process_group(void);
|
||||
|
||||
/** Return whether we are the child of a fork */
|
||||
bool is_forked_child(void);
|
||||
void assert_is_not_forked_child(const char *who);
|
||||
#define ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(x) assert_is_not_forked_child(x)
|
||||
#define ASSERT_IS_NOT_FORKED_CHILD() ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(__FUNCTION__)
|
||||
|
||||
extern "C" {
|
||||
__attribute__((noinline)) void debug_thread_error(void);
|
||||
}
|
||||
|
||||
/** Return the path of an appropriate runtime data directory */
|
||||
std::string common_get_runtime_path();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
2158
complete.c
2158
complete.c
File diff suppressed because it is too large
Load Diff
2102
complete.cpp
Normal file
2102
complete.cpp
Normal file
File diff suppressed because it is too large
Load Diff
298
complete.h
298
complete.h
@@ -1,8 +1,8 @@
|
||||
/** \file complete.h
|
||||
Prototypes for functions related to tab-completion.
|
||||
Prototypes for functions related to tab-completion.
|
||||
|
||||
These functions are used for storing and retrieving tab-completion
|
||||
data, as well as for performing tab-completion.
|
||||
These functions are used for storing and retrieving tab-completion
|
||||
data, as well as for performing tab-completion.
|
||||
*/
|
||||
|
||||
#ifndef FISH_COMPLETE_H
|
||||
@@ -12,123 +12,153 @@
|
||||
*/
|
||||
#define FISH_COMPLETE_H
|
||||
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include "common.h"
|
||||
/**
|
||||
Use all completions
|
||||
*/
|
||||
* Use all completions
|
||||
*/
|
||||
#define SHARED 0
|
||||
/**
|
||||
Do not use file completion
|
||||
*/
|
||||
* Do not use file completion
|
||||
*/
|
||||
#define NO_FILES 1
|
||||
/**
|
||||
Require a parameter after completion
|
||||
*/
|
||||
* Require a parameter after completion
|
||||
*/
|
||||
#define NO_COMMON 2
|
||||
/**
|
||||
Only use the argument list specifies with completion after
|
||||
option. This is the same as (NO_FILES & NO_COMMON)
|
||||
*/
|
||||
* Only use the argument list specifies with completion after
|
||||
* option. This is the same as (NO_FILES & NO_COMMON)
|
||||
*/
|
||||
#define EXCLUSIVE 3
|
||||
|
||||
/**
|
||||
Command is a path
|
||||
*/
|
||||
* Command is a path
|
||||
*/
|
||||
#define PATH 1
|
||||
/**
|
||||
Command is not a path
|
||||
*/
|
||||
* Command is not a path
|
||||
*/
|
||||
#define COMMAND 0
|
||||
|
||||
/**
|
||||
Separator between completion and description
|
||||
*/
|
||||
* Separator between completion and description
|
||||
*/
|
||||
#define COMPLETE_SEP L'\004'
|
||||
|
||||
/**
|
||||
Separator between completion and description
|
||||
*/
|
||||
* Separator between completion and description
|
||||
*/
|
||||
#define COMPLETE_SEP_STR L"\004"
|
||||
|
||||
/**
|
||||
Separator between completion items in fish_pager. This is used for
|
||||
completion grouping, e.g. when putting completions with the same
|
||||
descriptions on the same line.
|
||||
*/
|
||||
* Separator between completion items in fish_pager. This is used for
|
||||
* completion grouping, e.g. when putting completions with the same
|
||||
* descriptions on the same line.
|
||||
*/
|
||||
#define COMPLETE_ITEM_SEP L'\uf500'
|
||||
|
||||
/**
|
||||
Character that separates the completion and description on
|
||||
programmable completions
|
||||
*/
|
||||
* Character that separates the completion and description on
|
||||
* programmable completions
|
||||
*/
|
||||
#define PROG_COMPLETE_SEP L'\t'
|
||||
|
||||
/**
|
||||
Do not insert space afterwards if this is the only completion. (The
|
||||
default is to try insert a space)
|
||||
*/
|
||||
#define COMPLETE_NO_SPACE 1
|
||||
enum
|
||||
{
|
||||
/**
|
||||
Do not insert space afterwards if this is the only completion. (The
|
||||
default is to try insert a space)
|
||||
*/
|
||||
COMPLETE_NO_SPACE = 1 << 0,
|
||||
|
||||
/**
|
||||
This compeltion is case insensitive.
|
||||
/** This completion is case insensitive. */
|
||||
COMPLETE_CASE_INSENSITIVE = 1 << 1,
|
||||
|
||||
Warning: The contents of the completion_t structure is actually
|
||||
different if this flag is set! Specifically, the completion string
|
||||
contains the _entire_ completion token, not only the current
|
||||
*/
|
||||
#define COMPLETE_NO_CASE 2
|
||||
/** This is not the suffix of a token, but replaces it entirely */
|
||||
COMPLETE_REPLACES_TOKEN = 1 << 2,
|
||||
|
||||
/**
|
||||
This compeltion is the whole argument, not just the remainder. This
|
||||
flag must never be set on completions returned from the complete()
|
||||
function. It is strictly for internal use in the completion code.
|
||||
*/
|
||||
#define COMPLETE_WHOLE_ARGUMENT 4
|
||||
/**
|
||||
This completion may or may not want a space at the end - guess by
|
||||
checking the last character of the completion.
|
||||
*/
|
||||
COMPLETE_AUTO_SPACE = 1 << 3,
|
||||
|
||||
/**
|
||||
This completion may or may not want a space at the end - guess by
|
||||
checking the last character of the completion.
|
||||
*/
|
||||
#define COMPLETE_AUTO_SPACE 8
|
||||
/** This completion should be inserted as-is, without escaping. */
|
||||
COMPLETE_DONT_ESCAPE = 1 << 4,
|
||||
|
||||
/**
|
||||
This completion should be inserted as-is, without escaping.
|
||||
*/
|
||||
#define COMPLETE_DONT_ESCAPE 16
|
||||
/** If you do escape, don't escape tildes */
|
||||
COMPLETE_DONT_ESCAPE_TILDES = 1 << 5
|
||||
};
|
||||
typedef int complete_flags_t;
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
class completion_t
|
||||
{
|
||||
|
||||
/**
|
||||
The completion string
|
||||
*/
|
||||
const wchar_t *completion;
|
||||
private:
|
||||
/* No public default constructor */
|
||||
completion_t();
|
||||
public:
|
||||
|
||||
/**
|
||||
The description for this completion
|
||||
*/
|
||||
const wchar_t *description;
|
||||
/* Destructor. Not inlining it saves code size. */
|
||||
~completion_t();
|
||||
|
||||
/**
|
||||
Flags determining the completion behaviour.
|
||||
/**
|
||||
The completion string
|
||||
*/
|
||||
wcstring completion;
|
||||
|
||||
Determines whether a space should be inserted after this
|
||||
compeltion if it is the only possible completion using the
|
||||
COMPLETE_NO_SPACE flag.
|
||||
/**
|
||||
The description for this completion
|
||||
*/
|
||||
wcstring description;
|
||||
|
||||
The COMPLETE_NO_CASE can be used to signal that this completion
|
||||
is case insensitive.
|
||||
*/
|
||||
int flags;
|
||||
/**
|
||||
Flags determining the completion behaviour.
|
||||
|
||||
}
|
||||
completion_t;
|
||||
Determines whether a space should be inserted after this
|
||||
completion if it is the only possible completion using the
|
||||
COMPLETE_NO_SPACE flag.
|
||||
|
||||
The COMPLETE_NO_CASE can be used to signal that this completion
|
||||
is case insensitive.
|
||||
*/
|
||||
int flags;
|
||||
|
||||
bool is_case_insensitive() const
|
||||
{
|
||||
return !!(flags & COMPLETE_CASE_INSENSITIVE);
|
||||
}
|
||||
|
||||
/* Construction. Note: defining these so that they are not inlined reduces the executable size. */
|
||||
completion_t(const wcstring &comp, const wcstring &desc = L"", int flags_val = 0);
|
||||
completion_t(const completion_t &);
|
||||
completion_t &operator=(const completion_t &);
|
||||
|
||||
/* The following are needed for sorting and uniquing completions */
|
||||
bool operator < (const completion_t& rhs) const;
|
||||
bool operator == (const completion_t& rhs) const;
|
||||
bool operator != (const completion_t& rhs) const;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
COMPLETION_REQUEST_DEFAULT = 0,
|
||||
COMPLETION_REQUEST_AUTOSUGGESTION = 1 << 0, // indicates the completion is for an autosuggestion
|
||||
COMPLETION_REQUEST_DESCRIPTIONS = 1 << 1, // indicates that we want descriptions
|
||||
COMPLETION_REQUEST_FUZZY_MATCH = 1 << 2 // indicates that we don't require a prefix match
|
||||
};
|
||||
typedef uint32_t completion_request_flags_t;
|
||||
|
||||
/** Given a list of completions, returns a list of their completion fields */
|
||||
wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &completions);
|
||||
|
||||
/** Sorts a list of completions */
|
||||
void sort_completions(std::vector<completion_t> &completions);
|
||||
|
||||
/**
|
||||
|
||||
@@ -155,83 +185,83 @@ typedef struct
|
||||
|
||||
\param cmd Command to complete.
|
||||
\param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
||||
path of the program (optionally containing wildcards), otherwise it
|
||||
will be interpreted as the command name.
|
||||
\param short_opt The single character name of an option. (-a is a short option, --all and -funroll are long options)
|
||||
\param long_opt The multi character name of an option. (-a is a short option, --all and -funroll are long options)
|
||||
path of the program (optionally containing wildcards), otherwise it
|
||||
will be interpreted as the command name.
|
||||
\param short_opt The single character name of an option. (-a is a short option,
|
||||
--all and -funroll are long options)
|
||||
\param long_opt The multi character name of an option. (-a is a short option,
|
||||
--all and -funroll are long options)
|
||||
\param long_mode Whether to use old style, single dash long options.
|
||||
\param result_mode Whether to search further completions when this
|
||||
completion has been succesfully matched. If result_mode is SHARED,
|
||||
any other completions may also be used. If result_mode is NO_FILES,
|
||||
file completion should not be used, but other completions may be
|
||||
used. If result_mode is NO_COMMON, on option may follow it - only a
|
||||
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
||||
file completion is not performed.
|
||||
completion has been succesfully matched. If result_mode is SHARED,
|
||||
any other completions may also be used. If result_mode is NO_FILES,
|
||||
file completion should not be used, but other completions may be
|
||||
used. If result_mode is NO_COMMON, on option may follow it - only a
|
||||
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
||||
file completion is not performed.
|
||||
\param comp A space separated list of completions which may contain subshells.
|
||||
\param desc A description of the completion.
|
||||
\param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used.
|
||||
\param condition a command to be run to check it this completion should be used.
|
||||
If \c condition is empty, the completion is always used.
|
||||
\param flags A set of completion flags
|
||||
*/
|
||||
void complete_add( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt,
|
||||
int long_mode,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags );
|
||||
void complete_add(const wchar_t *cmd,
|
||||
bool cmd_is_path,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt,
|
||||
int long_mode,
|
||||
int result_mode,
|
||||
const wchar_t *condition,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags);
|
||||
/**
|
||||
Sets whether the completion list for this command is complete. If
|
||||
true, any options not matching one of the provided options will be
|
||||
flagged as an error by syntax highlighting.
|
||||
*/
|
||||
void complete_set_authoritative( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
int authoritative );
|
||||
void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authoritative);
|
||||
|
||||
/**
|
||||
Remove a previously defined completion
|
||||
*/
|
||||
void complete_remove( const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt );
|
||||
void complete_remove(const wchar_t *cmd,
|
||||
bool cmd_is_path,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt);
|
||||
|
||||
|
||||
/** Find all completions of the command cmd, insert them into out. If to_load is
|
||||
* not NULL, append all commands that we would autoload, but did not (presumably
|
||||
* because this is not the main thread)
|
||||
*/
|
||||
void complete(const wcstring &cmd,
|
||||
std::vector<completion_t> &comp,
|
||||
completion_request_flags_t flags,
|
||||
wcstring_list_t *to_load = NULL);
|
||||
|
||||
/**
|
||||
Find all completions of the command cmd, insert them into out. The
|
||||
caller must free the variables returned in out. The results are
|
||||
returned in the array_list_t 'out', in the format of wide character
|
||||
strings, with each element consisting of a suggested completion and
|
||||
a description of what kind of object this completion represents,
|
||||
separated by a separator of type COMPLETE_SEP.
|
||||
Print a list of all current completions into the string.
|
||||
|
||||
Values returned by this function should be freed by the caller.
|
||||
\param out The string to write completions to
|
||||
*/
|
||||
void complete( const wchar_t *cmd, array_list_t *out );
|
||||
|
||||
/**
|
||||
Print a list of all current completions into the string_buffer_t.
|
||||
|
||||
\param out The string_buffer_t to write completions to
|
||||
*/
|
||||
void complete_print( string_buffer_t *out );
|
||||
void complete_print(wcstring &out);
|
||||
|
||||
/**
|
||||
Tests if the specified option is defined for the specified command
|
||||
*/
|
||||
int complete_is_valid_option( const wchar_t *str,
|
||||
const wchar_t *opt,
|
||||
array_list_t *errors );
|
||||
int complete_is_valid_option(const wcstring &str,
|
||||
const wcstring &opt,
|
||||
wcstring_list_t *inErrorsOrNull,
|
||||
bool allow_autoload);
|
||||
|
||||
/**
|
||||
Tests if the specified argument is valid for the specified option
|
||||
and command
|
||||
*/
|
||||
int complete_is_valid_argument( const wchar_t *str,
|
||||
const wchar_t *opt,
|
||||
const wchar_t *arg );
|
||||
bool complete_is_valid_argument(const wcstring &str,
|
||||
const wcstring &opt,
|
||||
const wcstring &arg);
|
||||
|
||||
|
||||
/**
|
||||
@@ -241,22 +271,24 @@ int complete_is_valid_argument( const wchar_t *str,
|
||||
with internal dependencies.
|
||||
|
||||
\param cmd the command for which to load command-specific completions
|
||||
\param reload should the commands completions be reloaded, even if they where previously loaded. (This is set to true on actual completions, so that changed completion are updated in running shells)
|
||||
\param reload should the commands completions be reloaded, even if they where
|
||||
previously loaded. (This is set to true on actual completions, so that
|
||||
changed completion are updated in running shells)
|
||||
*/
|
||||
void complete_load( const wchar_t *cmd, int reload );
|
||||
void complete_load(const wcstring &cmd, bool reload);
|
||||
|
||||
/**
|
||||
Create a new completion entry
|
||||
|
||||
\param context The halloc context to use for allocating new memory
|
||||
\param completions The array of completions to append to
|
||||
\param comp The completion string
|
||||
\param desc The description of the completion
|
||||
\param flags completion flags
|
||||
*/
|
||||
void completion_allocate( array_list_t *context,
|
||||
const wchar_t *comp,
|
||||
const wchar_t *desc,
|
||||
int flags );
|
||||
|
||||
*/
|
||||
void append_completion(std::vector<completion_t> &completions, const wcstring &comp, const wcstring &desc = L"", int flags = 0);
|
||||
|
||||
/* Function used for testing */
|
||||
void complete_set_variable_names(const wcstring_list_t *names);
|
||||
|
||||
#endif
|
||||
|
||||
942
configure.ac
942
configure.ac
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,29 @@ alias NAME=DEFINITION</pre>
|
||||
|
||||
\subsection alias-description Description
|
||||
|
||||
Alias is a shellscript wrapper around the function builtin.
|
||||
\c alias is a simple wrapper for the \c function builtin.
|
||||
It exists for backwards compatibility with Posix
|
||||
shells. For other uses, it is recommended to define a <a
|
||||
href='#function'>function</a>.
|
||||
|
||||
Alias does not keep track of which functions have been defined using
|
||||
alias, nor does it allow erasing of aliases.
|
||||
\c fish does not keep track of which functions have been defined using
|
||||
\c alias. They must be erased using <code>functions -e</code>.
|
||||
|
||||
- NAME is the name of the alias
|
||||
- DEFINITION is the actual command to execute. The string " $argv" will be appended.
|
||||
|
||||
You cannot create an alias to a function with the same name.
|
||||
|
||||
\subsection alias-example Example
|
||||
|
||||
The following code will create \c rmi, which runs \c rm with additional
|
||||
arguments on every invocation.
|
||||
|
||||
<code>alias rmi "rm -i"</code>
|
||||
|
||||
This is equivalent to entering the following function:
|
||||
|
||||
<pre>function rmi
|
||||
rm -i $argv
|
||||
end</pre>
|
||||
|
||||
- NAME is the name of the function to define
|
||||
- DEFINITION is the body of the function. The string " $argv" will be appended to the body.
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
\subsection and-description Description
|
||||
|
||||
The \c and builtin is used to execute a command if the current exit
|
||||
\c and is used to execute a command if the current exit
|
||||
status (as set by the last previous command) is 0.
|
||||
|
||||
The and command does not change the current exit status.
|
||||
\c and does not change the current exit status.
|
||||
|
||||
The exit status of the last foreground command to exit can always be
|
||||
accessed using the <a href="index.html#variables-status">$status</a>
|
||||
@@ -16,10 +16,10 @@ variable.
|
||||
|
||||
\subsection and-example Example
|
||||
|
||||
The following code runs the \c make command to build a program, if the
|
||||
build succeeds, the program is installed. If either step fails,
|
||||
<tt>make clean</tt> is run, which removes the files created by the
|
||||
build process
|
||||
The following code runs the \c make command to build a program. If the
|
||||
build succeeds, <code>make</code>'s exit status is 0, and the program is installed. If either step fails,
|
||||
the exit status is 1, and <tt>make clean</tt> is run, which removes the files created by the.
|
||||
build process.
|
||||
|
||||
<pre>
|
||||
make; and make install; or make clean
|
||||
|
||||
@@ -5,15 +5,18 @@
|
||||
|
||||
\subsection begin-description Description
|
||||
|
||||
The \c begin builtin is used to create a new block of code. The block
|
||||
\c begin is used to create a new block of code.
|
||||
|
||||
The block
|
||||
is unconditionally executed. <code>begin; ...; end</tt> is equivalent
|
||||
to <tt>if true; ...; end</tt>. The begin command is used to group any
|
||||
number of commands into a block. The reason for doing so is usually
|
||||
either to introduce a new variable scope, to redirect the input or
|
||||
to <tt>if true; ...; end</tt>.
|
||||
|
||||
\c begin is used to group a number of commands into a block.
|
||||
This allows the introduction of a new variable scope, redirection of the input or
|
||||
output of a set of commands as a group, or to specify precedence when
|
||||
using the conditional commands like \c and.
|
||||
|
||||
The \c begin command does not change the current exit status.
|
||||
\c begin does not change the current exit status.
|
||||
|
||||
\subsection begin-example Example
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
\section bg bg - send to background
|
||||
\section bg bg - send jobs to background
|
||||
|
||||
\subsection bg-synopsis Synopsis
|
||||
<tt>bg [PID...]</tt>
|
||||
|
||||
\subsection bg-description Description
|
||||
Sends the specified jobs to the background. A background job is
|
||||
|
||||
\c bg sends <a href="index.html#syntax-job-control">jobs</a> to the background, resuming them if they are stopped. A background job is
|
||||
executed simultaneously with fish, and does not have access to the
|
||||
keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified group ids are put in the background.
|
||||
keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified process group IDs are put in the background.
|
||||
|
||||
The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.
|
||||
|
||||
\subsection bg-example Example
|
||||
|
||||
<tt>bg \%0</tt> will put the job with job id 0 in the background.
|
||||
<tt>bg \%1</tt> will put the job with job ID 1 in the background.
|
||||
|
||||
|
||||
@@ -5,33 +5,34 @@
|
||||
|
||||
\subsection bind-description Description
|
||||
|
||||
The <tt>bind</tt> builtin causes fish to add a key binding from the specified sequence.
|
||||
<tt>bind</tt> adds a binding for the specified key sequence to the
|
||||
specified command.
|
||||
|
||||
SEQUENCE is the character sequence to bind to. Usually, one would use
|
||||
fish escape sequences to express them. For example, because pressing
|
||||
SEQUENCE is the character sequence to bind to. These should be written as
|
||||
<a href="index.html#escapes">fish escape sequences</a>. For example, because pressing
|
||||
the Alt key and another character sends that character prefixed with
|
||||
an escape character, Alt-based key bindings can be written using the
|
||||
\c \\e escape. For example, Alt-w can be written as
|
||||
<tt>\\ew</tt>. Control character can be written in much the same way
|
||||
using the \c \\c escape, for example Control-x can be written as
|
||||
<tt>\\ew</tt>. The control character can be written in much the same way
|
||||
using the \c \\c escape, for example Control-x (^X) can be written as
|
||||
<tt>\\cx</tt>. Note that Alt-based key bindings are case sensitive and
|
||||
Control base key bindings are not. This is not a design choice in
|
||||
fish, it is simply how terminals work.
|
||||
Control-based key bindings are not. This is a constraint of text-based
|
||||
termainls, not \c fish.
|
||||
|
||||
If SEQUENCE is the empty string, i.e. an empty set of quotes, this is
|
||||
interpreted as the default keybinding. It will be used whenever no
|
||||
The default key binding can be set by specifying a SEQUENCE of the empty
|
||||
string (that is, <code>''</code>). It will be used whenever no
|
||||
other binding matches. For most key bindings, it makes sense to use
|
||||
the \c self-insert function (i.e. <tt>bind '' self-insert</tt> as the
|
||||
default keybining. This will insert any keystrokes not specifically
|
||||
default keybinding. This will insert any keystrokes not specifically
|
||||
bound to into the editor. Non-printable characters are ignored by the
|
||||
editor, so this will not result in e.g. control sequences being
|
||||
editor, so this will not result in control sequences being
|
||||
printable.
|
||||
|
||||
If the -k switch is used, the name of the key (such as down, up or
|
||||
backspace) is used instead of a sequence. The names used are the same
|
||||
as the corresponding curses variables, but without the 'key_'
|
||||
prefix. (See man 5 terminfo for more information, or use <tt>bind
|
||||
--key-names</tt> for a list of all available named keys)
|
||||
prefix. (See \c terminfo(5) for more information, or use <tt>bind
|
||||
--key-names</tt> for a list of all available named keys.)
|
||||
|
||||
COMMAND can be any fish command, but it can also be one of a set of
|
||||
special input functions. These include functions for moving the
|
||||
@@ -45,16 +46,19 @@ bind to the function name. This way it becomes significantly easier to
|
||||
test the function while editing, and the result is usually more
|
||||
readable as well.
|
||||
|
||||
- <tt>-a</tt> or <tt>--all</tt> If --key-names is specified, show all key names, not only the ones that actually are defined for the current terminal. If erase mode is specified, this switch will cause all current bindings to be erased.
|
||||
- <tt>-e</tt> or <tt>--erase</tt> Erase mode. All non-switch arguments are interpreted as character sequences and any commands associated with those sequences are erased.
|
||||
- <tt>-h</tt> or <tt>--help</tt> Display help and exit
|
||||
Key bindings are not saved between sessions by default. To save custom
|
||||
keybindings, edit the \c fish_user_key_bindings function and insert the
|
||||
appropirate \c bind statements.
|
||||
|
||||
The following parameters are available:
|
||||
|
||||
- <tt>-k</tt> or <tt>--key</tt> Specify a key name, such as 'left' or 'backspace' instead of a character sequence
|
||||
- <tt>-K</tt> or <tt>--key-names</tt> Display a list of available key names
|
||||
- <tt>-f</tt> or <tt>--function-names</tt> Display a list of available input functions
|
||||
|
||||
\subsection bind-example Example
|
||||
\subsection bind-example Examples
|
||||
|
||||
<tt>bind \\cd 'exit'</tt> causes fish to exit on Control-d
|
||||
<tt>bind \\cd 'exit'</tt> causes \c fish to exit when Control-d is pressed.
|
||||
|
||||
<tt>bind -k ppage history-search-backward</tt> Causes fish to perform a history search when the page up key is pressed
|
||||
<tt>bind -k ppage history-search-backward</tt> performs a history search when the Page Up key is pressed.
|
||||
|
||||
|
||||
@@ -5,15 +5,36 @@
|
||||
|
||||
\subsection block-description Description
|
||||
|
||||
- <tt>-l</tt> or <tt>--local</tt> Release the block at the end of the currently innermost block scope
|
||||
\c block prevents events triggered by \c fish or the
|
||||
<a href="commands.html#emit"><code>emit</code></a> command from
|
||||
being delivered and acted upon while the block is in place.
|
||||
|
||||
In functions, \c block can be useful while performing work that
|
||||
should not be interrupted by the shell.
|
||||
|
||||
The block can be removed. Any events which triggered while the
|
||||
block was in place will then be delivered.
|
||||
|
||||
Event blocks should not be confused with code blocks, which are created
|
||||
with <code>begin</code>, <code>if</code>, <code>while</code> or
|
||||
<code>for</code>
|
||||
|
||||
The following parameters are available:
|
||||
|
||||
- <tt>-l</tt> or <tt>--local</tt> Release the block automatically at the end of the current innermost code block scope
|
||||
- <tt>-g</tt> or <tt>--global</tt> Never automatically release the lock
|
||||
- <tt>-e</tt> or <tt>--erase</tt> Release global block
|
||||
|
||||
\subsection block-example Example
|
||||
|
||||
<pre>
|
||||
# Create a function that listens for events
|
||||
function --on-event foo foo; echo 'foo fired'; end
|
||||
# Block the delivery of events
|
||||
block -g
|
||||
\#Do something that should not be interrupted
|
||||
emit foo
|
||||
# No output will be produced
|
||||
block -e
|
||||
# 'foo fired' will now be printed
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
\section break break - stop the innermost currently evaluated loop
|
||||
\section break break - stop the current inner loop
|
||||
|
||||
\subsection break-synopsis Synopsis
|
||||
<tt>LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end</tt>
|
||||
|
||||
\subsection break-description Description
|
||||
The \c break builtin is used to halt a currently running loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.
|
||||
|
||||
\c break halts a currently running loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.
|
||||
|
||||
There are no parameters for <code>break</code>.
|
||||
|
||||
\subsection break-example Example
|
||||
The following code searches all .c files for smurfs, and halts at the first occurrence.
|
||||
The following code searches all .c files for "smurf", and halts at the first occurrence.
|
||||
|
||||
<pre>
|
||||
for i in *.c
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
\subsection breakpoint-description Description
|
||||
|
||||
The \c breakpoint builtin is used to halt a running script and launch
|
||||
an interactive debug prompt.
|
||||
\c breakpoint is used to halt a running script and launch
|
||||
an interactive debugging prompt.
|
||||
|
||||
For more details, see <a href="index.html#debugging">Debugging fish
|
||||
scripts</a> in the \c fish manual.
|
||||
|
||||
There are no parameters for <code>breakpoint</code>.
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
\subsection builtin-description Description
|
||||
|
||||
- <tt>-n</tt> or <tt>--names</tt> List the names of all defined builtins
|
||||
\c builtin forces the shell to use a builtin command, rather than a function or program.
|
||||
|
||||
Prefixing a command with the word 'builtin' forces fish to ignore any functions with the same name.
|
||||
The following parameters are available:
|
||||
|
||||
- <tt>-n</tt> or <tt>--names</tt> List the names of all defined builtins
|
||||
|
||||
\subsection builtin-example Example
|
||||
|
||||
<tt>builtin jobs</tt>
|
||||
|
||||
causes fish to execute the jobs builtin, even if a function named jobs exists.
|
||||
<tt>builtin jobs</tt> executes the jobs builtin, even if a function named jobs exists.
|
||||
|
||||
@@ -5,27 +5,24 @@
|
||||
|
||||
\subsection case-description Description
|
||||
|
||||
The \c switch statement is used to perform one of several blocks of
|
||||
commands depending on whether a specified value equals one of several
|
||||
wildcarded values. The \c case statement is used together with the \c
|
||||
switch statement in order to determine which block should be
|
||||
performed.
|
||||
\c switch performs one of several blocks of commands, depending on whether
|
||||
a specified value equals one of several wildcarded values. \c case is used
|
||||
together with the \c switch statement in order to determine which block should
|
||||
be executed.
|
||||
|
||||
Each \c case command is given one or more parameter. The first \c case
|
||||
Each \c case command is given one or more parameters. The first \c case
|
||||
command with a parameter that matches the string specified in the
|
||||
switch command will be evaluated. \c case parameters may contain
|
||||
wildcards. These need to be escaped or quoted in order to avoid
|
||||
regular wildcard expansion using filenames.
|
||||
|
||||
Note that fish does not fall through on case statements. Though the
|
||||
syntax may look a bit like C switch statements, it behaves more like
|
||||
the case statements of traditional shells.
|
||||
Note that fish does not fall through on case statements. Only the
|
||||
first matching case is executed.
|
||||
|
||||
Also note that command substitutions in a case statement will be
|
||||
evaluated even if it's body is not taken. This may seem
|
||||
counterintuitive at first, but it is unavoidable, since it would be
|
||||
impossible to know if a case command will evaluate to true before all
|
||||
forms of parameter expansion have been performed for the case command.
|
||||
Note that command substitutions in a case statement will be
|
||||
evaluated even if its body is not taken. All substitutions, including
|
||||
command substitutions, must be performed before the value can be compared
|
||||
against the parameter.
|
||||
|
||||
\subsection case-example Example
|
||||
|
||||
@@ -42,6 +39,7 @@ switch $animal
|
||||
echo bird
|
||||
case shark trout stingray
|
||||
echo fish
|
||||
# Note that the next case has a wildcard which is quoted
|
||||
case '*'
|
||||
echo I have no idea what a $animal is
|
||||
end
|
||||
|
||||
@@ -3,9 +3,22 @@
|
||||
\subsection cd-synopsis Synopsis
|
||||
<tt>cd [DIRECTORY]</tt>
|
||||
|
||||
\subsection cd-description Description Changes the current
|
||||
directory. If <tt>DIRECTORY</tt> is supplied it will become the new
|
||||
directory. If \c DIRECTORY is a relative path, the paths found in the
|
||||
CDPATH environment variable array will be tried as prefixes for the
|
||||
specified path. If CDPATH is not set, it is assumed to be '.'. If \c
|
||||
DIRECTORY is not specified, \$HOME will be the new directory.
|
||||
\subsection cd-description Description
|
||||
\c cd changes the current working directory.
|
||||
|
||||
If \c DIRECTORY is supplied, it will become the new directory. If no parameter
|
||||
is given, the contents of the \c HOME environment variable will be used.
|
||||
|
||||
If \c DIRECTORY is a relative path, the paths found in the
|
||||
\c CDPATH environment variable array will be tried as prefixes for the specified
|
||||
path.
|
||||
|
||||
Note that the shell will attempt to change directory without requiring \c cd
|
||||
if the name of a directory is provided (starting with '.', '/' or '~').
|
||||
|
||||
\subsection cd-example Examples
|
||||
|
||||
\c cd changes the working directory to your home directory.
|
||||
|
||||
<code>cd /usr/src/fish-shell</code> changes the working directory to
|
||||
<code>/usr/src/fish-shell</code>.
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
<tt>command COMMANDNAME [OPTIONS...]</tt>
|
||||
|
||||
\subsection command-description Description
|
||||
prefixing a command with the word 'command' forces fish to ignore any functions or builtins with the same name.
|
||||
|
||||
\c command forces the shell to execute the program \c COMMANDNAME and ignore any functions or builtins with the same name.
|
||||
|
||||
\subsection command-example Example
|
||||
|
||||
|
||||
<tt>command ls</tt>
|
||||
|
||||
causes fish to execute the ls program, even if there exists a 'ls' function.
|
||||
<tt>command ls</tt> causes fish to execute the \c ls program, even if an 'ls' function exists.
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
\section commandline commandline - set or get the current commandline buffer
|
||||
\section commandline commandline - set or get the current command line buffer
|
||||
|
||||
\subsection commandline-synopsis Synopsis
|
||||
<tt>commandline [OPTIONS] [CMD]</tt>
|
||||
|
||||
\subsection commandline-description Description
|
||||
|
||||
\c commandline can be used to set or get the current contents of the command
|
||||
line buffer.
|
||||
|
||||
- \c CMD is the new value of the commandline. If unspecified, the
|
||||
current value of the commandline is written to standard output. All
|
||||
output from the commandline builtin is escaped, i.e. quotes are
|
||||
removed, backslash escapes are expanded, etc..
|
||||
With no parameters, \c commandline returns the current value of the command
|
||||
line.
|
||||
|
||||
The following switches change what the commandline builtin does
|
||||
With \c CMD specified, the command line buffer is erased and replaced with
|
||||
the contents of \c CMD.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- \c -C or \c --cursor set or get the current cursor position, not
|
||||
the contents of the buffer. If no argument is given, the current
|
||||
cursor position is printed, otherwise the argument is interpreted
|
||||
as the new cursor position.
|
||||
- \c -f or \c --function inject readline functions into the
|
||||
reader. This option can not be combined with any other option. It
|
||||
reader. This option cannot be combined with any other option. It
|
||||
will cause any additional arguments to be interpreted as readline
|
||||
functions, and these functions will be injected into the reader, so
|
||||
that they will be returned to the reader before any additional
|
||||
actual key presses are read.
|
||||
|
||||
|
||||
The following switches change the way \c commandline updates the
|
||||
commandline buffer
|
||||
The following options change the way \c commandline updates the
|
||||
command line buffer:
|
||||
|
||||
- \c -a or \c --append do not remove the current commandline, append
|
||||
the specified string at the end of it
|
||||
@@ -35,29 +37,27 @@ commandline buffer
|
||||
- \c -r or \c --replace remove the current commandline and replace it
|
||||
with the specified string (default)
|
||||
|
||||
The following switches change what part of the commandline is printed
|
||||
or updated
|
||||
The following options change what part of the commandline is printed
|
||||
or updated:
|
||||
|
||||
- \c -b or \c --current-buffer select the entire buffer (default)
|
||||
- \c -j or \c --current-job select the current job
|
||||
- \c -p or \c --current-process select the current process
|
||||
- \c -t or \c --current-token select the current token.
|
||||
|
||||
The following switch changes the way \c commandline prints the current
|
||||
commandline buffer
|
||||
The following options change the way \c commandline prints the current
|
||||
commandline buffer:
|
||||
|
||||
- \c -c or \c --cut-at-cursor only print selection up until the
|
||||
current cursor position
|
||||
- \c -o or \c --tokenize tokenize the selection and print one string-type token per line
|
||||
|
||||
|
||||
If commandline is called during a call to complete a given string
|
||||
using <code>complete -C STRING</code>, commandline will consider the
|
||||
specified string to be the current contents of the commandline.
|
||||
If \c commandline is called during a call to complete a given string
|
||||
using <code>complete -C STRING</code>, \c commandline will consider the
|
||||
specified string to be the current contents of the command line.
|
||||
|
||||
\subsection commandline-example Example
|
||||
|
||||
<tt>commandline -j $history[3]</tt>
|
||||
|
||||
replaces the job under the cursor with the third item from the
|
||||
commandline history.
|
||||
<tt>commandline -j $history[3]</tt> replaces the job under the cursor with the
|
||||
third item from the command line history.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
\section complete complete - edit command specific tab-completions.
|
||||
\section complete complete - edit command specific tab-completions
|
||||
|
||||
\subsection complete-synopsis Synopsis
|
||||
<tt>complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION] </tt>
|
||||
|
||||
\subsection complete-description Description
|
||||
|
||||
For an introduction to how to specify completions, see the section <a
|
||||
href='index.html#completion-own'>Writing your own completions</a> of
|
||||
For an introduction to specifying completions, see <a
|
||||
href='index.html#completion-own'>Writing your own completions</a> in
|
||||
the fish manual.
|
||||
|
||||
- <tt>COMMAND</tt> is the name of the command for which to add a completion
|
||||
|
||||
@@ -5,19 +5,22 @@
|
||||
|
||||
\subsection contains-description Description
|
||||
|
||||
\c contains tests whether the set \c VALUES contains the string
|
||||
<code>KEY</code>. If so, \c contains exits with status 0; if not, it exits
|
||||
with status 1.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- \c -i or \c --index print the word index
|
||||
- \c -h or \c --help display this message
|
||||
|
||||
Test if the set VALUES contains the string KEY. Return status is 0 if
|
||||
yes, 1 otherwise
|
||||
|
||||
|
||||
\subsection contains-example Example
|
||||
<pre>
|
||||
for i in ~/bin /usr/local/bin
|
||||
if not contains \$i \$PATH
|
||||
set PATH \$PATH i
|
||||
set PATH \$PATH \$i
|
||||
end
|
||||
end
|
||||
</pre>
|
||||
|
||||
The above code tests if ~/bin and /usr/local/bin are in the path and if they are not, they are added.
|
||||
The above code tests if \c ~/bin and \c /usr/local/bin are in the path and adds them if not.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
\section continue continue - skip the rest of the current lap of the innermost currently evaluated loop
|
||||
\section continue continue - skip the remainder of the current iteration of the current inner loop
|
||||
|
||||
\subsection continue-synopsis Synopsis
|
||||
<tt>LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end</tt>
|
||||
|
||||
\subsection continue-description Description
|
||||
The \c continue builtin is used to skip the current lap of the innermost currently running loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.
|
||||
\c continue skips the remainder of the current iteration of the current inner loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.
|
||||
|
||||
\subsection continue-example Example
|
||||
The following code removes all tmp files without smurfs.
|
||||
The following code removes all tmp files that do not contain the word smurf.
|
||||
|
||||
<pre>
|
||||
for i in *.tmp
|
||||
|
||||
@@ -5,21 +5,14 @@
|
||||
|
||||
\subsection count-description Description
|
||||
|
||||
The <tt>count</tt> builtin prints the number of arguments that were
|
||||
<tt>count</tt> prints the number of arguments that were
|
||||
passed to it. This is usually used to find out how many elements an
|
||||
environment variable array contains, but this is not the only
|
||||
potential usage for the count command.
|
||||
environment variable array contains.
|
||||
|
||||
The count command does not accept any options, not even '-h'. This way
|
||||
the user does not have to worry about an array containing elements
|
||||
such as dashes. \c fish performs a special check when invoking the
|
||||
count command, and if the user uses a help option, this help page is
|
||||
displayed, but if a help option is contained inside of a variable or
|
||||
is the result of expansion, it will simply be counted like any other
|
||||
argument.
|
||||
\c count does not accept any options, including '-h'.
|
||||
|
||||
Count exits with a non-zero exit status if no arguments where passed
|
||||
to it, with zero otherwise.
|
||||
\c count exits with a non-zero exit status if no arguments were passed
|
||||
to it, and with zero if at least one argument was passed.
|
||||
|
||||
\subsection count-example Example
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Most tradeoffs between power and ease of use can be avoided with careful design.
|
||||
-# Whenever possible without breaking the above goals, fish should
|
||||
follow the Posix syntax.
|
||||
|
||||
To achive these high-level goals, the fish design relies on a number
|
||||
To achieve these high-level goals, the fish design relies on a number
|
||||
of more specific design principles. These are presented below,
|
||||
together with a rationale and a few examples for each.
|
||||
|
||||
@@ -33,43 +33,22 @@ program harder to maintain and update.
|
||||
Examples:
|
||||
|
||||
- Here documents are too similar to using echo inside of a pipeline.
|
||||
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achived either using a block or the psub shellscript function.
|
||||
- Subshells, command substitution and process substitution are strongly related. \c fish only supports command substitution, the others can be achieved either using a block or the psub shellscript function.
|
||||
- Having both aliases and functions is confusing, especially since both of them have limitations and problems. \c fish functions have none of the drawbacks of either syntax.
|
||||
- The many Posix quoting styles are silly, especially \$''.
|
||||
|
||||
\section sep The law of responsiveness
|
||||
|
||||
\section sep The law of minimalism
|
||||
|
||||
The shell should only contain features that cannot be implemented in
|
||||
a reasonable way outside of the shell. A large performance decrease,
|
||||
as well as some program complexity increase is acceptable in order to
|
||||
improve separation.
|
||||
The shell should attempt to remain responsive to the user at all times, even in the face of contended or unresponsive filesystems. It is only acceptable to block in response to a user initiated action, such as running a command.
|
||||
|
||||
Rationale:
|
||||
|
||||
A modular project is easier to maintain since smaller programs are far
|
||||
easier to understand than larger ones. A modular project is also more
|
||||
future proof since the modules can be individually
|
||||
replaced. Modularity also decreases the severity of bugs, since there
|
||||
is good hope that a bug, even a serious one, in one module, does not
|
||||
take the whole system down.
|
||||
Bad performance increases user-facing complexity, because it trains users to recognize and route around slow use cases. It is also incredibly frustrating.
|
||||
|
||||
Examples:
|
||||
|
||||
- Builtin commands should only be created when it cannot be
|
||||
avoided. \c echo, \c kill, \c printf and \c time are among the commands
|
||||
that fish does not implement internally since they can be provided as
|
||||
external commands. Several other commands that are commonly implemented
|
||||
as builtins and can not be implemented as external commands,
|
||||
including \c type, \c vared, \c pushd and \c popd are implemented as shellscript
|
||||
functions in fish.
|
||||
- Mathematical calculations, regex matching, generating lists of numbers
|
||||
and many other funtions can easily be done in external programs. They
|
||||
should not be supported internally by the shell.
|
||||
|
||||
The law of minimalism does not imply that a large feature set is
|
||||
bad. So long as a feature is not part of the shell itself, but a
|
||||
separate command or at least a shellscript function, bloat is fine.
|
||||
- Features like syntax highlighting and autosuggestions must perform all of their disk I/O asynchronously.
|
||||
- Startup should minimize forks and disk I/O, so that fish can be started even if the system is under load.
|
||||
|
||||
\section conf Configurability is the root of all evil
|
||||
|
||||
@@ -98,7 +77,7 @@ A special note on the evils of configurability is the long list of
|
||||
very useful features found in some shells, that are not turned on by
|
||||
default. Both zsh and bash support command specific completions, but
|
||||
no such completions are shipped with bash by default, and they are
|
||||
turned of by default in zsh. Other features that zsh support that are
|
||||
turned off by default in zsh. Other features that zsh support that are
|
||||
disabled by default include tab-completion of strings containing
|
||||
wildcards, a sane completion pager and a history file.
|
||||
|
||||
|
||||
@@ -4,5 +4,9 @@
|
||||
<tt>dirh</tt>
|
||||
|
||||
\subsection dirh-description Description
|
||||
|
||||
<tt>dirh</tt> prints the current directory history. The current position in the
|
||||
history is highlighted using <tt>$fish_color_history_current</tt>.
|
||||
history is highlighted using the color defined in the
|
||||
<tt>fish_color_history_current</tt> environment variable.
|
||||
|
||||
\c dirh does not accept any parameters.
|
||||
|
||||
@@ -4,4 +4,7 @@
|
||||
<tt>dirs</tt>
|
||||
|
||||
\subsection dirs-description Description
|
||||
<tt>dirs</tt> prints the current directory stack.
|
||||
<tt>dirs</tt> prints the current directory stack, as created by the
|
||||
<code><a href="#pushd">pushd</a></code> command.
|
||||
|
||||
\c dirs does not accept any parameters.
|
||||
|
||||
39
doc_src/echo.txt
Normal file
39
doc_src/echo.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
\section echo echo - display a line of text
|
||||
|
||||
\subsection echo-synopsis Synopsis
|
||||
<tt>echo [STRING]</tt>
|
||||
|
||||
\subsection echo-description Description
|
||||
|
||||
\c echo displays a string of text.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- \c -n, \c Do not output a newline
|
||||
- \c -s, \c Do not separate arguments with spaces
|
||||
- \c -E, \c Disable interpretation of backslash escapes (default)
|
||||
- \c -e, \c Enable interpretation of backslash escapes
|
||||
- \c -h, \c --help Display this help
|
||||
|
||||
\subsection echo-escapes Escape Sequences
|
||||
|
||||
If \c -e is used, the following sequences are recognized:
|
||||
|
||||
- \c \\\\ \c backslash
|
||||
- \\a alert (BEL)
|
||||
- \\b backspace
|
||||
- \\c produce no further output
|
||||
- \\e escape
|
||||
- \\f form feed
|
||||
- \\n new line
|
||||
- \\r carriage return
|
||||
- \\t horizontal tab
|
||||
- \\v vertical tab
|
||||
- \\0NNN byte with octal value NNN (1 to 3 digits)
|
||||
- \\xHH byte with hexadecimal value HH (1 to 2 digits)
|
||||
|
||||
\subsection echo-example Example
|
||||
|
||||
<tt>echo 'Hello World'</tt> Print hello world to stdout
|
||||
|
||||
<tt>echo -e 'Top\\nBottom'</tt> Print Top and Bottom on separate lines, using an escape sequence
|
||||
@@ -4,14 +4,18 @@
|
||||
<tt>if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end</tt>
|
||||
|
||||
\subsection else-description Description
|
||||
<tt>if</tt> will execute the command CONDITION. If the condition's exit
|
||||
status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and
|
||||
<tt>else</tt> is given, COMMANDS_FALSE will be executed. Hint: use
|
||||
<a href="#begin"><tt>begin; ...; end</tt></a> for complex conditions.
|
||||
<tt>if</tt> will execute the command \c CONDITION. If the condition's exit
|
||||
status is 0, the commands \c COMMANDS_TRUE will execute. If it is not 0 and
|
||||
<tt>else</tt> is given, \c COMMANDS_FALSE will be executed.
|
||||
|
||||
\subsection else-example Example
|
||||
|
||||
The command <tt>if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end</tt>
|
||||
will print <tt>foo.txt exists</tt> if the file foo.txt
|
||||
exists and is a regular file, otherwise it will print
|
||||
<tt>foo.txt does not exist</tt>.
|
||||
The following code tests whether a file \c foo.txt exists as a regular file.
|
||||
|
||||
<pre>
|
||||
if test -f foo.txt
|
||||
echo foo.txt exists
|
||||
else
|
||||
echo foo.txt does not exist
|
||||
end
|
||||
</pre>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
\section emit emit - Emit a generic event
|
||||
|
||||
\subsection block-synopsis Synopsis
|
||||
<tt>emit EVENT_NAME</tt>
|
||||
<tt>emit EVENT_NAME [ARGUMENTS...]</tt>
|
||||
|
||||
\subsection emit-description Description
|
||||
|
||||
The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
|
||||
\c emit emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments.
|
||||
|
||||
\subsection emit-example Example
|
||||
|
||||
@@ -13,7 +13,8 @@ The following code first defines an event handler for the generic
|
||||
event named 'test_event', and then emits an event of that type.
|
||||
|
||||
<pre>function event_test --on-event test_event
|
||||
echo event test!!!
|
||||
echo event test: $argv
|
||||
end
|
||||
|
||||
emit test_event</pre>
|
||||
emit test_event something
|
||||
</pre>
|
||||
|
||||
@@ -10,7 +10,9 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end
|
||||
</pre>
|
||||
|
||||
\subsection end-description Description
|
||||
<tt>end</tt> ends a block of commands. For more information, read the
|
||||
<tt>end</tt> ends a block of commands.
|
||||
|
||||
For more information, read the
|
||||
documentation for the block constructs, such as \c if, \c for and \c
|
||||
while.
|
||||
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
<tt>eval [COMMANDS...]</tt>
|
||||
|
||||
\subsection eval-description Description
|
||||
The <tt>eval</tt> function causes fish to evaluate the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator.
|
||||
<tt>eval</tt> evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator.
|
||||
|
||||
\subsection eval-example Example
|
||||
|
||||
The folloing code will call the ls command. Note that \c fish does not
|
||||
support the use of environment variables as direct commands; \c eval can
|
||||
be used to work around this.
|
||||
|
||||
<pre>
|
||||
set cmd ls
|
||||
eval $cmd
|
||||
</pre>
|
||||
|
||||
will call the ls command.
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
\subsection exec-description Description
|
||||
|
||||
The \c exec builtin is used to replace the currently running shells
|
||||
process image with a new command. On successful completion, exec never
|
||||
returns. exec can not be used inside a pipeline.
|
||||
\c exec replaces the currently running shell with a new command.
|
||||
On successful completion, \c exec never returns. \c exec cannot be used
|
||||
inside a pipeline.
|
||||
|
||||
\subsection exec-example Example
|
||||
|
||||
<tt>exec emacs</tt> starts up the emacs text editor. When emacs exits,
|
||||
the session will terminate.
|
||||
<tt>exec emacs</tt> starts up the emacs text editor, and exits \c fish.
|
||||
When emacs exits, the session will terminate.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
\section exit exit - exit the shell.
|
||||
\section exit exit - exit the shell
|
||||
|
||||
\subsection exit-synopsis Synopsis
|
||||
<tt>exit [STATUS]</tt>
|
||||
|
||||
\subsection exit-description Description
|
||||
|
||||
The <tt>exit</tt> builtin causes fish to exit. If <tt>STATUS</tt> is
|
||||
\c exit causes fish to exit. If <tt>STATUS</tt> is
|
||||
supplied, it will be converted to an integer and used as the exit
|
||||
code. Otherwise the exit code will be that of the last command executed.
|
||||
code. Otherwise, the exit code will be that of the last command executed.
|
||||
|
||||
If exit is called while sourcing a file (using the <a
|
||||
href="#source">.</a> builtin) the rest of the file will be skipped,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/** \page faq Frequently asked questions
|
||||
|
||||
- <a href='#faq-cwd-symlink'>Why does cd, pwd and other fish commands always resolve symlinked directories to their canonical path?</a>
|
||||
- <a href='#faq-cd-autocomplete'>Why does the cd command autocompletion list the subdirectories of my home directory as completions?</a>
|
||||
- <a href='#faq-cd-implicit'>I accidentally entered a directory path and fish changed directory. What happened?</a>
|
||||
- <a href='#faq-open'>The open command doesn't work.</a>
|
||||
- <a href='#faq-default'>How do I make fish my default shell?</a>
|
||||
- <a href='#faq-titlebar'>I'm seeing weird output before each prompt when using screen. What's wrong?</a>
|
||||
- <a href='#faq-greeting'>How do I change the greeting message?</a>
|
||||
- <a href='#faq-history'>Why doesn't history substitution ("!$" etc.) work?</a>
|
||||
- <a href='#faq-uninstalling'>How do I uninstall fish?</a>
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -26,9 +26,9 @@ handled, and are varitations of the following example:
|
||||
|
||||
Writing <code>cd images; ls ..</code> given the above directory
|
||||
structure would list the contents of ~/Documents, not of ~, even
|
||||
though using <code>cd ..</code> changes the current direcotry to ~,
|
||||
though using <code>cd ..</code> changes the current directory to ~,
|
||||
and the prompt, the pwd builtin and many other directory information
|
||||
sources suggest that the the current directory is ~/images and it's
|
||||
sources suggest that the current directory is ~/images and its
|
||||
parent is ~. This issue is not possible to fix without either making
|
||||
every single command into a builtin, breaking Unix semantics or
|
||||
implementing kludges in every single command.
|
||||
@@ -42,19 +42,9 @@ silently fails in shells that don't resolve symlinked paths.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-cd-autocomplete Why does the cd command autocompletion list the subdirectories of my home directory as completions?
|
||||
|
||||
Because they are completions. In fish, if you specify a relative
|
||||
directory to the cd command, i.e. any path that does not start with
|
||||
either './' or '/', the environment variable CDPATH will be examined, and any
|
||||
directories in this path is used as a base direcotry. To disable this
|
||||
feature, write <code>set CDPATH .</code> on the commandline.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-cd-implicit I accidentally entered a directory path and fish changed directory. What happened?
|
||||
|
||||
If fish is unable to locate a command with a given name, fish will
|
||||
If fish is unable to locate a command with a given name, and it starts with '.', '/' or '~', fish will
|
||||
test if a directory of that name exists. If it does, it is implicitly
|
||||
assumed that you want to change working directory. For example, the
|
||||
fastest way to switch to your home directory is to simply press
|
||||
@@ -64,13 +54,12 @@ fastest way to switch to your home directory is to simply press
|
||||
|
||||
\section faq-open The open command doesn't work.
|
||||
|
||||
The open command uses the mimetype database and the .desktop files
|
||||
The \c open command uses the MIME type database and the <code>.desktop</code> files
|
||||
used by Gnome and KDE to identify filetypes and default actions. If
|
||||
at least one of these two desktops are installed, but the open command is
|
||||
at least one of these environments is installed, but the open command is
|
||||
not working, this probably means that the relevant files are installed
|
||||
in a nonstandard location. Please contact the <a
|
||||
href='mailto:fish-users@lists.sf.net'>fish mailing list</a>, and
|
||||
hopefully this can be resolved.
|
||||
in a non-standard location. Consider <a href="index.html#more-help">asking for
|
||||
more help</a>.
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -91,10 +80,10 @@ In order to change your default shell, type:
|
||||
|
||||
<code>chsh -s /usr/local/bin/fish</code>
|
||||
|
||||
You may need to adjust the above path to e.g. /usr/bin/fish. Use the command <code>which fish</code> if you are unsure of where fish is installed.
|
||||
You may need to adjust the above path to e.g. \c /usr/bin/fish. Use the command <code>which fish</code> if you are unsure of where fish is installed.
|
||||
|
||||
Unfortunatly, there is no way to make the changes take effect at once,
|
||||
you will need to log out and back in again.
|
||||
Unfortunately, there is no way to make the changes take effect at once.
|
||||
You will need to log out and back in again.
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -114,7 +103,7 @@ The long answer:
|
||||
|
||||
Fish is trying to set the titlebar message of your terminal. While
|
||||
screen itself supports this feature, your terminal does
|
||||
not. Unfortuntaly, when the underlying terminal doesn't support
|
||||
not. Unfortunately, when the underlying terminal doesn't support
|
||||
setting the titlebar, screen simply passes through the escape codes
|
||||
and text to the underlying terminal instead of ignoring them. It is
|
||||
impossible detect and resolve this problem from inside fish since fish
|
||||
@@ -158,4 +147,19 @@ Fish history recall is very simple yet effective:
|
||||
|
||||
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
|
||||
|
||||
<hr>
|
||||
|
||||
\section faq-uninstalling Uninstalling fish
|
||||
|
||||
Should you wish to uninstall fish, first ensure fish is not set as your shell. Run <code>chsh -s /bin/bash</code> if you are not sure.
|
||||
|
||||
Next, do the following (assuming fish was installed to /usr/local):
|
||||
|
||||
<pre>
|
||||
rm -Rf /usr/local/etc/fish /usr/local/share/fish ~/.config/fish
|
||||
rm /usr/local/share/man/man1/fish*.1
|
||||
cd /usr/local/bin
|
||||
rm -f fish mimedb fish_pager fishd fish_indent
|
||||
</pre>
|
||||
|
||||
*/
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
\section fg fg - send job to foreground
|
||||
\section fg fg - bring job to foreground
|
||||
|
||||
\subsection fg-synopsis Synopsis
|
||||
<tt>fg [PID]</tt>
|
||||
|
||||
\subsection fg-description Description
|
||||
Sends the specified job to the foreground. While a foreground job is
|
||||
executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group id is put in the foreground.
|
||||
\c fg brings the specified <a href="index.html#syntax-job-control">job</a> to the foreground, resuming it if it is stopped. While a foreground job is
|
||||
executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground.
|
||||
|
||||
The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.
|
||||
|
||||
\subsection fg-example Example
|
||||
|
||||
<tt>fg \%0</tt> will put the job with job id 0 in the foreground.
|
||||
<tt>fg \%1</tt> will put the job with job ID 1 in the foreground.
|
||||
|
||||
@@ -5,10 +5,12 @@ fish [-h] [-v] [-c command] [FILE [ARGUMENTS...]]
|
||||
|
||||
\subsection fish-description Description
|
||||
|
||||
A commandline shell written mainly with interactive use in mind. The
|
||||
full manual is available <a href='index.html'>in html</a> by using the
|
||||
\c fish is a command-line shell written mainly with interactive use in mind. The
|
||||
full manual is available <a href='index.html'>in HTML</a> by using the
|
||||
<a href='#help'>help</a> command from inside fish.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- <code>-c</code> or <code>--command=COMMANDS</code> evaluate the specified commands instead of reading from the commandline
|
||||
- <code>-d</code> or <code>--debug-level=DEBUG_LEVEL</code> specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1.
|
||||
- <code>-h</code> or <code>--help</code> display help and exit
|
||||
|
||||
22
doc_src/fish_config.txt
Normal file
22
doc_src/fish_config.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
\section fish_config fish_config - start the web-based configuration interface
|
||||
|
||||
\subsection fish_config-description Description
|
||||
|
||||
\c fish_config starts the web-based configuration interface.
|
||||
|
||||
The web interface allows you to view your functions, variables and history, and
|
||||
to make changes to your prompt and color configuration.
|
||||
|
||||
\c fish_config starts a local web server and then opens a web browser window; when
|
||||
you have finished, close the browser window and then press the Enter key to
|
||||
terminate the configuration session.
|
||||
|
||||
There are no parameters for <code>fish_config</code>.
|
||||
|
||||
If the \c BROWSER environment variable is set, it will be used as the name
|
||||
of the web browser to open instead of the system default.
|
||||
|
||||
\subsection fish_config-example Example
|
||||
|
||||
\c fish_config opens a new web browser window and allows you to configure certain
|
||||
fish settings.
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
\subsection fish_indent-description Description
|
||||
|
||||
\c fish_indent is used to indent or otherwise prettify a piece of fish
|
||||
\c fish_indent is used to indent a piece of fish
|
||||
code. \c fish_indent reads commands from standard input and outputs
|
||||
them to standard output.
|
||||
|
||||
\c fish_indent understands the following options:
|
||||
The following options are available:
|
||||
|
||||
- <tt>-h</tt> or <tt>--help</tt> displays this help message and then exits
|
||||
- <tt>-i</tt> or <tt>--no-indent</tt> do not indent commands
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
\subsection fish_pager-description Description
|
||||
|
||||
This command is used internally by fish to display a list of
|
||||
completions. It should not be used by other commands, as it's
|
||||
interface is liable to change in the future.
|
||||
\c fish_pager is used internally by fish. It should not be used by other
|
||||
commands, as its interface is liable to change in the future.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
\section fish_prompt fish_prompt - define the apperance of the command line prompt
|
||||
\section fish_prompt fish_prompt - define the appearance of the command line prompt
|
||||
|
||||
\subsection fish_promt-synopsis Synopsis
|
||||
\subsection fish_prompt-synopsis Synopsis
|
||||
<pre>function fish_prompt
|
||||
...
|
||||
end</pre>
|
||||
@@ -11,6 +11,11 @@ By defining the \c fish_prompt function, the user can choose a custom
|
||||
prompt. The \c fish_prompt function is executed when the prompt is to
|
||||
be shown, and the output is used as a prompt.
|
||||
|
||||
The exit status of commands within \c fish_prompt will not modify the value of <a href="index.html#variables-status">$status</a> outside of the \c fish_prompt function.
|
||||
|
||||
\c fish ships with a number of example prompts that can be chosen with the
|
||||
\c fish_config command.
|
||||
|
||||
\subsection fish_prompt-example Example
|
||||
|
||||
A simple prompt:
|
||||
|
||||
23
doc_src/fish_right_prompt.txt
Normal file
23
doc_src/fish_right_prompt.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
\section fish_right_prompt fish_right_prompt - define the appearance of the right-side command line prompt
|
||||
|
||||
\subsection fish_right_prompt-synopsis Synopsis
|
||||
<pre>function fish_right_prompt
|
||||
...
|
||||
end</pre>
|
||||
|
||||
\subsection fish_right_prompt-description Description
|
||||
|
||||
\c fish_right_prompt is similar to \c fish_prompt, except that it appears on the right side of the terminal window.
|
||||
|
||||
Multiple lines are not supported in \c fish_right_prompt.
|
||||
|
||||
\subsection fish_prompt-example Example
|
||||
|
||||
A simple right prompt:
|
||||
|
||||
<pre>
|
||||
function fish_right_prompt -d "Write out the right prompt"
|
||||
date "+%m/%d/%y"
|
||||
end
|
||||
</pre>
|
||||
|
||||
9
doc_src/fish_update_completions.txt
Normal file
9
doc_src/fish_update_completions.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
\section fish_update_completions fish_update_completions - Update completions using manual pages
|
||||
|
||||
\subsection fish_update_completions-description Description
|
||||
|
||||
\c fish_update_completions parses manual pages installed on the system, and attempts to create completion files in the \c fish configuration directory.
|
||||
|
||||
This does not overwrite custom completions.
|
||||
|
||||
There are no parameters for <code>fish_update_completions</code>.
|
||||
@@ -6,26 +6,28 @@
|
||||
\subsection fishd-description Description
|
||||
|
||||
The \c fishd daemon is used to load, save and distribute universal
|
||||
variable information. fish automatically connects to fishd via a socket
|
||||
on startup. If no instance of fishd is running, fish spawns a new
|
||||
fishd instance. fishd will create a socket in /tmp, and wait for
|
||||
incoming connections from universal variable clients, such as fish,
|
||||
When no clients are connected, fishd will automatically shut down.
|
||||
variable information. \c fish automatically connects to \c fishd via a socket
|
||||
on startup.
|
||||
|
||||
\c fishd is started and stopped automatically.
|
||||
|
||||
The following options are available if starting \c fishd manually:
|
||||
|
||||
- <tt>-h</tt> or <tt>--help</tt> displays this help message and then exits
|
||||
- <tt>-v</tt> or <tt>--version</tt> displays the current fish version and then exits
|
||||
|
||||
\subsection fishd-files Files
|
||||
|
||||
\c ~/.config/fish/fishd.HOSTNAME permanent storage location for universal
|
||||
variable data. The data is stored as a set of \c set and \c set_export
|
||||
commands such as would be parsed by fishd. The file must always be
|
||||
stored in ASCII format. If an instance of fishd is running (which is
|
||||
generally the case), manual modifications to ~/.fishd.HOSTNAME will be
|
||||
lost. Do NOT edit this file manually!
|
||||
- \c ~/.config/fish/fishd.MACHINE_ID - permanent storage location for universal
|
||||
variable data. \c MACHINE_ID is generally based on the machine's MAC address.
|
||||
|
||||
\c /tmp/fishd.socket.USERNAME the socket which fishd uses to communicate
|
||||
The data is stored as a set of \c set and \c set_export commands such as
|
||||
would be parsed by fishd. The file must always be stored in YAML format.
|
||||
If an instance of fishd is running (which is generally the case), manual
|
||||
modifications to \c ~/.fishd.MACHINE_ID will be lost. Do NOT edit this file manually!
|
||||
|
||||
- \c /tmp/fishd.socket.USERNAME - the socket which fishd uses to communicate
|
||||
with all clients.
|
||||
|
||||
/tmp/fishd.log.USERNAME the fishd log file
|
||||
- /tmp/fishd.log.USERNAME - the fishd log file
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
\subsection for-description Description
|
||||
<tt>for</tt> is a loop construct. It will perform the commands specified by
|
||||
COMMANDS multiple times. Each time the environment variable specified by
|
||||
VARNAME is assigned a new value from VALUES. If VALUES is empty, COMMANDS will
|
||||
\c COMMANDS multiple times. On each iteration, the environment variable specified by
|
||||
\c VARNAME is assigned a new value from \c VALUES. If \c VALUES is empty, \c COMMANDS will
|
||||
not be executed at all.
|
||||
|
||||
\subsection for-example Example
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
\section funced funced - edit a function interactively
|
||||
|
||||
\subsection funced-synopsis Synopsis
|
||||
<code>funced NAME</code>
|
||||
<code>funced [OPTIONS] NAME</code>
|
||||
|
||||
\subsection funced-description Description
|
||||
|
||||
Use the funced command to interactively edit the definition of a
|
||||
function. If there is no function with the name specified, a skeleton function is inserted, if a function exist, the definion will be shown on the command line.
|
||||
\c funced provides an interface to edit the definition of the function
|
||||
<code>NAME</code>.
|
||||
|
||||
If the \c $EDITOR environment variable is set, it will be used as the program
|
||||
to edit the function. Otherwise, a built-in editor will be used.
|
||||
|
||||
If there is no function called \c NAME a new function will be created with
|
||||
the specified name
|
||||
|
||||
- <code>-e command</code> or <code>--editor command</code> Open the function
|
||||
body inside the text editor given by the command (for example, "vi"). The
|
||||
command 'fish' will use the built-in editor.
|
||||
- <code>-i</code> or <code>--interactive</code> Open function body in the
|
||||
built-in editor.
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
\section funcsave funcsave - save the definition of a function to the users autoload directory
|
||||
\section funcsave funcsave - save the definition of a function to the user's autoload directory
|
||||
|
||||
\subsection funcsave-synopsis Synopsis
|
||||
<tt>funcsave FUNCTION_NAME</tt>
|
||||
<tt>funcsave FUNCTION_NAME</tt>
|
||||
|
||||
\subsection funcsave-description Description
|
||||
|
||||
funcsave is used to save the current definition of a function to
|
||||
a file which will be autoloaded by current and future fish
|
||||
\c funcsave saves the current definition of a function to
|
||||
a file in the fish configuration directory. This function will be automatically
|
||||
loaded by current and future fish
|
||||
sessions. This can be useful if you have interactively created a new
|
||||
function and wish to save it for later use.
|
||||
|
||||
|
||||
@@ -5,32 +5,28 @@
|
||||
|
||||
\subsection function-description Description
|
||||
|
||||
- <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description
|
||||
\c function creates a new function \c NAME with the body <code>BODY</code>.
|
||||
|
||||
A function is a list of commands that will be executed when the name of the
|
||||
function is given as a command.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description.
|
||||
- <code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt.
|
||||
- <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group id PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
|
||||
- <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process id PID exits
|
||||
- <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP)
|
||||
- <code>-v</code> or <code>--on-variable VARIABLE_NAME</code> tells fish to run this function when the variable VARIABLE_NAME changes value
|
||||
|
||||
This builtin command is used to create a new function. A function is a
|
||||
list of commands that will be executed when the name of the function
|
||||
is entered. The function
|
||||
|
||||
<pre>
|
||||
function hi
|
||||
echo hello
|
||||
end
|
||||
</pre>
|
||||
|
||||
will write <code>hello</code> whenever the user enters \c hi.
|
||||
- <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group ID PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
|
||||
- <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process ID PID exits.
|
||||
- <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP).
|
||||
- <code>-v</code> or <code>--on-variable VARIABLE_NAME</code> tells fish to run this function when the variable VARIABLE_NAME changes value.
|
||||
|
||||
If the user enters any additional arguments after the function, they
|
||||
are inserted into the environment <a href="index.html#variables-arrays">variable array</a> argv.
|
||||
are inserted into the environment <a href="index.html#variables-arrays">variable array</a>
|
||||
<code>$argv</code>.
|
||||
|
||||
By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href='#emit">emit</a> builtin. Fish generates the following named events:
|
||||
By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href="#emit">emit</a> builtin. Fish generates the following named events:
|
||||
|
||||
- \c fish_prompt, which is emitted whenever a new fish prompt is about to be displayed
|
||||
- \c fish_command_not_found, which is emitted whenever a command lookup failed
|
||||
- \c fish_prompt, which is emitted whenever a new fish prompt is about to be displayed.
|
||||
- \c fish_command_not_found, which is emitted whenever a command lookup failed.
|
||||
|
||||
\subsection function-example Example
|
||||
|
||||
@@ -44,7 +40,7 @@ will run the \c ls command, using the \c -l option, while passing on any additio
|
||||
|
||||
<pre>
|
||||
function mkdir -d "Create a directory and set CWD"
|
||||
mkdir $argv
|
||||
command mkdir $argv
|
||||
if test $status = 0
|
||||
switch $argv[(count $argv)]
|
||||
case '-*'
|
||||
|
||||
@@ -1,31 +1,51 @@
|
||||
\section functions functions - print or erase functions
|
||||
|
||||
\subsection function-synopsis Synopsis
|
||||
<code>functions [-e] FUNCTIONS...</code>
|
||||
<pre>functions [-n]
|
||||
functions -c OLDNAME NEWNAME
|
||||
functions -d DESCRIPTION FUNCTION
|
||||
functions [-eq] FUNCTIONS...</pre>
|
||||
|
||||
\subsection functions-description Description
|
||||
|
||||
This builtin command is used to print or erase functions.
|
||||
\c functions prints or erases functions.
|
||||
|
||||
- <code>-a</code> or <code>--all</code> list all functions, even those whose name start with an underscore.
|
||||
The following options are available:
|
||||
|
||||
- <code>-a</code> or <code>--all</code> lists all functions, even those whose name start with an underscore.
|
||||
- <code>-c OLDNAME NEWNAME</code> or <code>--copy OLDNAME NEWNAME</code> creates a new function named NEWNAME, using the definition of the OLDNAME function.
|
||||
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> change the description of this function
|
||||
- <code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> changes the description of this function.
|
||||
- <code>-e</code> or <code>--erase</code> causes the specified functions to be erased.
|
||||
- <code>-h</code> or <code>--help</code> display a help message and exit
|
||||
- <code>-n</code> or <code>--names</code> list only the names of all defined functions, not their definition
|
||||
- <code>-q</code> or <code>--query</code> test if the specified functions exist. Does not output anything, but the builtins exit status is the number of functions specified that were not defined.
|
||||
- <code>-h</code> or <code>--help</code> displays a help message and exits.
|
||||
- <code>-n</code> or <code>--names</code> lists the names of all defined functions.
|
||||
- <code>-q</code> or <code>--query</code> tests if the specified functions exist.
|
||||
|
||||
The default behavior of \c functions when called with no arguments,
|
||||
is to print the names and definitions of all defined functions. If any
|
||||
non-switch parameters are given, only the definition of the specified
|
||||
The default behavior of <code>functions</code>, when called with no arguments,
|
||||
is to print the names of all defined functions. Unless the \c -a option is
|
||||
given, no functions starting with underscores are not included in the output.
|
||||
|
||||
If any non-option parameters are given, the definition of the specified
|
||||
functions are printed.
|
||||
|
||||
Automatically loaded functions can not be removed using functions
|
||||
-e. Either remove the definition file or change the
|
||||
Automatically loaded functions cannot be removed using <code>functions
|
||||
-e</code>. Either remove the definition file or change the
|
||||
$fish_function_path variable to remove autoloaded functions.
|
||||
|
||||
Function copies, created with -c, will not have any event/signal/on-exit
|
||||
notifications that the original may have had.
|
||||
Copying a function using \c -c copies only the body of the function, and
|
||||
does not attach any event notifications from the original function.
|
||||
|
||||
The exit status of the functions builtin is the number functions
|
||||
specified in the argument list that do not exist.
|
||||
Only one function's description can be changed in a single invocation
|
||||
of <code>functions -d</code>.
|
||||
|
||||
The exit status of \c functions is the number of functions
|
||||
specified in the argument list that do not exist, which can be used in
|
||||
concert with the \c -q option.
|
||||
|
||||
\subsection functions-example Examples
|
||||
|
||||
<code>functions -n</code> displays a list of currently-defined functions.
|
||||
|
||||
<code>functions -c foo bar</code> copies the \c foo function to a new function called
|
||||
<code>bar</code>.
|
||||
|
||||
<code>functions -e bar</code> erases the function <code>bar</code>.
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
\subsection help-description Description
|
||||
|
||||
The \c help command is used to display a section of the fish help documentation.
|
||||
\c help displays the fish help documentation.
|
||||
|
||||
If a \c SECTION is specified, the help for that command is shown.
|
||||
|
||||
If the BROWSER environment variable is set, it will be used to display the
|
||||
documentation, otherwise fish will search for a suitable browser.
|
||||
documentation. Otherwise, fish will search for a suitable browser.
|
||||
|
||||
Note also that most builtin commands display their help in the terminal when
|
||||
Note that most builtin commands display their help in the terminal when
|
||||
given the <tt>--help</tt> option.
|
||||
|
||||
\subsection help-example Example
|
||||
|
||||
44
doc_src/history.txt
Normal file
44
doc_src/history.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
\section history history - Show and manipulate command history
|
||||
|
||||
\subsection history-synopsis Synopsis
|
||||
<pre>
|
||||
history (--save | --clear)
|
||||
history (--search | --delete ) (--prefix "prefix string" | --contains "search string")
|
||||
</pre>
|
||||
|
||||
\subsection history-description Description
|
||||
|
||||
\c history is used to list, search and delete the history of commands used.
|
||||
|
||||
The following options are available:
|
||||
|
||||
- \c --save saves all changes in the history file. The shell automatically
|
||||
saves the history file; this option is provided for internal use.
|
||||
- \c --clear clears the history file. A prompt is displayed before the history
|
||||
is erased.
|
||||
- \c --search returns history items in keeping with the \c --prefix or
|
||||
\c --contains options.
|
||||
- \c --delete deletes history items.
|
||||
- \c --prefix searches or deletes items in the history that begin with the
|
||||
specified text string.
|
||||
- \c --contains searches or deletes items in the history that contain the
|
||||
specified text string.
|
||||
|
||||
If \c --search is specified without \c --contains or <code>--prefix</code>,
|
||||
\c --contains will be assumed.
|
||||
|
||||
If \c --delete is specified without \c --contains or <code>--prefix</code>,
|
||||
only a history item which exactly matches the parameter will be erased. No
|
||||
prompt will be given. If \c --delete is specified with either of these
|
||||
parameters, an interactive prompt will be displayed before any items are
|
||||
deleted.
|
||||
|
||||
\subsection history-examples Example
|
||||
|
||||
<code>history --clear</code> deletes all history items
|
||||
|
||||
<code>history --search --contains "foo"</code> outputs a list of all previous
|
||||
commands containing the string "foo".
|
||||
|
||||
<code>history --delete --prefix "foo"</code> interactively deletes the record
|
||||
of previous commands which start with "foo".
|
||||
@@ -1,19 +1,19 @@
|
||||
\section if if - conditionally execute a command
|
||||
|
||||
\subsection if-synopsis Synopsis
|
||||
<tt>if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end</tt>
|
||||
<tt>if CONDITION; COMMANDS_TRUE...; [else if CONDITION2; COMMANDS_TRUE2...;] [else; COMMANDS_FALSE...;] end</tt>
|
||||
|
||||
\subsection if-description Description
|
||||
|
||||
<tt>if</tt> will execute the command CONDITION. If the condition's
|
||||
exit status is 0, the commands COMMANDS_TRUE will execute. If the
|
||||
exit status is not 0 and <tt>else</tt> is given, COMMANDS_FALSE will
|
||||
<tt>if</tt> will execute the command \c CONDITION. If the condition's
|
||||
exit status is 0, the commands \c COMMANDS_TRUE will execute. If the
|
||||
exit status is not 0 and <tt>else</tt> is given, \c COMMANDS_FALSE will
|
||||
be executed.
|
||||
|
||||
In order to use the exit status of multiple commands as the condition
|
||||
of an if block, use <a href="#begin"><tt>begin; ...; end</tt></a> and
|
||||
the short circuit commands <a href="commands.html#and">and</a> and <a
|
||||
href="commands.html#or">or</a>.
|
||||
the short circuit commands <a href="commands.html#and"><tt>and</tt></a>
|
||||
and <a href="commands.html#or"><tt>or</tt></a>.
|
||||
|
||||
The exit status of the last foreground command to exit can always be
|
||||
accessed using the <a href="index.html#variables-status">$status</a>
|
||||
@@ -24,10 +24,13 @@ variable.
|
||||
<pre>
|
||||
if test -f foo.txt
|
||||
echo foo.txt exists
|
||||
else if test -f bar.txt
|
||||
echo bar.txt exists
|
||||
else
|
||||
echo foo.txt does not exist
|
||||
echo foo.txt and bar.txt do not exist
|
||||
end
|
||||
</pre>
|
||||
will print <tt>foo.txt exists</tt> if the file foo.txt
|
||||
</pre>will print <tt>foo.txt exists</tt> if the file foo.txt
|
||||
exists and is a regular file, otherwise it will print
|
||||
<tt>foo.txt does not exist</tt>.
|
||||
<tt>bar.txt exists</tt> if the file bar.txt exists
|
||||
and is a regular file, otherwise it will print
|
||||
<tt>foo.txt and bar.txt do not exist</tt>.
|
||||
|
||||
@@ -11,7 +11,7 @@ This is the documentation for \c fish, the friendly interactive
|
||||
shell. \c fish is a user friendly commandline shell intended
|
||||
mostly for interactive use. A shell is a program used to execute other
|
||||
programs. For the latest information on \c fish, please visit the <a
|
||||
href="http://www.fishshell.org"><code>fish</code> homepage</a>.
|
||||
href="http://fishshell.com/"><code>fish</code> homepage</a>.
|
||||
|
||||
\section syntax Syntax overview
|
||||
|
||||
@@ -48,7 +48,7 @@ Every program on your computer can be used as a command in \c fish. If
|
||||
the program file is located in one of the directories in the <a
|
||||
href="#variables-special">PATH</a>, it is sufficient to type the name
|
||||
of the program to use it. Otherwise the whole filename, including the
|
||||
directory (like \c /home/me/code/checkers/checkers or \c ../checkers)
|
||||
directory (like \c /home/me/code/checkers/checkers or <code>../checkers</code>)
|
||||
has to be used.
|
||||
|
||||
Here is a list of some useful commands:
|
||||
@@ -80,7 +80,7 @@ while '-f' will turn it off.
|
||||
|
||||
\subsection quotes Quotes
|
||||
|
||||
Sometimes features such as <a href="#globbing">parameter expansion</a>
|
||||
Sometimes features such as <a href="#expand">parameter expansion</a>
|
||||
and <a href="#escapes">character escapes</a> get in the way. When that
|
||||
happens, the user can write a parameter within quotes, either '
|
||||
(single quote) or " (double quote). There is one important difference
|
||||
@@ -92,8 +92,9 @@ only backslash escape accepted within single quotes is \\', which
|
||||
escapes a single quote and \\\\, which escapes the backslash
|
||||
symbol. The only backslash escapes accepted within double quotes are
|
||||
\\", which escapes a double quote, \\$, which escapes a dollar
|
||||
character, and \\\\, which escapes the backslash symbol. Single quotes
|
||||
have no special meaning withing double quotes and vice versa.
|
||||
character, \\ followed by a newline, which deletes the backslash
|
||||
and the newline, and lastly \\\\, which escapes the backslash symbol.
|
||||
Single quotes have no special meaning within double quotes and vice versa.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -110,35 +111,35 @@ would remove the two files 'cumbersome' and 'filename.txt'.
|
||||
Some characters can not be written directly on the command line. For
|
||||
these characters, so called escape sequences are provided. These are:
|
||||
|
||||
- <code>'\\a'</code>, escapes the alert character
|
||||
- <code>'\\b'</code>, escapes the backspace character
|
||||
- <code>'\\e'</code>, escapes the escape character
|
||||
- <code>'\\f'</code>, escapes the form feed character
|
||||
- <code>'\\n'</code>, escapes a newline character
|
||||
- <code>'\\r'</code>, escapes the carriage return character
|
||||
- <code>'\\t'</code>, escapes the tab character
|
||||
- <code>'\\v'</code>, escapes the vertical tab character
|
||||
- <code>'\\ '</code>, escapes the space character
|
||||
- <code>'\\$'</code>, escapes the dollar character
|
||||
- <code>'\\\\'</code>, escapes the backslash character
|
||||
- <code>'\\*'</code>, escapes the star character
|
||||
- <code>'\\?'</code>, escapes the question mark character
|
||||
- <code>'\\~'</code>, escapes the tilde character
|
||||
- <code>'\\%'</code>, escapes the percent character
|
||||
- <code>'\\#'</code>, escapes the hash character
|
||||
- <code>'\\('</code>, escapes the left parenthesis character
|
||||
- <code>'\\)'</code>, escapes the right parenthesis character
|
||||
- <code>'\\{'</code>, escapes the left curly bracket character
|
||||
- <code>'\\}'</code>, escapes the right curly bracket character
|
||||
- <code>'\\['</code>, escapes the left bracket character
|
||||
- <code>'\\]'</code>, escapes the right bracket character
|
||||
- <code>'\\\<'</code>, escapes the less than character
|
||||
- <code>'\\\>'</code>, escapes the more than character
|
||||
- <code>'\\^'</code>, escapes the circumflex character
|
||||
- <code>'\\&'</code>, escapes the ampersand character
|
||||
- <code>'\\;'</code>, escapes the semicolon character
|
||||
- <code>'\\"'</code>, escapes the quote character
|
||||
- <code>'\\''</code>, escapes the apostrophe character
|
||||
- <code>'\\a'</code> escapes the alert character
|
||||
- <code>'\\b'</code> escapes the backspace character
|
||||
- <code>'\\e'</code> escapes the escape character
|
||||
- <code>'\\f'</code> escapes the form feed character
|
||||
- <code>'\\n'</code> escapes a newline character
|
||||
- <code>'\\r'</code> escapes the carriage return character
|
||||
- <code>'\\t'</code> escapes the tab character
|
||||
- <code>'\\v'</code> escapes the vertical tab character
|
||||
- <code>'\\ '</code> escapes the space character
|
||||
- <code>'\\$'</code> escapes the dollar character
|
||||
- <code>'\\\\'</code> escapes the backslash character
|
||||
- <code>'\\*'</code> escapes the star character
|
||||
- <code>'\\?'</code> escapes the question mark character
|
||||
- <code>'\\~'</code> escapes the tilde character
|
||||
- <code>'\\%%'</code> escapes the percent character
|
||||
- <code>'\\#'</code> escapes the hash character
|
||||
- <code>'\\('</code> escapes the left parenthesis character
|
||||
- <code>'\\)'</code> escapes the right parenthesis character
|
||||
- <code>'\\{'</code> escapes the left curly bracket character
|
||||
- <code>'\\}'</code> escapes the right curly bracket character
|
||||
- <code>'\\['</code> escapes the left bracket character
|
||||
- <code>'\\]'</code> escapes the right bracket character
|
||||
- <code>'\\\<'</code> escapes the less than character
|
||||
- <code>'\\\>'</code> escapes the more than character
|
||||
- <code>'\\^'</code> escapes the circumflex character
|
||||
- <code>'\\&'</code> escapes the ampersand character
|
||||
- <code>'\\;'</code> escapes the semicolon character
|
||||
- <code>'\\"'</code> escapes the quote character
|
||||
- <code>'\\''</code> escapes the apostrophe character
|
||||
- <code>'\\x<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes the ascii character with the specified value. For example, \\x9 is the tab character.
|
||||
- <code>'\\X<i>xx</i>'</code>, where <code><i>xx</i></code> is a hexadecimal number, escapes a byte of data with the specified value. If you are using a mutibyte encoding, this can be used to enter invalid strings. Only use this if you know what you are doing.
|
||||
- <code>'\\<i>ooo</i>'</code>, where <code><i>ooo</i></code> is an octal number, escapes the ascii character with the specified value. For example, \\011 is the tab character.
|
||||
@@ -146,9 +147,9 @@ these characters, so called escape sequences are provided. These are:
|
||||
- <code>'\\U<i>xxxxxxxx</i>'</code>, where <code><i>xxxxxxxx</i></code> is a hexadecimal number, escapes the 32-bit Unicode character with the specified value. For example, \\U9 is the tab character.
|
||||
- <code>'\\c<i>x</i>'</code>, where <code><i>x</i></code> is a letter of the alphabet, escapes the control sequence generated by pressing the control key and the specified letter. For example, \\ci is the tab character
|
||||
|
||||
\subsection redirects IO redirection
|
||||
\subsection redirects Input/Output (IO) redirection
|
||||
|
||||
Most program use three types of input/output (IO), each represented by
|
||||
Most programs use three input/output (IO) streams, each represented by
|
||||
a number called a file descriptor (FD). These are:
|
||||
|
||||
- Standard input, FD 0, for reading, defaults to reading from the keyboard.
|
||||
@@ -162,7 +163,7 @@ Any file descriptor can be directed to a different output than its
|
||||
default through a simple mechanism called a redirection.
|
||||
|
||||
An example of a file redirection is <code> echo hello \>output.txt</code>,
|
||||
which directs the output of the echo command to the file error.txt.
|
||||
which directs the output of the echo command to the file output.txt.
|
||||
|
||||
- To redirect standard input, write <code>\<SOURCE_FILE</code>
|
||||
- To redirect standard output, write <code>\>DESTINATION</code>
|
||||
@@ -225,7 +226,7 @@ using the less pager.
|
||||
When you start a job in \c fish, \c fish itself will pause, and give
|
||||
control of the terminal to the program just started. Sometimes, you
|
||||
want to continue using the commandline, and have the job run in the
|
||||
background. To create a background job, append a \& (ampersand) to
|
||||
background. To create a background job, append an \& (ampersand) to
|
||||
your command. This will tell fish to run the job in the
|
||||
background. Background jobs are very useful when running programs that
|
||||
have a graphical user interface.
|
||||
@@ -238,12 +239,12 @@ will start the emacs text editor in the background.
|
||||
|
||||
\subsection syntax-job-control Job control
|
||||
|
||||
Most programs allow you to suspend the programs execution and return
|
||||
control to \c fish by Pressing ^Z (Press and hold the Control key and
|
||||
Most programs allow you to suspend the program's execution and return
|
||||
control to \c fish by pressing ^Z (press and hold the Control key and
|
||||
press 'z'). Once back at the \c fish commandline, you can start other
|
||||
programs and do anything you want. If you then want to go back to the
|
||||
suspended command by using the <a href="commands.html#fg">fg</a>
|
||||
command.
|
||||
programs and do anything you want. If you then want you can go back to
|
||||
the suspended command by using the <a href="commands.html#fg">fg</a>
|
||||
(foreground) command.
|
||||
|
||||
If you instead want to put a suspended job into the background, use
|
||||
the <a href="commands.html#bg">bg</a> command.
|
||||
@@ -251,12 +252,14 @@ the <a href="commands.html#bg">bg</a> command.
|
||||
To get a listing of all currently started jobs, use the <a
|
||||
href="commands.html#jobs">jobs</a> command.
|
||||
|
||||
\subsection syntax-function Shellscript functions
|
||||
\subsection syntax-function Functions
|
||||
|
||||
Functions are used to group together commands and arguments using a
|
||||
single name. It can also be used to start a specific command with
|
||||
additional arguments. For example, the following is a function
|
||||
definition that calls the command 'ls -l' to print a detailed listing
|
||||
Functions are programs written in the fish syntax. They group together one
|
||||
or more commands and their arguments using a single name. It can also be
|
||||
used to start a specific command with additional arguments.
|
||||
|
||||
For example, the following is a function definition that calls the command
|
||||
\c ls with the argument '-l' to print a detailed listing
|
||||
of the contents of the current directory:
|
||||
|
||||
<pre>
|
||||
@@ -265,7 +268,7 @@ function ll
|
||||
end
|
||||
</pre>
|
||||
|
||||
The first line tells fish that a function by the name of ll is to be
|
||||
The first line tells fish that a function by the name of \c ll is to be
|
||||
defined. To use it, simply write <code>ll</code> on the
|
||||
commandline. The second line tells fish that the command <code>ls -l
|
||||
$argv</code> should be called when ll is invoked. $argv is an array
|
||||
@@ -274,42 +277,44 @@ the example above, these are simply passed on to the ls command. For
|
||||
more information on functions, see the documentation for the <a
|
||||
href='commands.html#function'>function</a> builtin.
|
||||
|
||||
\subsubsection syntax-function-wrappers Defining wrapper functions
|
||||
\subsubsection syntax-function-wrappers Defining aliases
|
||||
|
||||
One of the most common used for functions is to slightly alter the
|
||||
One of the most common uses for functions is to slightly alter the
|
||||
behavior of an already existing command. For example, one might want
|
||||
to redefine the \c ls command to display colors. The switch for
|
||||
turning on colors on GNU systems is \c '--color=auto'. A wrapper
|
||||
around \c ls might look like this:
|
||||
turning on colors on GNU systems is \c '--color=auto'. An alias, or
|
||||
wrapper, around \c ls might look like this:
|
||||
|
||||
<pre>function ls
|
||||
ls --color=auto $argv
|
||||
command ls --color=auto $argv
|
||||
end
|
||||
</pre>
|
||||
|
||||
There are a few important things that need to be noted about wrapper
|
||||
functions:
|
||||
There are a few important things that need to be noted about aliases:
|
||||
|
||||
- Wrappers should always take care to add the $argv variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command.
|
||||
- If the wrapped command is not the first command to be called by the wrapper, it is necessary to prefix the call to the command with the word 'command' in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs.
|
||||
- Always take care to add the \c $argv variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command.
|
||||
- If the alias has the same name as the aliased command, it is necessary to prefix the call to the program with \c command in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs.
|
||||
|
||||
To easily create a function of this form, you can use the
|
||||
<a href="commands.html#alias">alias</a> command.
|
||||
|
||||
\subsubsection syntax-function-autoloading Autoloading functions
|
||||
|
||||
Functions can be defined on the commandline or in a configuration
|
||||
file, but they can also be automatically loaded. This method of
|
||||
defining functions has several advantages. An autoloaded function
|
||||
becomes available automatically to all running shells, if the function
|
||||
becomes available automatically to all running shells. If the function
|
||||
definition is changed, all running shells will automatically reload
|
||||
the altered version, startup time and memory usage is improved, etc.
|
||||
the altered version. Startup time and memory usage is improved, etc.
|
||||
|
||||
Fish automatically searches through any directories in the array
|
||||
variable \$fish_function_path, and any functions defined are
|
||||
variable \c $fish_function_path, and any functions defined are
|
||||
automatically loaded when needed. A function definition file must have
|
||||
a filename consisting of the name of the function plus the suffix
|
||||
'.fish'.
|
||||
|
||||
The default value for \$fish_function_path is \c ~/.config/fish/functions
|
||||
\c /etc/fish/functions \c /usr/share/fish/functions. The exact path
|
||||
The default value for \c $fish_function_path is <code>~/.config/fish/functions
|
||||
/etc/fish/functions /usr/share/fish/functions</code>. The exact path
|
||||
to the last two of these may be slightly different depending on what
|
||||
install path prefix was chosen at configuration time. The rationale
|
||||
behind having three different directories is that the first one is for
|
||||
@@ -320,11 +325,11 @@ administrator can override default fish functions, and the user can
|
||||
override functions defined by the system administrator.
|
||||
|
||||
It is very important that function definition files only contain the
|
||||
definition for the specified function and nothing else, otherwise it
|
||||
definition for the specified function and nothing else. Otherwise, it
|
||||
is possible that autoloading a function files requires that the
|
||||
function already be loaded, i.e. a circular dependency.
|
||||
function already be loaded, which creates a circular dependency.
|
||||
|
||||
\subsection syntax-conditional Conditional execution of code
|
||||
\subsection syntax-conditional Conditional execution of code and flow control
|
||||
|
||||
There are four fish builtins that let you execute commands only if a
|
||||
specific criterion is met. These builtins are
|
||||
@@ -359,11 +364,14 @@ This is a short explanation of some of the commonly used words in fish.
|
||||
\section help Help
|
||||
|
||||
\c fish has an extensive help system. Use the <a
|
||||
href="commands.html#help"><code>help</code></a> command to obtain help on
|
||||
href="commands.html#help">help</a> command to obtain help on
|
||||
a specific subject or command. For instance, writing <code>help
|
||||
syntax</code> displays the <a href="#syntax">syntax section</a> of this
|
||||
documentation.
|
||||
|
||||
fish also has man pages for its commands. For example, <code>man set</code>
|
||||
will show the documentation for \c set as a man page.
|
||||
|
||||
Help on a specific builtin can also be obtained with the <code>-h</code>
|
||||
parameter. For instance, to obtain help on the \c fg builtin, either
|
||||
type <code>fg -h</code> or <code>help fg</code>.
|
||||
@@ -386,24 +394,24 @@ command line.
|
||||
|
||||
These are the general purpose tab completions that \c fish provides:
|
||||
|
||||
- Completion of commands, both builtins, functions and regular programs.
|
||||
- Completion of commands (builtins, functions and regular programs).
|
||||
- Completion of environment variable names.
|
||||
- Completion of usernames for tilde expansion.
|
||||
- Completion of filenames, even on strings with wildcards such as '*', '**' and '?'.
|
||||
- Completion of job id, job name and process names for <a href="#expand-process">process expansion</a>.
|
||||
- Completion of job ID, job name and process names for <a href="#expand-process">process expansion</a>.
|
||||
|
||||
\c fish provides a large number of program specific completions. Most
|
||||
of these completions are simple options like the \c -l option for \c
|
||||
ls, but some are more advanced. The latter include:
|
||||
|
||||
- The programs 'man' and 'whatis' show all installed
|
||||
- The programs \c man and \c whatis show all installed
|
||||
manual pages as completions.
|
||||
- The 'make' program uses all targets in the Makefile in
|
||||
- The \c make program uses all targets in the Makefile in
|
||||
the current directory as completions.
|
||||
- The 'mount' command uses all mount points specified in fstab as completions.
|
||||
- The 'ssh' command uses all hosts that are stored
|
||||
in the known_hosts file as completions. (see the ssh documentation for more information)
|
||||
- The 'su' command uses all users on the system as completions.
|
||||
- The \c mount command uses all mount points specified in fstab as completions.
|
||||
- The \c ssh command uses all hosts that are stored
|
||||
in the known_hosts file as completions. (See the ssh documentation for more information)
|
||||
- The \c su command uses all users on the system as completions.
|
||||
- The \c apt-get, \c rpm and \c yum commands use all installed packages as completions.
|
||||
|
||||
\subsection completion-own Writing your own completions
|
||||
@@ -440,7 +448,7 @@ href="commands.html#complete">complete</a> builtin, or write 'complete
|
||||
--help' inside the \c fish shell.
|
||||
|
||||
For examples of how to write your own complex completions, study the
|
||||
completions in /usr/share/fish/completions. (The exact path depends on
|
||||
completions in \c /usr/share/fish/completions. (The exact path depends on
|
||||
your chosen installation prefix and may be slightly different)
|
||||
|
||||
\subsection completion-func Useful functions for writing completions
|
||||
@@ -507,12 +515,12 @@ Debian, rpm and Gentoo packages.
|
||||
Completions can be defined on the commandline or in a configuration
|
||||
file, but they can also be automatically loaded. Fish automatically
|
||||
searches through any directories in the array variable
|
||||
\$fish_complete_path, and any completions defined are automatically
|
||||
\c $fish_complete_path, and any completions defined are automatically
|
||||
loaded when needed. A completion file must have a filename consisting
|
||||
of the name of the command to complete and the suffix '.fish'.
|
||||
|
||||
The default value for \$fish_complete_path is ~/.config/fish/completions,
|
||||
/etc/fish/completions and /usr/share/fish/completions. The exact
|
||||
The default value for \c $fish_complete_path is <code>~/.config/fish/completions
|
||||
/etc/fish/completions /usr/share/fish/completions</code>. The exact
|
||||
path to the last two of these may be slightly different depending on
|
||||
what install path prefix was chosen at configuration time. If a
|
||||
suitable file is found in one of these directories, it will be
|
||||
@@ -522,16 +530,16 @@ user specific completions, the second one is for system-wide
|
||||
completions and the last one is for default fish completions.
|
||||
|
||||
If you have written new completions for a common
|
||||
Unix command, please consider sharing your work by sending it to <a
|
||||
href='mailto: fish-users@lists.sf.net'>the fish mailing list</a>.
|
||||
Unix command, please consider sharing your work by submitting it via
|
||||
the instructions in <a href="#more-help">Further help and development</a>.
|
||||
|
||||
|
||||
\section expand Parameter expansion (Globbing)
|
||||
|
||||
When an argument for a program is given on the commandline, it
|
||||
undergoes the process of parameter expansion before it is sent on to
|
||||
the command. Parameter expansion is a powerful set of mechanisms that
|
||||
allow you to expand the parameter in various ways, including
|
||||
the command. Parameter expansion is a powerful mechanism that
|
||||
allows you to expand the parameter in various ways, including
|
||||
performing wildcard matching on files, inserting the value of
|
||||
environment variables into the parameter or even using the output of
|
||||
another command as a parameter list.
|
||||
@@ -563,7 +571,7 @@ Examples:
|
||||
|
||||
<code>**</code> matches any files and directories in the current directory and all of its subdirectories.
|
||||
|
||||
If no matches are found for a specific wildcard, it will expand into
|
||||
Note that if no matches are found for a specific wildcard, it will expand into
|
||||
zero arguments, i.e. to nothing. If none of the wildcarded arguments
|
||||
sent to a command result in any matches, the command will not be
|
||||
executed. If this happens when using the shell interactively, a
|
||||
@@ -571,24 +579,27 @@ warning will also be printed.
|
||||
|
||||
\subsection expand-command-substitution Command substitution
|
||||
|
||||
If a parameter contains a set of parenthesis, the text enclosed by the
|
||||
The output of a series of commands can be used as the parameters to another
|
||||
command. If a parameter contains a set of parenthesis, the text enclosed by the
|
||||
parenthesis will be interpreted as a list of commands. On expansion,
|
||||
this list is executed, and substituted by the output. If the output is
|
||||
more than one line long, each line will be expanded to a new
|
||||
parameter.
|
||||
|
||||
A command substitution will not change the value of the <a
|
||||
href='#variables-status'>status</a> variable outside of the command
|
||||
substitution.
|
||||
The exit status of the last run command substitution is available in the <a
|
||||
href='#variables-status'>status</a> variable.
|
||||
|
||||
Example:
|
||||
Only part of the output can be used, see <a href='#expand-index-range'>index
|
||||
range expansion</a> for details.
|
||||
|
||||
Examples:
|
||||
|
||||
The command <code>echo (basename image.jpg .jpg).png</code> will
|
||||
output 'image.png'.
|
||||
|
||||
The command <code>for i in *.jpg; convert $i (basename $i .jpg).png;
|
||||
end</code> will convert all Jpeg files in the current directory to the
|
||||
PNG format.
|
||||
end</code> will convert all JPEG files in the current directory to the
|
||||
PNG format using the \c convert program.
|
||||
|
||||
|
||||
\subsection expand-brace Brace expansion
|
||||
@@ -608,35 +619,27 @@ The command <code>mv *.{c,h} src/</code> moves all files with the suffix
|
||||
A dollar sign followed by a string of characters is expanded into the
|
||||
value of the environment variable with the same name. For an
|
||||
introduction to the concept of environment variables, read the <a
|
||||
href="#variables"> Environment variables</a> section.
|
||||
href="#variables">Environment variables</a> section.
|
||||
|
||||
Example:
|
||||
Undefined and empty variables expand to nothing.
|
||||
|
||||
<code> echo \$HOME</code> prints the home directory of the current
|
||||
To separate a variable name from text it should immediately be followed by,
|
||||
encase the variable within braces.
|
||||
|
||||
Examples:
|
||||
|
||||
<code>echo $HOME</code> prints the home directory of the current
|
||||
user.
|
||||
|
||||
If you wish to combine environment variables with text, you can
|
||||
encase the variables within braces to embed a variable inside running
|
||||
text like <code>echo Konnichiwa {$USER}san</code>, which will print a
|
||||
personalized Japanese greeting.
|
||||
<code>echo $nonexistentvariable</code> prints no output.
|
||||
|
||||
The {$USER}san syntax might need a bit of an elaboration. Posix
|
||||
shells allow you to specify a variable name using '$VARNAME' or
|
||||
'${VARNAME}'. Fish supports the former, and has no support whatsoever
|
||||
for the latter or anything like it. So what is '{$VARNAME}' then?
|
||||
Well, '{WHATEVER}' is <a href='#brace'>brace expansion</a>, e.g. 'a{b,c}d' -> 'abd acd'.
|
||||
So '{$VARNAME}' is a bracket-expansion with
|
||||
only a single element, i.e. it becomes expanded to '$VARNAME', which
|
||||
will be variable expanded to the value of the variable 'VARNAME'. So
|
||||
you might think that the brackets don't actually do anything, and that
|
||||
is nearly the truth. The snag is that there once along the way was a
|
||||
'}' in there somewhere, and } is not a valid character in a variable
|
||||
name. So anything after the otherwise pointless bracket expansion
|
||||
becomes explicitly NOT a part of the variable name, even if it happens
|
||||
to be a legal variable name character. That's why '{$USER}san' looks
|
||||
for the variable '$USER' and not for the variable '$USERsan'. It's
|
||||
simply a case of one syntax lending itself nicely to solving an
|
||||
unrelated problem in its spare time.
|
||||
<code>echo The plural of $WORD is {$WORD}s</code> prints "The plural of
|
||||
cat is cats" when \c $WORD is set to cat. Note that without the braces, fish
|
||||
will try to expand a variable called <code>$WORDs</code>, which may not exist.
|
||||
|
||||
The latter syntax works by exploiting <a href="#expand-brace">brace
|
||||
expansion</a>; care should be taken with array variables and undefined
|
||||
variables, as these behave very differently to POSIX shells.
|
||||
|
||||
Variable expansion is the only type of expansion performed on double
|
||||
quoted strings. There is, however, an important difference in how
|
||||
@@ -648,7 +651,9 @@ array of five elements, the argument $foo will expand to five
|
||||
elements. When quoted, like "$foo", a variable expansion will always
|
||||
result in exactly one argument. Undefined variables will expand to the
|
||||
empty string, and array variables will be concatenated using the space
|
||||
character.
|
||||
character. The dangers noted in the third example above can therefore be
|
||||
avoided by wrapping the variable in double quotes
|
||||
(<code>echo {"$WORD"}s</code>).
|
||||
|
||||
There is one further notable feature of fish variable
|
||||
expansion. Consider the following code snippet:
|
||||
@@ -667,12 +672,56 @@ end
|
||||
|
||||
The above code demonstrates how to use multiple '$' symbols to expand
|
||||
the value of a variable as a variable name. One can think of
|
||||
the $-symbol as a variable dereference operator. When using this
|
||||
the $ symbol as a variable dereference operator. When using this
|
||||
feature together with array brackets, the brackets will always match
|
||||
the innermost $ dereference. Thus, $$foo[5] will always mean the fifth
|
||||
element of the foo variable should be dereferenced and never that the fifth
|
||||
element of the doubly dereferenced variable foo. The latter can
|
||||
instead be expressed as $$foo[1][5].
|
||||
the innermost $ dereference. Thus, <code>$$foo[5]</code> will always mean the fifth
|
||||
element of the \c foo variable should be dereferenced, not the fifth
|
||||
element of the doubly dereferenced variable \c foo. The latter can
|
||||
instead be expressed as <code>$$foo[1][5]</code>.
|
||||
|
||||
\subsection expand-index-range Index range expansion
|
||||
|
||||
Both command substitution and environment variables support accessing only
|
||||
specific items by providing a set of indices in square brackets. It's
|
||||
often needed to access a sequence of elements. To do this, use the range
|
||||
operator '..' for this. A range <code>'a..b'</code>, where range limits 'a'
|
||||
and 'b' are integer numbers, is expanded into a sequence of indices
|
||||
'a a+1 a+2 ... b' or 'a a-1 a-2 ... b' depending on which of 'a' or 'b'
|
||||
is higher. The negative range limits are calculated from the end of the array
|
||||
or command substitution.
|
||||
|
||||
Some examples:
|
||||
<pre>
|
||||
# Limit the command substitution output
|
||||
echo (seq 10)[2..5] # will use elements from 2 to 5
|
||||
# Output is:
|
||||
# 2 3 4 5
|
||||
|
||||
# Use overlapping ranges:
|
||||
echo (seq 10)[2..5 1..3] # will take elements from 2 to 5 and then elements from 1 to 3
|
||||
# Output is:
|
||||
# 2 3 4 5 1 2 3
|
||||
|
||||
# Reverse output
|
||||
echo (seq 10)[-1..1] # will use elements from the last output line to the first one in reverse direction
|
||||
# Output is:
|
||||
# 10 9 8 7 6 5 4 3 2 1
|
||||
</pre>
|
||||
|
||||
The same works when setting or expanding variables:
|
||||
<pre>
|
||||
# Reverse path variable
|
||||
set PATH $PATH[-1..1]
|
||||
# or
|
||||
set PATH[-1..1] $PATH
|
||||
|
||||
# Use only n last items of the PATH
|
||||
set n -3
|
||||
echo $PATH[$n..-1]
|
||||
</pre>
|
||||
|
||||
Note that variables can be used as indices for expansion of variables, but not
|
||||
command substitution.
|
||||
|
||||
\subsection expand-home Home directory expansion
|
||||
|
||||
@@ -684,19 +733,20 @@ directory of the process owner.
|
||||
\subsection expand-process Process expansion
|
||||
|
||||
The \% (percent) character at the beginning of a parameter followed by
|
||||
a string is expanded into a process id. The following expansions are
|
||||
a string is expanded into a process ID (PID). The following expansions are
|
||||
performed:
|
||||
|
||||
- If the string is the entire word \c self, the shells pid is the result.
|
||||
- Otherwise, if the string is the id of a job, the result is the process
|
||||
group id of the job.
|
||||
- If the string is the entire word \c self, the shell's PID is the result.
|
||||
- Otherwise, if the string is the ID of a job, the result is the process
|
||||
group ID of the job.
|
||||
- Otherwise, if any child processes match the specified string, their
|
||||
pids are the result of the expansion.
|
||||
PIDs are the result of the expansion.
|
||||
- Otherwise, if any processes owned by the user match the specified
|
||||
string, their pids are the result of the expansion.
|
||||
string, their PIDs are the result of the expansion.
|
||||
- If none of these matches apply, an error is produced.
|
||||
|
||||
This form of expansion is useful for commands like kill and fg, which
|
||||
take the process ids as an argument.
|
||||
take process IDs as arguments.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -705,7 +755,7 @@ with the letters 'ema', such as emacs, and if found, put it in the
|
||||
foreground.
|
||||
|
||||
<code>kill -s SIGINT \%3</code> will send the SIGINT signal to the job
|
||||
with job id 3.
|
||||
with job ID 3.
|
||||
|
||||
\subsection combine Combining different expansions
|
||||
|
||||
@@ -733,11 +783,8 @@ will output 'abar1 abar2 abar3 afoo1 afoo2 afoo3'.
|
||||
|
||||
\section variables Environment variables
|
||||
|
||||
The concept of environment variables are central to any
|
||||
shell. Environment variables are variables, whose values can be set
|
||||
and used by the user. For information on how to use the current value
|
||||
of a variable, see the section on <a href='#expand-variable'>variable
|
||||
expansion</a>.
|
||||
Environment variables are named pieces of data, which can be created, deleted
|
||||
and their values changed and used by the user.
|
||||
|
||||
To set a variable value, use the <a href="commands.html#set"> \c set
|
||||
command</a>.
|
||||
@@ -759,7 +806,7 @@ usually blue'.
|
||||
|
||||
\subsection variables-scope Variable scope
|
||||
|
||||
There are three kinds of variables in fish, universal, global and
|
||||
There are three kinds of variables in fish: universal, global and
|
||||
local variables. Universal variables are shared between all fish
|
||||
sessions a user is running on one computer. Global variables are
|
||||
specific to the current fish session, but are not associated with any
|
||||
@@ -768,9 +815,9 @@ explicitly requests it using <code>set -e</code>. Local variables are
|
||||
specific to the current fish session, and associated with a specific
|
||||
block of commands, and is automatically erased when a specific block
|
||||
goes out of scope. A block of commands is a series of commands that
|
||||
begins with one of the commands \c 'for, \c 'while' , \c 'if', \c
|
||||
'function', \c 'begin' or \c 'switch', and ends with the command \c
|
||||
'end'. The user can specify that a variable should have either global
|
||||
begins with one of the commands \c for, \c while , \c if, \c
|
||||
function, \c begin or \c switch, and ends with the command \c
|
||||
end. The user can specify that a variable should have either global
|
||||
or local scope using the \c -g/--global or \c -l/--local switches.
|
||||
|
||||
Variables can be explicitly set to be universal with the \c -U or \c
|
||||
@@ -780,7 +827,7 @@ creating or updating a variable are:
|
||||
|
||||
-# If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed.
|
||||
-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the variable scope is not changed.
|
||||
-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing functions. If no function is executing, the variable will be global.
|
||||
-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the \c -l or \c --local flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global.
|
||||
|
||||
There may be many variables with the same name, but different scopes.
|
||||
When using a variable, the variable scope will be searched from the
|
||||
@@ -818,7 +865,7 @@ prompt will instantly change to blue on both terminals.
|
||||
|
||||
\subsection variables-functions Variable scope for functions
|
||||
|
||||
When calling a function, all non-global variables temporarily
|
||||
When calling a function, all current local variables temporarily
|
||||
disappear. This shadowing of the local scope is needed since the
|
||||
variable namespace would become cluttered, making it very easy to
|
||||
accidentally overwrite variables from another function.
|
||||
@@ -871,7 +918,7 @@ echo $PATH[3]
|
||||
</pre>
|
||||
|
||||
Note that array indices start at 1 in fish, not 0, as is more common
|
||||
in other languages. This is because many common Unix tools like seq
|
||||
in other languages. This is because many common Unix tools like \c seq
|
||||
are more suited to such use.
|
||||
|
||||
If you do not use any brackets, all the elements of the array will be
|
||||
@@ -909,44 +956,49 @@ If you specify a negative index when expanding or assigning to an
|
||||
array variable, the index will be calculated from the end of the
|
||||
array. For example, the index -1 means the last index of an array.
|
||||
|
||||
A range of indices can be specified, see <a href='#expand-index-range'>index
|
||||
range expansion</a> for details.
|
||||
|
||||
All arrays are one-dimensional and cannot contain other arrays, although
|
||||
it is possible to fake nested arrays using the dereferencing rules of
|
||||
<a href="#expand-variable">variable expansion</a>.
|
||||
|
||||
\subsection variables-special Special variables
|
||||
|
||||
The user can change the settings of \c fish by changing the values of
|
||||
certain environment variables.
|
||||
|
||||
- \c BROWSER, which is the users preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
|
||||
- \c CDPATH, which is an array of directories in which to search for the new directory for the \c cd builtin. The fish init files defined CDPATH to be a universal variable with the values . and ~.
|
||||
- \c BROWSER, the user's preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
|
||||
- \c CDPATH, an array of directories in which to search for the new directory for the \c cd builtin. By default, the fish configuration defines \c CDPATH to be a universal variable with the values \c . and \c ~.
|
||||
- A large number of variable starting with the prefixes \c fish_color and \c fish_pager_color. See <a href='#variables-color'>Variables for changing highlighting colors</a> for more information.
|
||||
- \c fish_greeting, which is the greeting message printed on startup.
|
||||
- \c fish_greeting, the greeting message printed on startup.
|
||||
- \c LANG, \c LC_ALL, \c LC_COLLATE, \c LC_CTYPE, \c LC_MESSAGES, \c LC_MONETARY, \c LC_NUMERIC and \c LC_TIME set the language option for the shell and subprograms. See the section <a href='#variables-locale'>Locale variables</a> for more information.
|
||||
- \c PATH, which is an array of directories in which to search for commands
|
||||
- \c umask, which is the current file creation mask. The preferred way to change the umask variable is through the <a href="commands.html#umask">umask shellscript function</a>. An attempt to set umask to an invalid value will always fail.
|
||||
- \c fish_user_paths, an array of directories that are appended to PATH. This can be a universal variable.
|
||||
- \c PATH, an array of directories in which to search for commands
|
||||
- \c umask, the current file creation mask. The preferred way to change the umask variable is through the <a href="commands.html#umask">umask function</a>. An attempt to set umask to an invalid value will always fail.
|
||||
|
||||
\c fish also sends additional information to the user through the
|
||||
values of certain environment variables. The user can not change the
|
||||
values of certain environment variables. The user cannot change the
|
||||
values of most of these variables.
|
||||
|
||||
- \c _, which is the name of the currently running command.
|
||||
- \c argv, which is an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
|
||||
- \c history, which is an array containing the last commands that where entered.
|
||||
- \c HOME, which is the users home directory. This variable can only be changed by the root user.
|
||||
- \c PWD, which is the current working directory.
|
||||
- \c status, which is the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
||||
- \c USER, which is the username. This variable can only be changed by the root user.
|
||||
- \c _, the name of the currently running command.
|
||||
- \c argv, an array of arguments to the shell or function. \c argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like 'fish myscript.fish foo bar'. This variable can be changed by the user.
|
||||
- \c history, an array containing the last commands that were entered.
|
||||
- \c HOME, the user's home directory. This variable can only be changed by the root user.
|
||||
- \c PWD, the current working directory.
|
||||
- \c status, the <a href="#variables-status">exit status</a> of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
|
||||
- \c USER, the current username. This variable can only be changed by the root user.
|
||||
|
||||
The names of these variables are mostly derived from the csh family of
|
||||
shells and differ from the ones used by Bourne style shells such as
|
||||
bash. The csh names where chosen because Bourne style names, such as
|
||||
?, * and @ lead to significantly less readable code, and much larger
|
||||
discoverability problems, and given the existence of tab completion,
|
||||
the keystroke savings are minimal.
|
||||
bash.
|
||||
|
||||
Variables whose name are in uppercase are exported to the commands
|
||||
started by fish, those in lowercase are not exported. This rule is not
|
||||
started by fish, while those in lowercase are not exported. This rule is not
|
||||
enforced by fish, but it is good coding practice to use casing to
|
||||
distinguish between exported and unexported variables. \c fish also
|
||||
uses several variables internally. Such variables are prefixed with
|
||||
the string __FISH or __fish. These should never be used by the
|
||||
the string \c __FISH or \c __fish. These should never be used by the
|
||||
user. Changing their value may break fish.
|
||||
|
||||
\subsection variables-status The status variable
|
||||
@@ -961,10 +1013,10 @@ some form of problem.
|
||||
Fish stores the exit status of the last process in the last job to
|
||||
exit in the \c status variable.
|
||||
|
||||
If fish encounters a problem while executing a command, the status
|
||||
If \c fish encounters a problem while executing a command, the status
|
||||
variable may also be set to a specific value:
|
||||
|
||||
- 1 is the generally the exit status from fish builtins if they where supplied with invalid arguments
|
||||
- 1 is the generally the exit status from fish builtin commands if they were supplied with invalid arguments
|
||||
- 124 means that the command was not executed because none of the wildcards in the command produced any matches
|
||||
- 125 means that while an executable with the specified name was located, the operating system could not actually execute the command
|
||||
- 126 means that while a file with the specified name was located, it was not executable
|
||||
@@ -1004,6 +1056,7 @@ highlighting in the completion pager:
|
||||
- \c fish_pager_color_completion, the color of the completion itself
|
||||
- \c fish_pager_color_description, the color of the completion description
|
||||
- \c fish_pager_color_progress, the color of the progress bar at the bottom left corner
|
||||
- \c fish_pager_color_secondary, the background color of the every second completion
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1027,13 +1080,13 @@ variables set the specified aspect of the locale information. LANG
|
||||
is a fallback value, it will be used if none of the LC_ variables are
|
||||
specified.
|
||||
|
||||
\section builtin-overview Builtins
|
||||
\section builtin-overview Builtin commands
|
||||
|
||||
Many other shells have a large library of builtin commands. Most of
|
||||
these commands are also available as standalone commands, but have
|
||||
been implemented in the shell anyway for whatever reason. To avoid
|
||||
been implemented in the shell anyway. To avoid
|
||||
code duplication, and to avoid the confusion of subtly differing
|
||||
versions of the same command, \c fish only implements builtins for
|
||||
versions of the same command, \c fish generally only implements builtins for
|
||||
actions which cannot be performed by a regular command.
|
||||
|
||||
For a list of all builtins, functions and commands shipped with fish,
|
||||
@@ -1041,31 +1094,32 @@ see the <a href="#toc-commands">table of contents</a>. The
|
||||
documentation is also available by using the <code>--help</code>
|
||||
switch of the command.
|
||||
|
||||
\section editor Command Line editor
|
||||
\section editor Command line editor
|
||||
|
||||
The \c fish editor features copy and paste, a searchable history and
|
||||
many editor functions that can be bound to special keyboard
|
||||
shortcuts. The most important keybinding is probably the tab key, which is bound to the complete function.
|
||||
shortcuts.
|
||||
|
||||
Here are some of the commands available in the editor:
|
||||
|
||||
- Tab completes the current token
|
||||
- Home or Ctrl-a moves to the beginning of the line
|
||||
- End or Ctrl-e moves to the end of line
|
||||
- Left and right moves one character left or right
|
||||
- Alt-left and Alt-right moves one word left or right, or moves forward/backward in the directory history if the commandline is empty
|
||||
- Up and down search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the <a href='#history'>history </a>section for more information on history searching.
|
||||
- Alt-up and Alt-down search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the <a href='#history'>history </a>section for more information on history searching.
|
||||
- Delete and backspace removes one character forwards or backwards respectively
|
||||
- Ctrl-c deletes entire line
|
||||
- Ctrl-d delete one character to the right of the cursor, unless the buffer is empty, in which case the shell will exit
|
||||
- Ctrl-k move contents from the cursor to the end of line to the <a href="#killring">killring</a>
|
||||
- Ctrl-u move contents from the beginning of line to the cursor to the <a href="#killring">killring</a>
|
||||
- Ctrl-l clear and repaint screen
|
||||
- Ctrl-w move previous word to the <a href="#killring">killring</a>
|
||||
- Alt-d move next word to the <a href="#killring">killring</a>
|
||||
- Alt-w prints a short description of the command under the cursor
|
||||
- Alt-l lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
|
||||
- Alt-p adds the string '| less;' to the end of the job under the cursor. The result is that the output of the command will be paged.
|
||||
- Tab <a href="#completion">completes</a> the current token
|
||||
- Home or Ctrl-A moves to the beginning of the line
|
||||
- End or Ctrl-E moves to the end of line
|
||||
- Left and Right moves one character left or right
|
||||
- Alt-Left and Alt-Right moves one word left or right, or moves forward/backward in the directory history if the commandline is empty
|
||||
- Up and Down search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the <a href='#history'>history </a>section for more information on history searching.
|
||||
- Alt-Up and Alt-Down search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the <a href='#history'>history </a>section for more information on history searching.
|
||||
- Delete and Backspace removes one character forwards or backwards respectively
|
||||
- Ctrl-C deletes entire line
|
||||
- Ctrl-D delete one character to the right of the cursor, unless the buffer is empty, in which case the shell will exit
|
||||
- Ctrl-K moves contents from the cursor to the end of line to the <a href="#killring">killring</a>
|
||||
- Ctrl-U moves contents from the beginning of line to the cursor to the <a href="#killring">killring</a>
|
||||
- Ctrl-L clears and repaints the screen
|
||||
- Ctrl-W moves the previous word to the <a href="#killring">killring</a>
|
||||
- Alt-D moves the next word to the <a href="#killring">killring</a>
|
||||
- Alt-W prints a short description of the command under the cursor
|
||||
- Alt-L lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed
|
||||
- Alt-P adds the string <code>'| less;'</code> to the end of the job under the cursor. The result is that the output of the command will be paged.
|
||||
|
||||
You can change these key bindings using the
|
||||
<a href="commands.html#bind">bind</a> builtin command.
|
||||
@@ -1108,8 +1162,8 @@ inserted into a linked list of kills, called the kill ring. To paste
|
||||
the latest value from the kill ring use Ctrl-Y. After pasting, use
|
||||
Meta-Y to rotate to the previous kill.
|
||||
|
||||
If the environment variable DISPLAY is set, \c fish will try to
|
||||
connect to the X-windows server specified by this variable, and use
|
||||
If the environment variable DISPLAY is set and the \c xsel program is installed, \c fish will try to
|
||||
connect to the X Windows server specified by this variable, and use
|
||||
the clipboard on the X server for copying and pasting.
|
||||
|
||||
\subsection history Searchable history
|
||||
@@ -1121,31 +1175,36 @@ forwards and backwards in the history. If the current command line is
|
||||
not empty when starting a history search, only the commands containing
|
||||
the string entered into the command line are shown.
|
||||
|
||||
By pressing Alt-up and Alt-down, a history search is also performed,
|
||||
By pressing Alt-Up and Alt-Down, a history search is also performed,
|
||||
but instead of searching for a complete commandline, each commandline
|
||||
is tokenized into separate elements just like it would be before
|
||||
execution, and each such token is matched against the token under the
|
||||
cursor when the search began.
|
||||
is broken into separate elements just like it would be before
|
||||
execution, and the history is searched for an element matching that under
|
||||
the cursor.
|
||||
|
||||
History searches can be aborted by pressing the escape key.
|
||||
|
||||
The history is stored in the file '~/.config/fish/fish_history'. It is automatically
|
||||
read on startup and merged on program exit.
|
||||
Prefixing the commandline with a space will prevent the entire line
|
||||
from being stored in the history.
|
||||
|
||||
Example:
|
||||
The history is stored in the file <code>~/.config/fish/fish_history</code>.
|
||||
|
||||
To search for previous entries containing the word 'make', type 'make'
|
||||
Examples:
|
||||
|
||||
To search for previous entries containing the word \c 'make', type \c 'make'
|
||||
in the console and press the up key.
|
||||
|
||||
If the commandline reads '<code>cd m</code>', place the cursor over the \c m
|
||||
character and press Alt-Up to search for previously typed words containing 'm'.
|
||||
|
||||
\subsection multiline Multiline editing
|
||||
|
||||
The fish commandline editor can be used to work on commands that are
|
||||
several lines long. There are three ways to make a command span more
|
||||
than a single line:
|
||||
|
||||
- Pressing the enter key while a block of commands is unclosed, i.e. when one or more block commands such as 'for', 'begin' or 'if' do not have a corresponding 'end' command.
|
||||
- Pressing Alt-enter instead of pressing the enter key.
|
||||
- By backslash escaping a newline, i.e. by inserting a backslash (\\) character before pressing the enter key.
|
||||
- Pressing the Enter key while a block of commands is unclosed, such as when one or more block commands such as \c 'for', \c 'begin' or \c 'if' do not have a corresponding \c 'end' command.
|
||||
- Pressing Alt-Enter instead of pressing the Enter key.
|
||||
- By inserting a backslash (\\) character before pressing the Enter key, escaping the newline.
|
||||
|
||||
The fish commandline editor works exactly the same in single line mode
|
||||
and in multiline mode. To move between lines use the left and right
|
||||
@@ -1162,9 +1221,13 @@ continue using the shell. In such cases, there are several ways in
|
||||
which the user can change <code>fish</code>'s behavior.
|
||||
|
||||
-# By ending a command with the \& (ampersand) symbol, the user tells \c fish to put the specified command into the background. A background process will be run simultaneous with \c fish. \c fish will retain control of the terminal, so the program will not be able to read from the keyboard.
|
||||
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. Gnu emacs uses ^X z to stop running.
|
||||
-# By pressing ^Z, the user stops a currently running foreground program and returns control to \c fish. Some programs do not support this feature, or remap it to another key. GNU Emacs uses ^X z to stop running.
|
||||
-# By using the <a href="commands.html#fg">fg</a> and <a href="commands.html#bg">bg</a> builtin commands, the user can send any currently running job into the foreground or background.
|
||||
|
||||
Note that functions cannot be started in the background. Functions that
|
||||
are stopped and then restarted in the background using the \c bg command
|
||||
will not execute correctly.
|
||||
|
||||
\section initialization Initialization files
|
||||
|
||||
On startup, \c fish evaluates the files /usr/share/fish/config.fish
|
||||
@@ -1198,9 +1261,9 @@ shell:
|
||||
end</pre>
|
||||
|
||||
<a href="#variables-universal">Universal variables</a> are stored in
|
||||
the file .config/fish/fishd.HOSTNAME, where HOSTNAME is the name of your
|
||||
computer. Do not edit this file directly, edit them through fish
|
||||
scripts or by using fish interactively instead.
|
||||
the file .config/fish/fishd.MACHINE_ID, where MACHINE_ID is typically your
|
||||
MAC address. Do not edit this file directly, as your edits may be overwritten.
|
||||
Edit them through fish scripts or by using fish interactively instead.
|
||||
|
||||
\section other Other features
|
||||
|
||||
@@ -1227,8 +1290,8 @@ fish_color_substitution, \c fish_color_redirection, \c fish_color_end,
|
||||
\c fish_color_error, \c fish_color_param, \c fish_color_comment, \c
|
||||
fish_color_match, \c fish_color_search_match, \c fish_color_cwd, \c
|
||||
fish_pager_color_prefix, \c fish_pager_color_completion, \c
|
||||
fish_pager_color_description and \c
|
||||
fish_pager_color_progress. Usually, the value of these variables will
|
||||
fish_pager_color_description, \c fish_pager_color_progress
|
||||
and \c fish_pager_color_secondary. Usually, the value of these variables will
|
||||
be one of \c black, \c red, \c green, \c brown, \c yellow, \c blue, \c
|
||||
magenta, \c purple, \c cyan, \c white or \c normal, but they can be an
|
||||
array containing any color options for the set_color command.
|
||||
@@ -1323,7 +1386,7 @@ translated, a future version of fish should also include translated
|
||||
manuals.
|
||||
|
||||
To make a translation of fish, you will first need the source code,
|
||||
available from the <a href='http://www.fishshell.org'>fish
|
||||
available from the <a href='http://fishshell.com/'>fish
|
||||
homepage</a>. Download the latest version, and then extract it using a
|
||||
command like <code>tar -zxf fish-VERSION.tar.gz</code>.
|
||||
|
||||
@@ -1374,70 +1437,19 @@ are ways to avoid this, but they are too complicated for this short
|
||||
introduction. See the full manual for the printf C function for more
|
||||
information.)
|
||||
|
||||
Once you have provided a translation for fish, please send it to <a
|
||||
href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>.
|
||||
Once you have provided a translation for fish, please submit it via
|
||||
the instructions in <a href="#more-help">Further help and development</a>.
|
||||
|
||||
\section todo Missing features and bugs
|
||||
\section more-help Further help and development
|
||||
|
||||
\subsection todo-features Missing features
|
||||
If you have a question not answered by this documentation, there are
|
||||
several avenues for help:
|
||||
|
||||
- Complete vi-mode key bindings
|
||||
- More completions (for example konsole, gnome-terminal,
|
||||
rlogin, rsync, arch, finger, bibtex, aspell, xpdf,
|
||||
compress, wine, dig, batch,
|
||||
g++, javac, java, gcj, lpr, doxygen, whois)
|
||||
- Undo support
|
||||
- wait shellscript
|
||||
- Support for the screen clipboard
|
||||
- It should be possible to test in a script if a function is autoloaded or manually defined
|
||||
- The validator should be better about error reporting unclosed quotes. They are usually reported as something else.
|
||||
-# The official mailing list at <a href='fish-users@lists.sf.net'>fish-users@lists.sf.net</a>
|
||||
-# The Internet Relay Chat channel, \c #fish on \c irc.oftc.net
|
||||
-# The <a href="http://github.com/fish-shell/fish-shell/">project GitHub page</a>
|
||||
|
||||
\subsection todo-possible Possible features
|
||||
|
||||
- mouse support like zsh has with http://stchaz.free.fr/mouse.zsh
|
||||
installed would be awesome
|
||||
- suggest a completion on unique matches by writing it out in an understated color
|
||||
- Highlight beginning/end of block when moving over a block command
|
||||
- command specific wildcarding (use case * instead of case '*', etc.)
|
||||
- Map variables. (export only the values. When expanding with no key specified, expand to all values.)
|
||||
- Descriptions for variables using 'set -d'.
|
||||
- Parse errors should when possible honor IO redirections
|
||||
- Support for writing strings like /u/l/b/foo and have them expand to /usr/local/bin/foo - perhaps through tab expansion
|
||||
- Right-side prompt
|
||||
- Selectable completions in the pager
|
||||
- Per process output redirection
|
||||
- Reduce the space of the pager by one line to allow the commandline to remain visible.
|
||||
- down-arrow could be used to save the current command to the history. Or give the next command in-sequence. Or both.
|
||||
- History could reload itself when the file is updated. This would need to be done in a clever way to avoid chain reactions
|
||||
- The error function should probably be moved into it's own library, and be made mere general purpose.
|
||||
- The code validation functions should be moved from the parser to parse_util.
|
||||
- Try to remove more malloc calls to reduce memory usage. The time_t arrays used by the autoloader sound like a good candidate.
|
||||
- The code validator should warn about unknown commands.
|
||||
- Auto-newlines
|
||||
- A fault injector could be written to increase robustness and testing of error recovery paths
|
||||
- The parser/validator could be more clever in order to make things like writing 'function --help' work as expected
|
||||
- Some event handler functions make much more sense as oneshots - maybe they should be automatically deleted after firing?
|
||||
- exec_subshell should be either merged with eval or moved to parser.c
|
||||
- Don't use expand_string to perform completions. wildcard_complete can be called directly, the brace expansion handling should be universal, and the process expansion can be moved to complete.c.
|
||||
- Make the history search support incremental searching
|
||||
- An automatic logout feature
|
||||
- Make tab completions completely silent by default, i.e. kill stderr when running completion commands. This needs to be overridalbe for debugging purposes.
|
||||
- Move history to an environment variable
|
||||
|
||||
\subsection bugs Known bugs and issues
|
||||
|
||||
- Suspending and then resuming pipelines containing a builtin or a shellscript function is broken. Ideally, the exec function in exec.c should be able to resume execution of a partially executed job.
|
||||
- delete-word is broken on the commandline 'sudo update-alternatives --config x-'
|
||||
- Sometimes autoheader needs to be run on a fresh tarball. Fix dates before creating tarballs.
|
||||
- The completion autoloader does not remember which completions where actually autoloaded, and may unload manually specified completions.
|
||||
- There have been stray reports of issues with strange values of the PATH variable during startup.
|
||||
- bindings in config.fish are overwritten by default key bindings.
|
||||
- Adding 'bind -k ...' doesn't overwrite non-keybinding binds of the same sequence.
|
||||
- History file does not remove duplicates.
|
||||
- History file should apply some kind of maximum history length.
|
||||
- Older versions of Doxygen has bugs in the man-page generation which cause the builtin help to render incorrectly. Version 1.2.14 is known to have this problem.
|
||||
|
||||
If you think you have found a bug not described here, please send a
|
||||
report to <a href="mailto:fish-users@lists.sf.net">fish-users@lists.sf.net</a>.
|
||||
If you have an improvement for fish, you can submit it via the mailing list
|
||||
or the GitHub page.
|
||||
|
||||
*/
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
\subsection isatty-synopsis Synopsis
|
||||
<tt>isatty [FILE DESCRIPTOR]</tt>
|
||||
|
||||
where FILE DESCRIPTOR may be either the number of a file descriptor, or one
|
||||
of the strings stdin, stdout and stderr.
|
||||
\subsection isatty-description Description
|
||||
<tt>isatty</tt> tests if a file descriptor is a tty.
|
||||
|
||||
If the specified file descriptor is a tty, the exit status of the
|
||||
command is zero, otherwise, it is non-zero.
|
||||
<tt>FILE DESCRIPTOR</tt> may be either the number of a file descriptor, or one of the
|
||||
strings <tt>stdin</tt>, \c stdout and <tt>stderr</tt>.
|
||||
|
||||
If the specified file descriptor is a tty, the exit status of the command is
|
||||
zero. Otherwise, it is non-zero.
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
\section jobs jobs - print currently running jobs
|
||||
|
||||
\subsection jobs-synopsis
|
||||
\subsection jobs-synopsis Synopsis
|
||||
<code>jobs [OPTIONS] [PID]</code>
|
||||
|
||||
\subsection jobs-description Description
|
||||
The <code>jobs</code> builtin causes fish to print a list of the currently
|
||||
running jobs and their status.
|
||||
<code>jobs</code> prints a list of the currently
|
||||
running <a href="index.html#syntax-job-control">jobs</a> and their status.
|
||||
|
||||
jobs accepts the following switches:
|
||||
|
||||
- <code>-c</code> or <code>--command</code> print the command name for each process in jobs
|
||||
- <code>-g</code> or <code>--group</code> only print the group id of each job
|
||||
- <code>-h</code> or <code>--help</code> display a help message and exit
|
||||
- <code>-l</code> or <code>--last</code> only the last job to be started is printed
|
||||
- <code>-p</code> or <code>--pid</code> print the process id for each process in all jobs
|
||||
- <code>-c</code> or <code>--command</code> prints the command name for each process in jobs.
|
||||
- <code>-g</code> or <code>--group</code> only prints the group ID of each job.
|
||||
- <code>-h</code> or <code>--help</code> displays a help message and exits.
|
||||
- <code>-l</code> or <code>--last</code> prints only the last job to be started.
|
||||
- <code>-p</code> or <code>--pid</code> prints the process ID for each process in all jobs.
|
||||
|
||||
On systems that supports this feature, jobs will print the CPU usage
|
||||
of each job since the last command was executed. The CPU usage is
|
||||
expressed as a percentage of full CPU activity. Note that on
|
||||
multiprocessor systems, the total activity may be more than 100\%.
|
||||
|
||||
\subsection jobs-example Example
|
||||
|
||||
<code>jobs</code> outputs a summary of the current jobs.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user