mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-08 11:33:49 -05:00
Compare commits
606 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84839ae589 | ||
|
|
75aee988b3 | ||
|
|
1d08efe089 | ||
|
|
2e3ef01abb | ||
|
|
efeab7f8ee | ||
|
|
e5c7eb3399 | ||
|
|
a43095dc11 | ||
|
|
4aa904634f | ||
|
|
4a7d13d7ce | ||
|
|
c335ab83de | ||
|
|
bf1fcd346b | ||
|
|
873e0249a5 | ||
|
|
d6e547b94e | ||
|
|
3bac268cdb | ||
|
|
19fa774e42 | ||
|
|
af03af9593 | ||
|
|
1fcb988164 | ||
|
|
925e5ad0e7 | ||
|
|
35960ee19e | ||
|
|
c3ba994ec2 | ||
|
|
a3b98a4223 | ||
|
|
ac020225c2 | ||
|
|
f2ac882579 | ||
|
|
e8b7a27ee6 | ||
|
|
8d0ca21451 | ||
|
|
d7a5e87d75 | ||
|
|
5cae73944f | ||
|
|
325abac17d | ||
|
|
d10388a052 | ||
|
|
7c4350edf4 | ||
|
|
d6bb1c6396 | ||
|
|
ad6544409b | ||
|
|
ae8a0ee125 | ||
|
|
3646eb840b | ||
|
|
6e58140657 | ||
|
|
a7e508fcdf | ||
|
|
d1f1865c2a | ||
|
|
86b5797083 | ||
|
|
5d78e47399 | ||
|
|
59acc42647 | ||
|
|
4fec76f267 | ||
|
|
592fe6a087 | ||
|
|
906a6acc10 | ||
|
|
3112172081 | ||
|
|
cfe1c37d26 | ||
|
|
af9201ea1e | ||
|
|
56512aee3b | ||
|
|
e390b228c8 | ||
|
|
a632465cf4 | ||
|
|
54744db05e | ||
|
|
dd79c11f6c | ||
|
|
0704e65781 | ||
|
|
8644fb5519 | ||
|
|
41e242857e | ||
|
|
6f21f76965 | ||
|
|
8be1b9bd0e | ||
|
|
7eafc5fe02 | ||
|
|
9fe4cb8e1e | ||
|
|
61747c06d4 | ||
|
|
7509eafdd0 | ||
|
|
593f820a7d | ||
|
|
5c12600625 | ||
|
|
6717c62dc1 | ||
|
|
5f9c0ba613 | ||
|
|
52acbdf83f | ||
|
|
85f304ef3b | ||
|
|
41580b69db | ||
|
|
3e5347be1e | ||
|
|
172a79e993 | ||
|
|
8275e15cb0 | ||
|
|
90c0357682 | ||
|
|
30aaf4edba | ||
|
|
d97713d1b5 | ||
|
|
43e30ef815 | ||
|
|
6b1cc34610 | ||
|
|
d2d3012f17 | ||
|
|
410e05bf8c | ||
|
|
a6cf6aeadb | ||
|
|
8406a2bc7f | ||
|
|
ed1a3a5545 | ||
|
|
22ee5d4175 | ||
|
|
7c7c4dc11c | ||
|
|
45ae8d2ebc | ||
|
|
396e65a461 | ||
|
|
959968c46d | ||
|
|
009ef3a2db | ||
|
|
acdd8a95bd | ||
|
|
98412dba80 | ||
|
|
6426f852d0 | ||
|
|
33f8621ec8 | ||
|
|
9572edf4bb | ||
|
|
117a381575 | ||
|
|
56a440e4a7 | ||
|
|
a8ecfc743e | ||
|
|
c4395e5820 | ||
|
|
a54b47e783 | ||
|
|
c6cc0a1959 | ||
|
|
b39d4291be | ||
|
|
cec6d46792 | ||
|
|
e4f61e67e2 | ||
|
|
42aa760e2e | ||
|
|
d2c527cdd7 | ||
|
|
a76c4aaafa | ||
|
|
5b5c60fb6e | ||
|
|
304cb7b6a7 | ||
|
|
25fdc1caf9 | ||
|
|
264cb65a1e | ||
|
|
00d93c1d91 | ||
|
|
68fca03bb8 | ||
|
|
6cc7bff383 | ||
|
|
38e1fbb08e | ||
|
|
69323e77cc | ||
|
|
526f2de13d | ||
|
|
28cd6f123e | ||
|
|
d3d4606d2f | ||
|
|
0767d64344 | ||
|
|
76e64ff2ea | ||
|
|
b0fb351419 | ||
|
|
e7fd07dd91 | ||
|
|
faf999211b | ||
|
|
585ed84283 | ||
|
|
d061cb4651 | ||
|
|
059bb2c151 | ||
|
|
b904ea54cc | ||
|
|
dcba8b4064 | ||
|
|
633436706f | ||
|
|
4092eba274 | ||
|
|
064e1c48ba | ||
|
|
462bb67709 | ||
|
|
b424d452d0 | ||
|
|
80af359232 | ||
|
|
ccb4601f3a | ||
|
|
5d6f998c52 | ||
|
|
6b842a7670 | ||
|
|
45951d2cbb | ||
|
|
d604acb78a | ||
|
|
37405c3249 | ||
|
|
268c61a69c | ||
|
|
b5429624c2 | ||
|
|
5f7597e754 | ||
|
|
62d7798270 | ||
|
|
4086bbe562 | ||
|
|
60c9339685 | ||
|
|
d3f8de4c04 | ||
|
|
0843745be9 | ||
|
|
d4d69ed0cd | ||
|
|
0493a33f59 | ||
|
|
8bc71e9161 | ||
|
|
a5a1c4d50d | ||
|
|
c879cb0f2f | ||
|
|
59004d77ed | ||
|
|
c2cfbd1e8b | ||
|
|
a17c5fb596 | ||
|
|
c6324ff45a | ||
|
|
74c2486a2c | ||
|
|
ac5dce9014 | ||
|
|
19ae300eb8 | ||
|
|
e429cc0bd8 | ||
|
|
d58cf6ec71 | ||
|
|
143b2c9c02 | ||
|
|
f977248086 | ||
|
|
569d464d36 | ||
|
|
7795476af1 | ||
|
|
137e705db7 | ||
|
|
302797ba41 | ||
|
|
40db754168 | ||
|
|
5c3268c9af | ||
|
|
dd86f543fc | ||
|
|
c46a970595 | ||
|
|
8bb5b1607e | ||
|
|
cc9726c641 | ||
|
|
a574a74042 | ||
|
|
0c3967aa32 | ||
|
|
af454a32dc | ||
|
|
d38d18ec25 | ||
|
|
577f04653d | ||
|
|
8ebf088360 | ||
|
|
4e923221ce | ||
|
|
370c26a6c9 | ||
|
|
a3fa9b73b8 | ||
|
|
483e7f9bdf | ||
|
|
ae2e7a3f0b | ||
|
|
59785f6762 | ||
|
|
806f3f6ae2 | ||
|
|
1c772d5ff2 | ||
|
|
8103febc62 | ||
|
|
8b18b962a3 | ||
|
|
199e598351 | ||
|
|
e55e3c05eb | ||
|
|
bc1b66250f | ||
|
|
dfba9f7608 | ||
|
|
c8ba27fd07 | ||
|
|
9daf81f16e | ||
|
|
b943955dbf | ||
|
|
643023d98f | ||
|
|
af53c790cc | ||
|
|
6aa70b6541 | ||
|
|
5f8a4c4d62 | ||
|
|
eda952ab08 | ||
|
|
b80ea43e25 | ||
|
|
c310bc5f83 | ||
|
|
eab68688dc | ||
|
|
5183e32887 | ||
|
|
e2f469a7cd | ||
|
|
33a5c2495d | ||
|
|
66b9f6fb2b | ||
|
|
a9ca72ab8e | ||
|
|
1a8b5e04a9 | ||
|
|
2d7cefe782 | ||
|
|
650c9d3452 | ||
|
|
4ebd1bd12c | ||
|
|
dbaa8c83b6 | ||
|
|
fb9130e85a | ||
|
|
615f8443fe | ||
|
|
fc706daf60 | ||
|
|
6cd487db81 | ||
|
|
e3e99cc906 | ||
|
|
95b1b05cbe | ||
|
|
755c820724 | ||
|
|
b4330a48b1 | ||
|
|
a81da8d864 | ||
|
|
4e27113494 | ||
|
|
be2e606fbd | ||
|
|
9d93605e18 | ||
|
|
1f1e291385 | ||
|
|
db39044ef6 | ||
|
|
fab5cf912f | ||
|
|
9f52b56aa8 | ||
|
|
4f8925abe7 | ||
|
|
8eb97549e1 | ||
|
|
e60ad4a090 | ||
|
|
6ced4e25de | ||
|
|
2207c27cb4 | ||
|
|
c4d97ad392 | ||
|
|
1b751261ce | ||
|
|
c7dcaf1259 | ||
|
|
d0779fc8fb | ||
|
|
99342d642f | ||
|
|
0c7224af95 | ||
|
|
36138f4901 | ||
|
|
83e874a165 | ||
|
|
8eefa41a4d | ||
|
|
57a902f36a | ||
|
|
07fd1ae66b | ||
|
|
a456528be8 | ||
|
|
6030ea51e4 | ||
|
|
2485257424 | ||
|
|
26ac59fd1d | ||
|
|
7860ad5268 | ||
|
|
9fdce5d069 | ||
|
|
d246e20764 | ||
|
|
121159c089 | ||
|
|
8b0b51a166 | ||
|
|
29b4da7737 | ||
|
|
b81f0a2c42 | ||
|
|
ad7dfa63ab | ||
|
|
35ca51fe88 | ||
|
|
d6ab394efd | ||
|
|
d29ba1f80e | ||
|
|
6a912bf104 | ||
|
|
c38833179b | ||
|
|
565798d617 | ||
|
|
0f7a2cad8d | ||
|
|
5ccba5d7cc | ||
|
|
2cc2ec160e | ||
|
|
a95ccd09a2 | ||
|
|
e199a3d8f7 | ||
|
|
fec0f56d0b | ||
|
|
fe809ea90d | ||
|
|
f880dc6d6f | ||
|
|
3c9674453f | ||
|
|
22f4980a21 | ||
|
|
abbcde665c | ||
|
|
c9c9415154 | ||
|
|
3997a394d9 | ||
|
|
e0b85397c8 | ||
|
|
e554cd86c3 | ||
|
|
38692f97fe | ||
|
|
7e5680a0d8 | ||
|
|
d51f6d4376 | ||
|
|
a9a9636d1e | ||
|
|
32030e2ed9 | ||
|
|
f9d8b551dc | ||
|
|
2c7960102c | ||
|
|
1a0be6f0ad | ||
|
|
6481cbb172 | ||
|
|
6e30032278 | ||
|
|
4fde4ecbaf | ||
|
|
40c1d27445 | ||
|
|
97f0499f43 | ||
|
|
c3a5f91ed0 | ||
|
|
258e4413b1 | ||
|
|
a62a75369e | ||
|
|
ba072adcb9 | ||
|
|
ca25259900 | ||
|
|
90373d78b9 | ||
|
|
dc23ef10b6 | ||
|
|
3c7a13d81f | ||
|
|
20755cfc15 | ||
|
|
df4c16ecb4 | ||
|
|
f0e8bdcdaf | ||
|
|
f85c41b14f | ||
|
|
75a1dd25cd | ||
|
|
a1ef9efc80 | ||
|
|
87dd5fe2c0 | ||
|
|
5fb9c84e14 | ||
|
|
d138f5f5e4 | ||
|
|
3ddedc021a | ||
|
|
a22adc77eb | ||
|
|
a3ff3adc39 | ||
|
|
2dcb9d0611 | ||
|
|
a6cb4b6317 | ||
|
|
2f917312f1 | ||
|
|
d1f8081d1c | ||
|
|
63671a1479 | ||
|
|
d7ca2aba2a | ||
|
|
2c4dd63f77 | ||
|
|
06e4f1b682 | ||
|
|
825de5d2e3 | ||
|
|
8f87f43e22 | ||
|
|
c30e096a54 | ||
|
|
3405c4d03c | ||
|
|
09b18cf6f5 | ||
|
|
fcedf169fb | ||
|
|
14655a43c8 | ||
|
|
8c3cab61c7 | ||
|
|
6296bf3f8b | ||
|
|
c18a3f9042 | ||
|
|
f6c1e5220a | ||
|
|
d740406daf | ||
|
|
7026e529c7 | ||
|
|
e80886e9be | ||
|
|
6e02b944f7 | ||
|
|
bb129a782b | ||
|
|
d508822f9a | ||
|
|
6913fee89a | ||
|
|
074161f9c1 | ||
|
|
2b0f16757a | ||
|
|
7b289bcee6 | ||
|
|
8dcd715ede | ||
|
|
dcca61c0bc | ||
|
|
0f44c57d08 | ||
|
|
efb187f26f | ||
|
|
c101052a7f | ||
|
|
51a1ee06e4 | ||
|
|
8a0555f8ef | ||
|
|
55f692ba9c | ||
|
|
3a265c1af9 | ||
|
|
c43928a8e4 | ||
|
|
c6cf4e18b8 | ||
|
|
9e664b5d27 | ||
|
|
3b6faa8531 | ||
|
|
e3982fae38 | ||
|
|
83ac0fbd94 | ||
|
|
46fbc5414a | ||
|
|
43b28caa94 | ||
|
|
4ea7d0849b | ||
|
|
5b9e4f0584 | ||
|
|
06c1959e78 | ||
|
|
0cd078bae6 | ||
|
|
7ad01b2b48 | ||
|
|
8c6b764a4c | ||
|
|
050f750563 | ||
|
|
4d72eefffc | ||
|
|
b6ac87c220 | ||
|
|
6b908bf39f | ||
|
|
f87d8762eb | ||
|
|
c54fa3731f | ||
|
|
4d0c289287 | ||
|
|
52bb0dcfcf | ||
|
|
98953c2e14 | ||
|
|
9ae8ba8a29 | ||
|
|
1a7f49d2f0 | ||
|
|
70c6d3f67e | ||
|
|
b155380a06 | ||
|
|
cd60df52af | ||
|
|
6820704c91 | ||
|
|
55341f4436 | ||
|
|
c9a96c9f79 | ||
|
|
7e0e85bdda | ||
|
|
d1a0398fdb | ||
|
|
67f429c41d | ||
|
|
632263568e | ||
|
|
bf39d88d11 | ||
|
|
07d675350f | ||
|
|
39cde6fc95 | ||
|
|
1381c2ca79 | ||
|
|
89d4e8a0e0 | ||
|
|
a8df5d587c | ||
|
|
e2173df4aa | ||
|
|
e851250da6 | ||
|
|
c69d9a1128 | ||
|
|
f4652fbbf0 | ||
|
|
3ee395f9b5 | ||
|
|
e4cbf04592 | ||
|
|
6bb7f07d2d | ||
|
|
51bd975820 | ||
|
|
294cff3fd4 | ||
|
|
a6e0785b84 | ||
|
|
302b317b89 | ||
|
|
8facb3b3a7 | ||
|
|
b5622bee3a | ||
|
|
3f74da0e73 | ||
|
|
68b92a7f5d | ||
|
|
8bac958994 | ||
|
|
5287e2ebf4 | ||
|
|
284588f9b4 | ||
|
|
16c7eb4135 | ||
|
|
9bcef4b875 | ||
|
|
f237a11f4f | ||
|
|
13a474c4e9 | ||
|
|
fe0b2436b8 | ||
|
|
808527b5d0 | ||
|
|
f71e22768c | ||
|
|
b025dfcf58 | ||
|
|
f205ec8359 | ||
|
|
f50cee2ac7 | ||
|
|
3be9773c4f | ||
|
|
2fd3b18d39 | ||
|
|
024bee1a6f | ||
|
|
5c1094adb9 | ||
|
|
14bc162ca6 | ||
|
|
1a6bada94c | ||
|
|
eda535a942 | ||
|
|
1e1c9cb0dc | ||
|
|
3dc0005032 | ||
|
|
6d0bf9b39f | ||
|
|
2f5d9a6f90 | ||
|
|
783618b89c | ||
|
|
4f2f6f8575 | ||
|
|
59aca30267 | ||
|
|
605e691bff | ||
|
|
09ec276a85 | ||
|
|
590b19a1b1 | ||
|
|
be5e1a4ded | ||
|
|
8650de0c0c | ||
|
|
95a039aaaa | ||
|
|
f1fdb9bbc8 | ||
|
|
44e76bea23 | ||
|
|
a898e2a534 | ||
|
|
681435e0b4 | ||
|
|
d2eace00c9 | ||
|
|
3300587c6b | ||
|
|
878bd87328 | ||
|
|
ff23666d56 | ||
|
|
f4fade3d26 | ||
|
|
16c3e0ddac | ||
|
|
0d216c2d82 | ||
|
|
a1fb5b1153 | ||
|
|
e97326845c | ||
|
|
71a6d791c2 | ||
|
|
5ae2cac088 | ||
|
|
31fab8cdae | ||
|
|
5bfec84432 | ||
|
|
caa4a8e228 | ||
|
|
bdcc2e1790 | ||
|
|
749f21e482 | ||
|
|
1cc75362d6 | ||
|
|
a2adc61c6f | ||
|
|
c7208bf1ff | ||
|
|
db143bb654 | ||
|
|
8b043038b8 | ||
|
|
5130b41f5b | ||
|
|
81bb14e181 | ||
|
|
e93ab45dc3 | ||
|
|
060f141b21 | ||
|
|
6ca591ab75 | ||
|
|
bc1049f5ae | ||
|
|
05568496c1 | ||
|
|
ab9ebb9d0d | ||
|
|
ab197ef51e | ||
|
|
7fc5f46bbb | ||
|
|
969af1567a | ||
|
|
7a10b64cf7 | ||
|
|
f6db678b20 | ||
|
|
97290b2442 | ||
|
|
b8504ed2a9 | ||
|
|
497911d6c0 | ||
|
|
4d96d0a6c6 | ||
|
|
9b58b6642e | ||
|
|
45f651ab00 | ||
|
|
400fe31061 | ||
|
|
4b6ab0389b | ||
|
|
baf7656d2f | ||
|
|
382db59cd0 | ||
|
|
2bbf49b2f5 | ||
|
|
6a6ae8ae46 | ||
|
|
03fa148e81 | ||
|
|
ea3203dbab | ||
|
|
a81ace2ccb | ||
|
|
a7da06998e | ||
|
|
5e5e3e0588 | ||
|
|
bc369fb1ab | ||
|
|
bb6bccb782 | ||
|
|
1fe59e41ea | ||
|
|
0d1f1d09f0 | ||
|
|
13f36e0416 | ||
|
|
e3f72ebae2 | ||
|
|
98f45695db | ||
|
|
3cb95b4d2d | ||
|
|
892aea138e | ||
|
|
045f6c1bce | ||
|
|
1d4261a997 | ||
|
|
da80bced53 | ||
|
|
1d687ac734 | ||
|
|
bef7a12964 | ||
|
|
14ff078b85 | ||
|
|
cd940bd797 | ||
|
|
093809eac6 | ||
|
|
c56f72794e | ||
|
|
9375e99f92 | ||
|
|
b66eeaf2f7 | ||
|
|
c6855e01a9 | ||
|
|
7f975a37f9 | ||
|
|
41cfa5f3d0 | ||
|
|
9c45206c28 | ||
|
|
308aa42b67 | ||
|
|
5174d14d5c | ||
|
|
6fe338e563 | ||
|
|
266d896871 | ||
|
|
7e85ae7bd2 | ||
|
|
9a284a3da4 | ||
|
|
871f0e26df | ||
|
|
e56885f4c9 | ||
|
|
149f4b4607 | ||
|
|
80750f730f | ||
|
|
253f6ee1d9 | ||
|
|
bac149e824 | ||
|
|
3ec34448fa | ||
|
|
919c4240fc | ||
|
|
44c2378f2a | ||
|
|
377b176260 | ||
|
|
d2a8ca7d89 | ||
|
|
d4faae187a | ||
|
|
5e52fae7c1 | ||
|
|
b974bf54dc | ||
|
|
4b6c91e827 | ||
|
|
51467dc4a3 | ||
|
|
eb79a3edaa | ||
|
|
37eca782cc | ||
|
|
19666f2598 | ||
|
|
3436bddaea | ||
|
|
5cc6b0e3d3 | ||
|
|
2b21e22e97 | ||
|
|
57df945738 | ||
|
|
e2e474c59d | ||
|
|
4c19dc22d7 | ||
|
|
ef44b4ccac | ||
|
|
8ee2f2657a | ||
|
|
f635c8715c | ||
|
|
3ceeb72ac6 | ||
|
|
e0b8938fef | ||
|
|
811ca05916 | ||
|
|
df9bbd7ab3 | ||
|
|
339e331f1d | ||
|
|
283e67b57e | ||
|
|
6c1fb9ffd0 | ||
|
|
c3fe192243 | ||
|
|
1ebcbd92e2 | ||
|
|
3060578e3b | ||
|
|
b8715bfee6 | ||
|
|
7fe9231e64 | ||
|
|
9289af0132 | ||
|
|
1f7722088d | ||
|
|
e548877ead | ||
|
|
21391c8d2f | ||
|
|
99551dd1ec | ||
|
|
b5a26936e8 | ||
|
|
cf28136003 | ||
|
|
349236c932 | ||
|
|
0ce6fad14e | ||
|
|
0a9e2baef1 | ||
|
|
da562ad74c | ||
|
|
d45dc17f25 | ||
|
|
7f1aefa09b | ||
|
|
2162054659 | ||
|
|
0ff3ca8a12 | ||
|
|
47c8a0e0b8 | ||
|
|
2a347226df | ||
|
|
962452d6d1 | ||
|
|
2df165c49e | ||
|
|
fc3a634e22 | ||
|
|
01a9141780 | ||
|
|
f783b9ec0d | ||
|
|
b745a51f30 | ||
|
|
02332d78f3 | ||
|
|
183c780698 | ||
|
|
406c8e0303 | ||
|
|
6778c8e905 | ||
|
|
3a94daeaf8 | ||
|
|
e5c64db280 | ||
|
|
d3700dfd70 | ||
|
|
975b45dbfe | ||
|
|
a49b07975c | ||
|
|
5e57ab95ce | ||
|
|
9c43fa9161 | ||
|
|
9b286ecbfd | ||
|
|
b7e9569ccb | ||
|
|
e922131422 | ||
|
|
34813ef32c | ||
|
|
e899f1d31c | ||
|
|
d1bfeee334 | ||
|
|
9ea1f7d53e | ||
|
|
f40bc773d2 | ||
|
|
5d0a6630b9 | ||
|
|
114b81c9a4 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/share/man/man[1-8]/*.[1-8] linguist-generated
|
||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
17
.github/workflows/ci.yml
vendored
Normal file
17
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: CI
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install bats
|
||||
run: git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git bats
|
||||
- name: Run tests
|
||||
run: PATH="./bats/bin:$PATH" test/run
|
||||
29
.github/workflows/lint.yml
vendored
Normal file
29
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
|
||||
name: Lint
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Repository checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Differential ShellCheck
|
||||
uses: redhat-plumbers-in-action/differential-shellcheck@v5
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
16
.github/workflows/release.yml
vendored
Normal file
16
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags: 'v*'
|
||||
|
||||
jobs:
|
||||
homebrew:
|
||||
name: Bump Homebrew formula
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: mislav/bump-homebrew-formula-action@v3.2
|
||||
if: "!contains(github.ref, '-')" # skip prereleases
|
||||
with:
|
||||
formula-name: rbenv
|
||||
env:
|
||||
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -2,3 +2,9 @@
|
||||
/shims
|
||||
/version
|
||||
/versions
|
||||
/sources
|
||||
/cache
|
||||
/libexec/*.dylib
|
||||
/src/Makefile
|
||||
/src/*.o
|
||||
/gems
|
||||
|
||||
80
CODE_OF_CONDUCT.md
Normal file
80
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting one of the project maintainers listed below. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Project Maintainers
|
||||
|
||||
* Sam Stephenson <<sstephenson@gmail.com>>
|
||||
* Mislav Marohnić <<mislav.marohnic@gmail.com>>
|
||||
* Erik Michaels-Ober <<sferik@gmail.com>>
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2011 Sam Stephenson
|
||||
Copyright (c) 2013 Sam Stephenson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
4
Makefile
Normal file
4
Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
release_version := $(shell GIT_CEILING_DIRECTORIES=$(PWD) bin/rbenv --version | cut -d' ' -f2)
|
||||
|
||||
share/man/man1/rbenv.1: share/man/man1/rbenv.1.adoc
|
||||
asciidoctor -b manpage -a version=$(release_version:v%=%) $<
|
||||
582
README.md
582
README.md
@@ -1,263 +1,186 @@
|
||||
# Simple Ruby Version Management: rbenv
|
||||
|
||||
rbenv lets you easily switch between multiple versions of Ruby. It's
|
||||
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
||||
tools that do one thing well.
|
||||
|
||||
<img src="http://i.sstephenson.us/rbenv2.png" width="894" height="464">
|
||||
|
||||
### rbenv _does…_
|
||||
|
||||
* Let you **change the global Ruby version** on a per-user basis.
|
||||
* Provide support for **per-project Ruby versions**.
|
||||
* Allow you to **override the Ruby version** with an environment
|
||||
variable.
|
||||
# Seamlessly manage your app’s Ruby environment with rbenv.
|
||||
|
||||
### In contrast with rvm, rbenv _does not…_
|
||||
|
||||
* **Need to be loaded into your shell.** Instead, rbenv's shim
|
||||
approach works by adding a directory to your `$PATH`.
|
||||
* **Override shell commands like `cd`.** That's dangerous and
|
||||
error-prone.
|
||||
* **Have a configuration file.** There's nothing to configure except
|
||||
which version of Ruby you want to use.
|
||||
* **Install Ruby.** You can build and install Ruby yourself, or use
|
||||
[ruby-build](https://github.com/sstephenson/ruby-build) to
|
||||
automate the process.
|
||||
* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
|
||||
way to manage application dependencies. If you have projects that
|
||||
are not yet using Bundler you can install the
|
||||
[rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
|
||||
* **Require changes to Ruby libraries for compatibility.** The
|
||||
simplicity of rbenv means as long as it's in your `$PATH`,
|
||||
[nothing](https://rvm.beginrescueend.com/integration/bundler/)
|
||||
[else](https://rvm.beginrescueend.com/integration/capistrano/)
|
||||
needs to know about it.
|
||||
* **Prompt you with warnings when you switch to a project.** Instead
|
||||
of executing arbitrary code, rbenv reads just the version name
|
||||
from each project. There's nothing to "trust."
|
||||
rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version.
|
||||
|
||||
## Table of Contents
|
||||
## How It Works
|
||||
|
||||
* [1 How It Works](#section_1)
|
||||
* [2 Installation](#section_2)
|
||||
* [2.1 Basic GitHub Checkout](#section_2.1)
|
||||
* [2.1.1 Upgrading](#section_2.1.1)
|
||||
* [2.2 Homebrew on Mac OS X](#section_2.2)
|
||||
* [2.3 Neckbeard Configuration](#section_2.3)
|
||||
* [3 Usage](#section_3)
|
||||
* [3.1 rbenv global](#section_3.1)
|
||||
* [3.2 rbenv local](#section_3.2)
|
||||
* [3.3 rbenv shell](#section_3.3)
|
||||
* [3.4 rbenv versions](#section_3.4)
|
||||
* [3.5 rbenv version](#section_3.5)
|
||||
* [3.6 rbenv rehash](#section_3.6)
|
||||
* [3.7 rbenv which](#section_3.7)
|
||||
* [3.8 rbenv whence](#section_3.8)
|
||||
* [4 Development](#section_4)
|
||||
* [4.1 Version History](#section_4.1)
|
||||
* [4.2 License](#section_4.2)
|
||||
After rbenv injects itself into your PATH at installation time, any invocation of `ruby`, `gem`, `bundler`, or other Ruby-related executable will first activate rbenv. Then, rbenv scans the current project directory for a file named `.ruby-version`. If found, that file determines the version of Ruby that should be used within that directory. Finally, rbenv looks up that Ruby version among those installed under `~/.rbenv/versions/`.
|
||||
|
||||
## <a name="section_1"></a> 1 How It Works
|
||||
You can choose the Ruby version for your project with, for example:
|
||||
```sh
|
||||
cd myproject
|
||||
# choose Ruby version 3.1.2:
|
||||
rbenv local 3.1.2
|
||||
```
|
||||
|
||||
rbenv operates on the per-user directory `~/.rbenv`. Version names in
|
||||
rbenv correspond to subdirectories of `~/.rbenv/versions`. For
|
||||
example, you might have `~/.rbenv/versions/1.8.7-p354` and
|
||||
`~/.rbenv/versions/1.9.3-rc1`.
|
||||
Doing so will create or update the `.ruby-version` file in the current directory with the version that you've chosen. A different project of yours that is another directory might be using a different version of Ruby altogether—rbenv will seamlessly transition from one Ruby version to another when you switch projects.
|
||||
|
||||
Each version is a working tree with its own binaries, like
|
||||
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
|
||||
`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
|
||||
for every such binary across all installed versions of Ruby.
|
||||
Finally, almost every aspect of rbenv's mechanism is [customizable via plugins][plugins] written in bash.
|
||||
|
||||
These shims are simple wrapper scripts that live in `~/.rbenv/shims`
|
||||
and detect which Ruby version you want to use. They insert the
|
||||
directory for the selected version at the beginning of your `$PATH`
|
||||
and then execute the corresponding binary.
|
||||
The simplicity of rbenv has its benefits, but also some downsides. See the [comparison of version managers][alternatives] for more details and some alternatives.
|
||||
|
||||
Because of the simplicity of the shim approach, all you need to use
|
||||
rbenv is `~/.rbenv/shims` in your `$PATH`.
|
||||
## Installation
|
||||
|
||||
## <a name="section_2"></a> 2 Installation
|
||||
On systems with Homebrew package manager, the “Using Package Managers” method is recommended. On other systems, “Basic Git Checkout” might be the easiest way of ensuring that you are always installing the latest version of rbenv.
|
||||
|
||||
**Compatibility note**: rbenv is _incompatible_ with rvm. Things will
|
||||
appear to work until you try to install a gem. The problem is that
|
||||
rvm actually overrides the `gem` command with a shell function!
|
||||
Please remove any references to rvm before using rbenv.
|
||||
### Using Package Managers
|
||||
|
||||
### <a name="section_2.1"></a> 2.1 Basic GitHub Checkout
|
||||
1. Install rbenv using one of the following approaches.
|
||||
|
||||
This will get you going with the latest version of rbenv and make it
|
||||
easy to fork and contribute any changes back upstream.
|
||||
#### Homebrew
|
||||
|
||||
On macOS or Linux, we recommend installing rbenv with [Homebrew](https://brew.sh).
|
||||
|
||||
```sh
|
||||
brew install rbenv
|
||||
```
|
||||
|
||||
#### Debian, Ubuntu, and their derivatives
|
||||
|
||||
> [!CAUTION]
|
||||
> The version of rbenv that is packaged and maintained in official
|
||||
Debian and Ubuntu repositories is _out of date_. To install the latest
|
||||
version, it is recommended to [install rbenv using git](#basic-git-checkout).
|
||||
|
||||
```sh
|
||||
sudo apt install rbenv
|
||||
```
|
||||
|
||||
#### Arch Linux and its derivatives
|
||||
|
||||
Archlinux has an [AUR Package](https://aur.archlinux.org/packages/rbenv/) for
|
||||
rbenv and you can install it from the AUR using the instructions from this
|
||||
[wiki page](https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_and_upgrading_packages).
|
||||
|
||||
1. Check out rbenv into `~/.rbenv`.
|
||||
#### Fedora
|
||||
|
||||
$ cd
|
||||
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
|
||||
Fedora has an [official package](https://packages.fedoraproject.org/pkgs/rbenv/rbenv/) which you can install:
|
||||
|
||||
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
|
||||
command-line utility.
|
||||
```sh
|
||||
sudo dnf install rbenv
|
||||
```
|
||||
|
||||
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
||||
2. Set up your shell to load rbenv.
|
||||
|
||||
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||
```sh
|
||||
rbenv init
|
||||
```
|
||||
|
||||
3. Add rbenv init to your shell to enable shims and autocompletion.
|
||||
3. Close your Terminal window and open a new one so your changes take effect.
|
||||
|
||||
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
||||
That's it! You are now ready to [install some Ruby versions](#installing-ruby-versions).
|
||||
|
||||
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||
### Basic Git Checkout
|
||||
|
||||
4. Restart your shell so the path changes take effect. You can now
|
||||
begin using rbenv.
|
||||
> [!NOTE]
|
||||
> For a more automated install, you can use [rbenv-installer](https://github.com/rbenv/rbenv-installer#rbenv-installer). If you do not want to execute scripts downloaded from a web URL or simply prefer a manual approach, follow the steps below.
|
||||
|
||||
$ exec $SHELL
|
||||
This will get you going with the latest version of rbenv without needing a system-wide install.
|
||||
|
||||
5. Install Ruby versions into `~/.rbenv/versions`. For example, to
|
||||
install Ruby 1.9.2-p290, download and unpack the source, then run:
|
||||
1. Clone rbenv into `~/.rbenv`.
|
||||
|
||||
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
|
||||
$ make
|
||||
$ make install
|
||||
```sh
|
||||
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
|
||||
```
|
||||
|
||||
The [ruby-build](https://github.com/sstephenson/ruby-build) project
|
||||
provides an `rbenv install` command that simplifies the process of
|
||||
installing new Ruby versions to:
|
||||
2. Set up your shell to load rbenv.
|
||||
|
||||
$ rbenv install 1.9.2-p290
|
||||
```sh
|
||||
~/.rbenv/bin/rbenv init
|
||||
```
|
||||
|
||||
6. Rebuild the shim binaries. You should do this any time you install
|
||||
a new Ruby binary (for example, when installing a new Ruby version,
|
||||
or when installing a gem that provides a binary).
|
||||
If you are curious, see here to [understand what `init` does](#how-rbenv-hooks-into-your-shell).
|
||||
|
||||
$ rbenv rehash
|
||||
3. Restart your shell so that these changes take effect. (Opening a new terminal tab will usually do it.)
|
||||
|
||||
#### <a name="section_2.1.1"></a> 2.1.1 Upgrading
|
||||
#### Shell completions
|
||||
|
||||
If you've installed rbenv using the instructions above, you can
|
||||
upgrade your installation at any time using git.
|
||||
When _manually_ installing rbenv, it might be useful to note how completion scripts for various shells work. Completion scripts help with typing rbenv commands by expanding partially entered rbenv command names and option flags; typically this is invoked by pressing <kbd>Tab</kbd> key in an interactive shell.
|
||||
|
||||
To upgrade to the latest development version of rbenv, use `git pull`:
|
||||
- The **bash** completion script for rbenv ships with the project and gets [loaded by the `rbenv init` mechanism](#how-rbenv-hooks-into-your-shell).
|
||||
|
||||
$ cd ~/.rbenv
|
||||
$ git pull
|
||||
- The **zsh** completion script ships with the project, but needs to be added to FPATH in zsh before it can be discovered by the shell. One way to do this would be to edit `~/.zshrc`:
|
||||
|
||||
To upgrade to a specific release of rbenv, check out the corresponding
|
||||
tag:
|
||||
```sh
|
||||
# assuming that rbenv was installed to `~/.rbenv`
|
||||
FPATH=~/.rbenv/completions:"$FPATH"
|
||||
|
||||
$ cd ~/.rbenv
|
||||
$ git fetch
|
||||
$ git tag
|
||||
v0.1.0
|
||||
v0.1.1
|
||||
v0.1.2
|
||||
v0.2.0
|
||||
$ git checkout v0.2.0
|
||||
autoload -U compinit
|
||||
compinit
|
||||
```
|
||||
|
||||
### <a name="section_2.2"></a> 2.2 Homebrew on Mac OS X
|
||||
- The **fish** completion script for rbenv ships with the fish shell itself and is not maintained by the rbenv project.
|
||||
|
||||
You can also install rbenv using the
|
||||
[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
|
||||
X.
|
||||
### Installing Ruby versions
|
||||
|
||||
$ brew update
|
||||
$ brew install rbenv
|
||||
$ brew install ruby-build
|
||||
The `rbenv install` command does not ship with rbenv out-of-the-box, but is provided by the [ruby-build][] plugin.
|
||||
|
||||
The same commands can be used for upgrading.
|
||||
Before attempting to install Ruby, **check that [your build environment](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment) has the necessary tools and libraries**. Then:
|
||||
|
||||
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
|
||||
profile as stated in the caveats. You'll only ever have to do this
|
||||
once.
|
||||
```sh
|
||||
# list latest stable versions:
|
||||
rbenv install -l
|
||||
|
||||
### <a name="section_2.3"></a> 2.3 Neckbeard Configuration
|
||||
# list all local versions:
|
||||
rbenv install -L
|
||||
|
||||
Skip this section unless you must know what every line in your shell
|
||||
profile is doing.
|
||||
# install a Ruby version:
|
||||
rbenv install 3.1.2
|
||||
```
|
||||
|
||||
`rbenv init` is the only command that crosses the line of loading
|
||||
extra commands into your shell. Coming from rvm, some of you might be
|
||||
opposed to this idea. Here's what `rbenv init` actually does:
|
||||
For troubleshooting `BUILD FAILED` scenarios, check the [ruby-build Discussions section](https://github.com/rbenv/ruby-build/discussions/categories/build-failures).
|
||||
|
||||
1. Sets up your shims path. This is the only requirement for rbenv to
|
||||
function properly. You can do this by hand by prepending
|
||||
`~/.rbenv/shims` to your `$PATH`.
|
||||
> [!NOTE]
|
||||
> If the `rbenv install` command wasn't found, you can install ruby-build as a plugin:
|
||||
> ```sh
|
||||
> git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
|
||||
> ```
|
||||
|
||||
2. Installs autocompletion. This is entirely optional but pretty
|
||||
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
|
||||
up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
|
||||
users.
|
||||
Set a Ruby version to finish installation and start using Ruby:
|
||||
```sh
|
||||
rbenv global 3.1.2 # set the default Ruby version for this machine
|
||||
# or:
|
||||
rbenv local 3.1.2 # set the Ruby version for this directory
|
||||
```
|
||||
|
||||
3. Rehashes shims. From time to time you'll need to rebuild your
|
||||
shim files. Doing this on init makes sure everything is up to
|
||||
date. You can always run `rbenv rehash` manually.
|
||||
Alternatively to the `rbenv install` command, you can download and compile Ruby manually as a subdirectory of `~/.rbenv/versions`. An entry in that directory can also be a symlink to a Ruby version installed elsewhere on the filesystem.
|
||||
|
||||
4. Installs the sh dispatcher. This bit is also optional, but allows
|
||||
rbenv and plugins to change variables in your current shell, making
|
||||
commands like `rbenv shell` possible. The sh dispatcher doesn't do
|
||||
anything crazy like override `cd` or hack your shell prompt, but if
|
||||
for some reason you need `rbenv` to be a real script rather than a
|
||||
shell function, you can safely skip it.
|
||||
#### Installing Ruby gems
|
||||
|
||||
Run `rbenv init -` for yourself to see exactly what happens under the
|
||||
hood.
|
||||
Select a Ruby version for your project using `rbenv local 3.1.2`, for example. Then, proceed to install gems as you normally would:
|
||||
|
||||
## <a name="section_3"></a> 3 Usage
|
||||
```sh
|
||||
gem install bundler
|
||||
```
|
||||
|
||||
Like `git`, the `rbenv` command delegates to subcommands based on its
|
||||
first argument. The most common subcommands are:
|
||||
> [!NOTE]
|
||||
> You _should not use sudo_ to install gems. Typically, the Ruby versions will be installed under your home directory and thus writeable by your user. If you get the “you don't have write permissions” error when installing gems, it's likely that your "system" Ruby version is still a global default. Change that with `rbenv global <version>` and try again.
|
||||
|
||||
### <a name="section_3.1"></a> 3.1 rbenv global
|
||||
Check the location where gems are being installed with `gem env`:
|
||||
|
||||
Sets the global version of Ruby to be used in all shells by writing
|
||||
the version name to the `~/.rbenv/version` file. This version can be
|
||||
overridden by a per-project `.rbenv-version` file, or by setting the
|
||||
`RBENV_VERSION` environment variable.
|
||||
```sh
|
||||
gem env home
|
||||
# => ~/.rbenv/versions/<version>/lib/ruby/gems/...
|
||||
```
|
||||
|
||||
$ rbenv global 1.9.2-p290
|
||||
#### Uninstalling Ruby versions
|
||||
|
||||
The special version name `system` tells rbenv to use the system Ruby
|
||||
(detected by searching your `$PATH`).
|
||||
As time goes on, Ruby versions you install will accumulate in your
|
||||
`~/.rbenv/versions` directory.
|
||||
|
||||
When run without a version number, `rbenv global` reports the
|
||||
currently configured global version.
|
||||
To remove old Ruby versions, simply `rm -rf` the directory of the
|
||||
version you want to remove. You can find the directory of a particular
|
||||
Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
|
||||
2.7.0`.
|
||||
|
||||
### <a name="section_3.2"></a> 3.2 rbenv local
|
||||
The [ruby-build][] plugin provides an `rbenv uninstall` command to
|
||||
automate the removal process.
|
||||
|
||||
Sets a local per-project Ruby version by writing the version name to
|
||||
an `.rbenv-version` file in the current directory. This version
|
||||
overrides the global, and can be overridden itself by setting the
|
||||
`RBENV_VERSION` environment variable or with the `rbenv shell`
|
||||
command.
|
||||
## Command Reference
|
||||
|
||||
$ rbenv local rbx-1.2.4
|
||||
The main rbenv commands you need to know are:
|
||||
|
||||
When run without a version number, `rbenv local` reports the currently
|
||||
configured local version. You can also unset the local version:
|
||||
|
||||
$ rbenv local --unset
|
||||
|
||||
### <a name="section_3.3"></a> 3.3 rbenv shell
|
||||
|
||||
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
||||
environment variable in your shell. This version overrides both
|
||||
project-specific versions and the global version.
|
||||
|
||||
$ rbenv shell jruby-1.6.4
|
||||
|
||||
When run without a version number, `rbenv shell` reports the current
|
||||
value of `RBENV_VERSION`. You can also unset the shell version:
|
||||
|
||||
$ rbenv shell --unset
|
||||
|
||||
Note that you'll need rbenv's shell integration enabled (step 3 of
|
||||
the installation instructions) in order to use this command. If you
|
||||
prefer not to use shell integration, you may simply set the
|
||||
`RBENV_VERSION` variable yourself:
|
||||
|
||||
$ export RBENV_VERSION=jruby-1.6.4
|
||||
|
||||
### <a name="section_3.4"></a> 3.4 rbenv versions
|
||||
### rbenv versions
|
||||
|
||||
Lists all Ruby versions known to rbenv, and shows an asterisk next to
|
||||
the currently active version.
|
||||
@@ -265,150 +188,163 @@ the currently active version.
|
||||
$ rbenv versions
|
||||
1.8.7-p352
|
||||
1.9.2-p290
|
||||
* 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
|
||||
jruby-1.6.4
|
||||
* 1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
||||
jruby-1.7.1
|
||||
rbx-1.2.4
|
||||
ree-1.8.7-2011.03
|
||||
|
||||
### <a name="section_3.5"></a> 3.5 rbenv version
|
||||
### rbenv version
|
||||
|
||||
Displays the currently active Ruby version, along with information on
|
||||
how it was set.
|
||||
|
||||
$ rbenv version
|
||||
1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
|
||||
1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
||||
|
||||
### <a name="section_3.6"></a> 3.6 rbenv rehash
|
||||
### rbenv local
|
||||
|
||||
Installs shims for all Ruby binaries known to rbenv (i.e.,
|
||||
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
|
||||
version of Ruby, or install a gem that provides binaries.
|
||||
Sets a local application-specific Ruby version by writing the version
|
||||
name to a `.ruby-version` file in the current directory. This version
|
||||
overrides the global version, and can be overridden itself by setting
|
||||
the `RBENV_VERSION` environment variable or with the `rbenv shell`
|
||||
command.
|
||||
|
||||
$ rbenv rehash
|
||||
rbenv local 3.1.2
|
||||
|
||||
### <a name="section_3.7"></a> 3.7 rbenv which
|
||||
When run without a version number, `rbenv local` reports the currently
|
||||
configured local version. You can also unset the local version:
|
||||
|
||||
Displays the full path to the binary that rbenv will execute when you
|
||||
run the given command.
|
||||
rbenv local --unset
|
||||
|
||||
### rbenv global
|
||||
|
||||
Sets the global version of Ruby to be used in all shells by writing
|
||||
the version name to the `~/.rbenv/version` file. This version can be
|
||||
overridden by an application-specific `.ruby-version` file, or by
|
||||
setting the `RBENV_VERSION` environment variable.
|
||||
|
||||
rbenv global 3.1.2
|
||||
|
||||
The special version name `system` tells rbenv to use the system Ruby
|
||||
(detected by searching your `$PATH`).
|
||||
|
||||
When run without a version number, `rbenv global` reports the
|
||||
currently configured global version.
|
||||
|
||||
### rbenv shell
|
||||
|
||||
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
||||
environment variable in your shell. This version overrides
|
||||
application-specific versions and the global version.
|
||||
|
||||
rbenv shell jruby-1.7.1
|
||||
|
||||
When run without a version number, `rbenv shell` reports the current
|
||||
value of `RBENV_VERSION`. You can also unset the shell version:
|
||||
|
||||
rbenv shell --unset
|
||||
|
||||
Note that you'll need rbenv's shell integration enabled (step 3 of
|
||||
the installation instructions) in order to use this command. If you
|
||||
prefer not to use shell integration, you may simply set the
|
||||
`RBENV_VERSION` variable yourself:
|
||||
|
||||
export RBENV_VERSION=jruby-1.7.1
|
||||
|
||||
### rbenv rehash
|
||||
|
||||
Installs shims for all Ruby executables known to rbenv (`~/.rbenv/versions/*/bin/*`). Typically you do not need to run this command, as it will run automatically after installing gems.
|
||||
|
||||
rbenv rehash
|
||||
|
||||
### rbenv which
|
||||
|
||||
Displays the full path to the executable that rbenv will invoke when
|
||||
you run the given command.
|
||||
|
||||
$ rbenv which irb
|
||||
/Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
|
||||
/Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
|
||||
|
||||
### <a name="section_3.8"></a> 3.8 rbenv whence
|
||||
### rbenv whence
|
||||
|
||||
Lists all Ruby versions with the given command installed.
|
||||
Lists all Ruby versions that contain the specified executable name.
|
||||
|
||||
$ rbenv whence rackup
|
||||
1.9.3-rc1
|
||||
jruby-1.6.4
|
||||
1.9.3-p327
|
||||
jruby-1.7.1
|
||||
ree-1.8.7-2011.03
|
||||
|
||||
## <a name="section_4"></a> 4 Development
|
||||
## Environment variables
|
||||
|
||||
The rbenv source code is [hosted on
|
||||
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
|
||||
and easy to understand, even if you're not a shell hacker.
|
||||
You can affect how rbenv operates with the following settings:
|
||||
|
||||
name | default | description
|
||||
-----|---------|------------
|
||||
`RBENV_VERSION` | | Specifies the Ruby version to be used.<br>Also see [`rbenv shell`](#rbenv-shell)
|
||||
`RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.<br>Also see `rbenv root`
|
||||
`RBENV_DEBUG` | | Outputs debug information.<br>Also as: `rbenv --debug <subcommand>`
|
||||
`RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks.
|
||||
`RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files.
|
||||
|
||||
### How rbenv hooks into your shell
|
||||
|
||||
`rbenv init` is a helper command to hook rbenv into a shell. This helper is part of the recommended installation instructions, but optional, as an experienced user can set up the following tasks manually. The `rbenv init` command has two modes of operation:
|
||||
|
||||
1. `rbenv init`: made for humans, this command edits your shell initialization files on disk to add rbenv to shell startup. (Prior to rbenv 1.3.0, this mode only printed user instructions to the terminal, but did nothing else.)
|
||||
|
||||
2. `rbenv init -`: made for machines, this command outputs a shell script suitable to be eval'd by the user's shell.
|
||||
|
||||
When `rbenv init` is invoked from a bash shell, for example, it will add the following to the user's `~/.bashrc` or `~/.bash_profile`:
|
||||
|
||||
```sh
|
||||
# Added by `rbenv init` on <DATE>
|
||||
eval "$(rbenv init - --no-rehash bash)"
|
||||
```
|
||||
|
||||
You may add this line to your shell initialization files manually if you want to avoid running `rbenv init` as part of the setup process. Here is what the eval'd script does:
|
||||
|
||||
0. Adds `rbenv` executable to PATH if necessary.
|
||||
|
||||
1. Prepends `~/.rbenv/shims` directory to PATH. This is basically the only requirement for rbenv to function properly.
|
||||
|
||||
2. Installs bash shell completion for rbenv commands.
|
||||
|
||||
3. Regenerates rbenv shims. If this step slows down your shell startup, you can invoke `rbenv init -` with the `--no-rehash` flag.
|
||||
|
||||
4. Installs the "sh" dispatcher. This bit is also optional, but allows rbenv and plugins to change variables in your current shell, making commands like `rbenv shell` possible.
|
||||
|
||||
|
||||
### Uninstalling rbenv
|
||||
|
||||
The simplicity of rbenv makes it easy to temporarily disable it, or
|
||||
uninstall from the system.
|
||||
|
||||
1. To **disable** rbenv managing your Ruby versions, simply comment or remove the `rbenv init` line from your shell startup configuration. This will remove rbenv shims directory from PATH, and future invocations like `ruby` will execute the system Ruby version, bypassing rbenv completely.
|
||||
|
||||
While disabled, `rbenv` will still be accessible on the command line, but your Ruby apps won't be affected by version switching.
|
||||
|
||||
2. To completely **uninstall** rbenv, perform step (1) and then remove the rbenv root directory. This will **delete all Ruby versions** that were installed under `` `rbenv root`/versions/ ``:
|
||||
|
||||
rm -rf "$(rbenv root)"
|
||||
|
||||
If you've installed rbenv using a package manager, as a final step
|
||||
perform the rbenv package removal:
|
||||
- Homebrew: `brew uninstall rbenv`
|
||||
- Debian, Ubuntu, and their derivatives: `sudo apt purge rbenv`
|
||||
- Archlinux and its derivatives: `sudo pacman -R rbenv`
|
||||
|
||||
## Development
|
||||
|
||||
Tests are executed using [Bats](https://github.com/bats-core/bats-core):
|
||||
|
||||
$ bats test
|
||||
$ bats test/<file>.bats
|
||||
|
||||
Please feel free to submit pull requests and file bugs on the [issue
|
||||
tracker](https://github.com/sstephenson/rbenv/issues).
|
||||
tracker](https://github.com/rbenv/rbenv/issues).
|
||||
|
||||
### <a name="section_4.1"></a> 4.1 Version History
|
||||
|
||||
**0.3.0** (December 25, 2011)
|
||||
|
||||
* Added an `rbenv root` command which prints the value of
|
||||
`$RBENV_ROOT`, or the default root directory if it's unset.
|
||||
* Clarified Zsh installation instructions in the readme.
|
||||
* Removed some redundant code in `rbenv rehash`.
|
||||
* Fixed an issue with calling `readlink` for paths with spaces.
|
||||
* Changed Zsh initialization code to install completion hooks only for
|
||||
interactive shells.
|
||||
* Added preliminary support for ksh.
|
||||
* `rbenv rehash` creates or removes shims only when necessary instead
|
||||
of removing and re-creating all shims on each invocation.
|
||||
* Fixed that `RBENV_DIR`, when specified, would be incorrectly
|
||||
expanded to its parent directory.
|
||||
* Removed the deprecated `set-default` and `set-local` commands.
|
||||
* Added a `--no-rehash` option to `rbenv init` for skipping the
|
||||
automatic rehash when opening a new shell.
|
||||
|
||||
**0.2.1** (October 1, 2011)
|
||||
|
||||
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
||||
absolute path. This fixes an issue where Ruby scripts using the
|
||||
`ruby-local-exec` wrapper would go into an infinite loop when
|
||||
invoked with a relative path from the command line.
|
||||
|
||||
**0.2.0** (September 28, 2011)
|
||||
|
||||
* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
|
||||
to `rbenv local`. The `set-` commands are deprecated and will be
|
||||
removed in the next major release.
|
||||
* rbenv now uses `greadlink` on Solaris.
|
||||
* Added a `ruby-local-exec` command which can be used in shebangs in
|
||||
place of `#!/usr/bin/env ruby` to properly set the project-specific
|
||||
Ruby version regardless of current working directory.
|
||||
* Fixed an issue with `rbenv rehash` when no binaries are present.
|
||||
* Added support for `rbenv-sh-*` commands, which run inside the
|
||||
current shell instead of in a child process.
|
||||
* Added an `rbenv shell` command for conveniently setting the
|
||||
`$RBENV_VERSION` environment variable.
|
||||
* Added support for storing rbenv versions and shims in directories
|
||||
other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
|
||||
* Added support for debugging rbenv via `set -x` when the
|
||||
`$RBENV_DEBUG` environment variable is set.
|
||||
* Refactored the autocompletion system so that completions are now
|
||||
built-in to each command and shared between bash and Zsh.
|
||||
* Added support for plugin bundles in `~/.rbenv/plugins` as documented
|
||||
in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
|
||||
* Added `/usr/local/etc/rbenv.d` to the list of directories searched
|
||||
for rbenv hooks.
|
||||
* Added support for an `$RBENV_DIR` environment variable which
|
||||
defaults to the current working directory for specifying where rbenv
|
||||
searches for local version files.
|
||||
|
||||
**0.1.2** (August 16, 2011)
|
||||
|
||||
* Fixed rbenv to be more resilient against nonexistent entries in
|
||||
`$PATH`.
|
||||
* Made the `rbenv rehash` command operate atomically.
|
||||
* Modified the `rbenv init` script to automatically run `rbenv
|
||||
rehash` so that shims are recreated whenever a new shell is opened.
|
||||
* Added initial support for Zsh autocompletion.
|
||||
* Removed the dependency on egrep for reading version files.
|
||||
|
||||
**0.1.1** (August 14, 2011)
|
||||
|
||||
* Fixed a syntax error in the `rbenv help` command.
|
||||
* Removed `-e` from the shebang in favor of `set -e` at the top of
|
||||
each file for compatibility with operating systems that do not
|
||||
support more than one argument in the shebang.
|
||||
|
||||
**0.1.0** (August 11, 2011)
|
||||
|
||||
* Initial public release.
|
||||
|
||||
### <a name="section_4.2"></a> 4.2 License
|
||||
|
||||
(The MIT license)
|
||||
|
||||
Copyright (c) 2011 Sam Stephenson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
[ruby-build]: https://github.com/rbenv/ruby-build#readme
|
||||
[hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks
|
||||
[alternatives]: https://github.com/rbenv/rbenv/wiki/Comparison-of-version-managers
|
||||
[plugins]: https://github.com/rbenv/rbenv/wiki/Plugins
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# `ruby-local-exec` is a drop-in replacement for the standard Ruby
|
||||
# shebang line:
|
||||
#
|
||||
# #!/usr/bin/env ruby-local-exec
|
||||
#
|
||||
# Use it for scripts inside a project with an `.rbenv-version`
|
||||
# file. When you run the scripts, they'll use the project-specified
|
||||
# Ruby version, regardless of what directory they're run from. Useful
|
||||
# for e.g. running project tasks in cron scripts without needing to
|
||||
# `cd` into the project first.
|
||||
|
||||
set -e
|
||||
export RBENV_DIR="${1%/*}"
|
||||
exec ruby "$@"
|
||||
13
completions/_rbenv
Normal file
13
completions/_rbenv
Normal file
@@ -0,0 +1,13 @@
|
||||
#compdef rbenv
|
||||
|
||||
_rbenv() {
|
||||
local completions
|
||||
|
||||
if [ "${#words}" -eq 2 ]; then
|
||||
completions=(${(f)"$(rbenv help --complete-commands "${words[2]}")"})
|
||||
_describe 'rbenv commands' completions
|
||||
else
|
||||
completions="$(rbenv completions ${words[2,-2]})"
|
||||
compadd - "${(ps:\n:)completions}"
|
||||
fi
|
||||
}
|
||||
@@ -5,8 +5,10 @@ _rbenv() {
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") )
|
||||
else
|
||||
local command="${COMP_WORDS[1]}"
|
||||
local completions="$(rbenv completions "$command")"
|
||||
local words=("${COMP_WORDS[@]}")
|
||||
unset "words[0]"
|
||||
unset "words[$COMP_CWORD]"
|
||||
local completions=$(rbenv completions "${words[@]}")
|
||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
if [[ ! -o interactive ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
compctl -K _rbenv rbenv
|
||||
|
||||
_rbenv() {
|
||||
local word words completions
|
||||
read -cA words
|
||||
word="${words[2]}"
|
||||
|
||||
if [ "${#words}" -eq 2 ]; then
|
||||
completions="$(rbenv commands)"
|
||||
else
|
||||
completions="$(rbenv completions "${word}")"
|
||||
fi
|
||||
|
||||
reply=("${(ps:\n:)completions}")
|
||||
}
|
||||
395
doc/README.mdtoc
395
doc/README.mdtoc
@@ -1,395 +0,0 @@
|
||||
# Simple Ruby Version Management: rbenv
|
||||
|
||||
rbenv lets you easily switch between multiple versions of Ruby. It's
|
||||
simple, unobtrusive, and follows the UNIX tradition of single-purpose
|
||||
tools that do one thing well.
|
||||
|
||||
<img src="http://i.sstephenson.us/rbenv2.png" width="894" height="464">
|
||||
|
||||
### rbenv _does…_
|
||||
|
||||
* Let you **change the global Ruby version** on a per-user basis.
|
||||
* Provide support for **per-project Ruby versions**.
|
||||
* Allow you to **override the Ruby version** with an environment
|
||||
variable.
|
||||
|
||||
### In contrast with rvm, rbenv _does not…_
|
||||
|
||||
* **Need to be loaded into your shell.** Instead, rbenv's shim
|
||||
approach works by adding a directory to your `$PATH`.
|
||||
* **Override shell commands like `cd`.** That's dangerous and
|
||||
error-prone.
|
||||
* **Have a configuration file.** There's nothing to configure except
|
||||
which version of Ruby you want to use.
|
||||
* **Install Ruby.** You can build and install Ruby yourself, or use
|
||||
[ruby-build](https://github.com/sstephenson/ruby-build) to
|
||||
automate the process.
|
||||
* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
|
||||
way to manage application dependencies. If you have projects that
|
||||
are not yet using Bundler you can install the
|
||||
[rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
|
||||
* **Require changes to Ruby libraries for compatibility.** The
|
||||
simplicity of rbenv means as long as it's in your `$PATH`,
|
||||
[nothing](https://rvm.beginrescueend.com/integration/bundler/)
|
||||
[else](https://rvm.beginrescueend.com/integration/capistrano/)
|
||||
needs to know about it.
|
||||
* **Prompt you with warnings when you switch to a project.** Instead
|
||||
of executing arbitrary code, rbenv reads just the version name
|
||||
from each project. There's nothing to "trust."
|
||||
|
||||
## Table of Contents
|
||||
|
||||
## How It Works ##
|
||||
|
||||
rbenv operates on the per-user directory `~/.rbenv`. Version names in
|
||||
rbenv correspond to subdirectories of `~/.rbenv/versions`. For
|
||||
example, you might have `~/.rbenv/versions/1.8.7-p354` and
|
||||
`~/.rbenv/versions/1.9.3-rc1`.
|
||||
|
||||
Each version is a working tree with its own binaries, like
|
||||
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
|
||||
`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
|
||||
for every such binary across all installed versions of Ruby.
|
||||
|
||||
These shims are simple wrapper scripts that live in `~/.rbenv/shims`
|
||||
and detect which Ruby version you want to use. They insert the
|
||||
directory for the selected version at the beginning of your `$PATH`
|
||||
and then execute the corresponding binary.
|
||||
|
||||
Because of the simplicity of the shim approach, all you need to use
|
||||
rbenv is `~/.rbenv/shims` in your `$PATH`.
|
||||
|
||||
## Installation ##
|
||||
|
||||
**Compatibility note**: rbenv is _incompatible_ with rvm. Things will
|
||||
appear to work until you try to install a gem. The problem is that
|
||||
rvm actually overrides the `gem` command with a shell function!
|
||||
Please remove any references to rvm before using rbenv.
|
||||
|
||||
### Basic GitHub Checkout ###
|
||||
|
||||
This will get you going with the latest version of rbenv and make it
|
||||
easy to fork and contribute any changes back upstream.
|
||||
|
||||
1. Check out rbenv into `~/.rbenv`.
|
||||
|
||||
$ cd
|
||||
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
|
||||
|
||||
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
|
||||
command-line utility.
|
||||
|
||||
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
||||
|
||||
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||
|
||||
3. Add rbenv init to your shell to enable shims and autocompletion.
|
||||
|
||||
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
||||
|
||||
**Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
|
||||
|
||||
4. Restart your shell so the path changes take effect. You can now
|
||||
begin using rbenv.
|
||||
|
||||
$ exec $SHELL
|
||||
|
||||
5. Install Ruby versions into `~/.rbenv/versions`. For example, to
|
||||
install Ruby 1.9.2-p290, download and unpack the source, then run:
|
||||
|
||||
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
|
||||
$ make
|
||||
$ make install
|
||||
|
||||
The [ruby-build](https://github.com/sstephenson/ruby-build) project
|
||||
provides an `rbenv install` command that simplifies the process of
|
||||
installing new Ruby versions to:
|
||||
|
||||
$ rbenv install 1.9.2-p290
|
||||
|
||||
6. Rebuild the shim binaries. You should do this any time you install
|
||||
a new Ruby binary (for example, when installing a new Ruby version,
|
||||
or when installing a gem that provides a binary).
|
||||
|
||||
$ rbenv rehash
|
||||
|
||||
#### Upgrading ####
|
||||
|
||||
If you've installed rbenv using the instructions above, you can
|
||||
upgrade your installation at any time using git.
|
||||
|
||||
To upgrade to the latest development version of rbenv, use `git pull`:
|
||||
|
||||
$ cd ~/.rbenv
|
||||
$ git pull
|
||||
|
||||
To upgrade to a specific release of rbenv, check out the corresponding
|
||||
tag:
|
||||
|
||||
$ cd ~/.rbenv
|
||||
$ git fetch
|
||||
$ git tag
|
||||
v0.1.0
|
||||
v0.1.1
|
||||
v0.1.2
|
||||
v0.2.0
|
||||
$ git checkout v0.2.0
|
||||
|
||||
### Homebrew on Mac OS X ###
|
||||
|
||||
You can also install rbenv using the
|
||||
[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
|
||||
X.
|
||||
|
||||
$ brew update
|
||||
$ brew install rbenv
|
||||
$ brew install ruby-build
|
||||
|
||||
The same commands can be used for upgrading.
|
||||
|
||||
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
|
||||
profile as stated in the caveats. You'll only ever have to do this
|
||||
once.
|
||||
|
||||
### Neckbeard Configuration ###
|
||||
|
||||
Skip this section unless you must know what every line in your shell
|
||||
profile is doing.
|
||||
|
||||
`rbenv init` is the only command that crosses the line of loading
|
||||
extra commands into your shell. Coming from rvm, some of you might be
|
||||
opposed to this idea. Here's what `rbenv init` actually does:
|
||||
|
||||
1. Sets up your shims path. This is the only requirement for rbenv to
|
||||
function properly. You can do this by hand by prepending
|
||||
`~/.rbenv/shims` to your `$PATH`.
|
||||
|
||||
2. Installs autocompletion. This is entirely optional but pretty
|
||||
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
|
||||
up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
|
||||
users.
|
||||
|
||||
3. Rehashes shims. From time to time you'll need to rebuild your
|
||||
shim files. Doing this on init makes sure everything is up to
|
||||
date. You can always run `rbenv rehash` manually.
|
||||
|
||||
4. Installs the sh dispatcher. This bit is also optional, but allows
|
||||
rbenv and plugins to change variables in your current shell, making
|
||||
commands like `rbenv shell` possible. The sh dispatcher doesn't do
|
||||
anything crazy like override `cd` or hack your shell prompt, but if
|
||||
for some reason you need `rbenv` to be a real script rather than a
|
||||
shell function, you can safely skip it.
|
||||
|
||||
Run `rbenv init -` for yourself to see exactly what happens under the
|
||||
hood.
|
||||
|
||||
## Usage ##
|
||||
|
||||
Like `git`, the `rbenv` command delegates to subcommands based on its
|
||||
first argument. The most common subcommands are:
|
||||
|
||||
### rbenv global ###
|
||||
|
||||
Sets the global version of Ruby to be used in all shells by writing
|
||||
the version name to the `~/.rbenv/version` file. This version can be
|
||||
overridden by a per-project `.rbenv-version` file, or by setting the
|
||||
`RBENV_VERSION` environment variable.
|
||||
|
||||
$ rbenv global 1.9.2-p290
|
||||
|
||||
The special version name `system` tells rbenv to use the system Ruby
|
||||
(detected by searching your `$PATH`).
|
||||
|
||||
When run without a version number, `rbenv global` reports the
|
||||
currently configured global version.
|
||||
|
||||
### rbenv local ###
|
||||
|
||||
Sets a local per-project Ruby version by writing the version name to
|
||||
an `.rbenv-version` file in the current directory. This version
|
||||
overrides the global, and can be overridden itself by setting the
|
||||
`RBENV_VERSION` environment variable or with the `rbenv shell`
|
||||
command.
|
||||
|
||||
$ rbenv local rbx-1.2.4
|
||||
|
||||
When run without a version number, `rbenv local` reports the currently
|
||||
configured local version. You can also unset the local version:
|
||||
|
||||
$ rbenv local --unset
|
||||
|
||||
### rbenv shell ###
|
||||
|
||||
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
||||
environment variable in your shell. This version overrides both
|
||||
project-specific versions and the global version.
|
||||
|
||||
$ rbenv shell jruby-1.6.4
|
||||
|
||||
When run without a version number, `rbenv shell` reports the current
|
||||
value of `RBENV_VERSION`. You can also unset the shell version:
|
||||
|
||||
$ rbenv shell --unset
|
||||
|
||||
Note that you'll need rbenv's shell integration enabled (step 3 of
|
||||
the installation instructions) in order to use this command. If you
|
||||
prefer not to use shell integration, you may simply set the
|
||||
`RBENV_VERSION` variable yourself:
|
||||
|
||||
$ export RBENV_VERSION=jruby-1.6.4
|
||||
|
||||
### rbenv versions ###
|
||||
|
||||
Lists all Ruby versions known to rbenv, and shows an asterisk next to
|
||||
the currently active version.
|
||||
|
||||
$ rbenv versions
|
||||
1.8.7-p352
|
||||
1.9.2-p290
|
||||
* 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
|
||||
jruby-1.6.4
|
||||
rbx-1.2.4
|
||||
ree-1.8.7-2011.03
|
||||
|
||||
### rbenv version ###
|
||||
|
||||
Displays the currently active Ruby version, along with information on
|
||||
how it was set.
|
||||
|
||||
$ rbenv version
|
||||
1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
|
||||
|
||||
### rbenv rehash ###
|
||||
|
||||
Installs shims for all Ruby binaries known to rbenv (i.e.,
|
||||
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
|
||||
version of Ruby, or install a gem that provides binaries.
|
||||
|
||||
$ rbenv rehash
|
||||
|
||||
### rbenv which ###
|
||||
|
||||
Displays the full path to the binary that rbenv will execute when you
|
||||
run the given command.
|
||||
|
||||
$ rbenv which irb
|
||||
/Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
|
||||
|
||||
### rbenv whence ###
|
||||
|
||||
Lists all Ruby versions with the given command installed.
|
||||
|
||||
$ rbenv whence rackup
|
||||
1.9.3-rc1
|
||||
jruby-1.6.4
|
||||
ree-1.8.7-2011.03
|
||||
|
||||
## Development ##
|
||||
|
||||
The rbenv source code is [hosted on
|
||||
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
|
||||
and easy to understand, even if you're not a shell hacker.
|
||||
|
||||
Please feel free to submit pull requests and file bugs on the [issue
|
||||
tracker](https://github.com/sstephenson/rbenv/issues).
|
||||
|
||||
### Version History ###
|
||||
|
||||
**0.3.0** (December 25, 2011)
|
||||
|
||||
* Added an `rbenv root` command which prints the value of
|
||||
`$RBENV_ROOT`, or the default root directory if it's unset.
|
||||
* Clarified Zsh installation instructions in the readme.
|
||||
* Removed some redundant code in `rbenv rehash`.
|
||||
* Fixed an issue with calling `readlink` for paths with spaces.
|
||||
* Changed Zsh initialization code to install completion hooks only for
|
||||
interactive shells.
|
||||
* Added preliminary support for ksh.
|
||||
* `rbenv rehash` creates or removes shims only when necessary instead
|
||||
of removing and re-creating all shims on each invocation.
|
||||
* Fixed that `RBENV_DIR`, when specified, would be incorrectly
|
||||
expanded to its parent directory.
|
||||
* Removed the deprecated `set-default` and `set-local` commands.
|
||||
* Added a `--no-rehash` option to `rbenv init` for skipping the
|
||||
automatic rehash when opening a new shell.
|
||||
|
||||
**0.2.1** (October 1, 2011)
|
||||
|
||||
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
|
||||
absolute path. This fixes an issue where Ruby scripts using the
|
||||
`ruby-local-exec` wrapper would go into an infinite loop when
|
||||
invoked with a relative path from the command line.
|
||||
|
||||
**0.2.0** (September 28, 2011)
|
||||
|
||||
* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
|
||||
to `rbenv local`. The `set-` commands are deprecated and will be
|
||||
removed in the next major release.
|
||||
* rbenv now uses `greadlink` on Solaris.
|
||||
* Added a `ruby-local-exec` command which can be used in shebangs in
|
||||
place of `#!/usr/bin/env ruby` to properly set the project-specific
|
||||
Ruby version regardless of current working directory.
|
||||
* Fixed an issue with `rbenv rehash` when no binaries are present.
|
||||
* Added support for `rbenv-sh-*` commands, which run inside the
|
||||
current shell instead of in a child process.
|
||||
* Added an `rbenv shell` command for conveniently setting the
|
||||
`$RBENV_VERSION` environment variable.
|
||||
* Added support for storing rbenv versions and shims in directories
|
||||
other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
|
||||
* Added support for debugging rbenv via `set -x` when the
|
||||
`$RBENV_DEBUG` environment variable is set.
|
||||
* Refactored the autocompletion system so that completions are now
|
||||
built-in to each command and shared between bash and Zsh.
|
||||
* Added support for plugin bundles in `~/.rbenv/plugins` as documented
|
||||
in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
|
||||
* Added `/usr/local/etc/rbenv.d` to the list of directories searched
|
||||
for rbenv hooks.
|
||||
* Added support for an `$RBENV_DIR` environment variable which
|
||||
defaults to the current working directory for specifying where rbenv
|
||||
searches for local version files.
|
||||
|
||||
**0.1.2** (August 16, 2011)
|
||||
|
||||
* Fixed rbenv to be more resilient against nonexistent entries in
|
||||
`$PATH`.
|
||||
* Made the `rbenv rehash` command operate atomically.
|
||||
* Modified the `rbenv init` script to automatically run `rbenv
|
||||
rehash` so that shims are recreated whenever a new shell is opened.
|
||||
* Added initial support for Zsh autocompletion.
|
||||
* Removed the dependency on egrep for reading version files.
|
||||
|
||||
**0.1.1** (August 14, 2011)
|
||||
|
||||
* Fixed a syntax error in the `rbenv help` command.
|
||||
* Removed `-e` from the shebang in favor of `set -e` at the top of
|
||||
each file for compatibility with operating systems that do not
|
||||
support more than one argument in the shebang.
|
||||
|
||||
**0.1.0** (August 11, 2011)
|
||||
|
||||
* Initial public release.
|
||||
|
||||
### License ###
|
||||
|
||||
(The MIT license)
|
||||
|
||||
Copyright (c) 2011 Sam Stephenson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
82
doc/mdtoc.rb
82
doc/mdtoc.rb
@@ -1,82 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# A little Markdown filter that scans your document for headings,
|
||||
# numbers them, adds anchors, and inserts a table of contents.
|
||||
#
|
||||
# To use it, make sure the headings you want numbered and linked are
|
||||
# in this format:
|
||||
#
|
||||
# ### Title ###
|
||||
#
|
||||
# I.e. they must have an equal number of octothorpes around the title
|
||||
# text. (In Markdown, `#` means `h1`, `##` means `h2`, and so on.)
|
||||
# The table of contents will be inserted before the first such
|
||||
# heading.
|
||||
#
|
||||
# Released into the public domain.
|
||||
# Sam Stephenson <sstephenson@gmail.com>
|
||||
# 2011-04-30
|
||||
|
||||
def mdtoc(markdown)
|
||||
titles = []
|
||||
lines = markdown.split($/)
|
||||
start = nil
|
||||
|
||||
# First pass: Scan the Markdown source looking for titles of the
|
||||
# format: `### Title ###`. Record the line number, header level
|
||||
# (number of octothorpes), and text of each matching title.
|
||||
lines.each_with_index do |line, line_no|
|
||||
if line.match(/^(\#{1,6})\s+(.+?)\s+\1$/)
|
||||
titles << [line_no, $1.length, $2]
|
||||
start ||= line_no
|
||||
end
|
||||
end
|
||||
|
||||
last_section = nil
|
||||
last_level = nil
|
||||
|
||||
# Second pass: Iterate over all matched titles and compute their
|
||||
# corresponding section numbers. Then replace the titles with
|
||||
# annotated anchors.
|
||||
titles.each do |title_info|
|
||||
line_no, level, text = title_info
|
||||
|
||||
if last_section
|
||||
section = last_section.dup
|
||||
|
||||
if last_level < level
|
||||
section << 1
|
||||
else
|
||||
(last_level - level).times { section.pop }
|
||||
section[-1] += 1
|
||||
end
|
||||
else
|
||||
section = [1]
|
||||
end
|
||||
|
||||
name = section.join(".")
|
||||
lines[line_no] = %(#{"#" * level} <a name="section_#{name}"></a> #{name} #{text})
|
||||
|
||||
title_info << section
|
||||
last_section = section
|
||||
last_level = level
|
||||
end
|
||||
|
||||
# Third pass: Iterate over matched titles once more to produce the
|
||||
# table of contents. Then insert it immediately above the first
|
||||
# matched title.
|
||||
if start
|
||||
toc = titles.map do |(line_no, level, text, section)|
|
||||
name = section.join(".")
|
||||
%(#{" " * (section.length * 3)}* [#{name} #{text}](#section_#{name}))
|
||||
end + [""]
|
||||
|
||||
lines.insert(start, *toc)
|
||||
end
|
||||
|
||||
lines.join("\n")
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
puts mdtoc($<.read)
|
||||
end
|
||||
126
libexec/rbenv
126
libexec/rbenv
@@ -1,23 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
}
|
||||
if [ "$1" = "--debug" ]; then
|
||||
export RBENV_DEBUG=1
|
||||
shift
|
||||
fi
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
if [ -n "$RBENV_DEBUG" ]; then
|
||||
# https://web.archive.org/web/20221105082147/https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
set -x
|
||||
fi
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
abort() {
|
||||
{ if [ "$#" -eq 0 ]; then cat -
|
||||
else echo "rbenv: $*"
|
||||
fi
|
||||
} >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "${RBENV_ROOT}" ]; then
|
||||
@@ -28,48 +28,102 @@ fi
|
||||
export RBENV_ROOT
|
||||
|
||||
if [ -z "${RBENV_DIR}" ]; then
|
||||
RBENV_DIR="$(pwd)"
|
||||
RBENV_DIR="$PWD"
|
||||
else
|
||||
cd "$RBENV_DIR" 2>/dev/null || {
|
||||
echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
|
||||
exit 1
|
||||
} >&2
|
||||
RBENV_DIR="$(pwd)"
|
||||
[[ $RBENV_DIR == /* ]] || RBENV_DIR="$PWD/$RBENV_DIR"
|
||||
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
|
||||
RBENV_DIR="$PWD"
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
export RBENV_DIR
|
||||
|
||||
[ -n "$RBENV_ORIG_PATH" ] || export RBENV_ORIG_PATH="$PATH"
|
||||
|
||||
canonicalize() {
|
||||
local readlink resolved_path
|
||||
if readlink="$(type -P greadlink)" || readlink="$(type -P readlink)"; then
|
||||
# happy path: GNU & BSD readlink, macOS 12.3+
|
||||
if resolved_path="$("$readlink" -f "$1" 2>/dev/null)"; then
|
||||
printf "%s\n" "$resolved_path"
|
||||
return 0
|
||||
fi
|
||||
# likely macOS < 12.3 with old readlink
|
||||
local path="$1"
|
||||
while [ -L "$path" ]; do
|
||||
resolved_path="$("$readlink" "$path" 2>/dev/null)"
|
||||
[[ $resolved_path == /* ]] || resolved_path="$(cd "${path%/*}/${resolved_path%/*}" && pwd)/${resolved_path##*/}"
|
||||
path="$resolved_path"
|
||||
done
|
||||
printf "%s\n" "$path"
|
||||
return 0
|
||||
fi
|
||||
# fail if the argument is a symlink and was not canonicalized
|
||||
[ ! -L "$1" ] || return 1
|
||||
}
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
bin_path="$(abs_dirname "$0")"
|
||||
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
||||
bin_path="${bin_path}:${plugin_bin}"
|
||||
done
|
||||
export PATH="${bin_path}:${PATH}"
|
||||
# all this trouble just to find out where rbenv's executables live
|
||||
rbenv_bin="${BASH_SOURCE:-$0}"
|
||||
if libexec_dir="$(canonicalize "$rbenv_bin")"; then
|
||||
libexec_dir="${libexec_dir%/*}"
|
||||
else
|
||||
libexec_dir="${rbenv_bin%/*}"
|
||||
[ "$libexec_dir" != "." ] || libexec_dir="$PWD"
|
||||
fi
|
||||
|
||||
hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d"
|
||||
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
||||
hook_path="${hook_path}:${plugin_hook}"
|
||||
for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do
|
||||
PATH="${plugin_bin}:${PATH}"
|
||||
done
|
||||
export RBENV_HOOK_PATH="$hook_path"
|
||||
export PATH="${libexec_dir}:${PATH}"
|
||||
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d"
|
||||
if [ ! "${libexec_dir%/*}"/rbenv.d -ef "$RBENV_ROOT"/rbenv.d ]; then
|
||||
# Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${libexec_dir%/*}/rbenv.d"
|
||||
fi
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/etc/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}"
|
||||
done
|
||||
RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}"
|
||||
export RBENV_HOOK_PATH
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
|
||||
command="$1"
|
||||
case "$command" in
|
||||
"" | "-h" | "--help" )
|
||||
echo -e "rbenv 0.3.0\n$(rbenv-help)" >&2
|
||||
"" )
|
||||
{ rbenv---version
|
||||
rbenv-help
|
||||
} | abort
|
||||
;;
|
||||
-v | --version )
|
||||
exec rbenv---version
|
||||
;;
|
||||
-h | --help )
|
||||
exec rbenv-help
|
||||
;;
|
||||
* )
|
||||
command_path="$(command -v "rbenv-$command" || true)"
|
||||
command_path="$(type -P "rbenv-$command" || true)"
|
||||
if [ -z "$command_path" ]; then
|
||||
echo "rbenv: no such command \`$command'" >&2
|
||||
exit 1
|
||||
if [ "$command" == "shell" ]; then
|
||||
abort "shell integration not enabled. Run \`rbenv init' for instructions."
|
||||
else
|
||||
abort "no such command \`$command'"
|
||||
fi
|
||||
fi
|
||||
|
||||
shift 1
|
||||
exec "$command_path" "$@"
|
||||
if [ "$1" = --help ]; then
|
||||
if [[ "$command" == "sh-"* ]]; then
|
||||
echo "rbenv help \"$command\""
|
||||
else
|
||||
exec rbenv-help "$command"
|
||||
fi
|
||||
else
|
||||
exec "$command_path" "$@"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
23
libexec/rbenv---version
Executable file
23
libexec/rbenv---version
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Display the version of rbenv
|
||||
#
|
||||
# Displays the version number of this rbenv release, including the
|
||||
# current revision from git, if available.
|
||||
#
|
||||
# The format of the git revision is:
|
||||
# <version>-<num_commits>-<git_sha>
|
||||
# where `num_commits` is the number of commits since `version` was
|
||||
# tagged.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
version="1.3.1"
|
||||
git_revision=""
|
||||
|
||||
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
fi
|
||||
|
||||
echo "rbenv ${git_revision:-$version}"
|
||||
@@ -1,4 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: List all available rbenv commands
|
||||
# Usage: rbenv commands [--sh|--no-sh]
|
||||
#
|
||||
# List names of all rbenv commands, including 3rd-party ones found in the
|
||||
# PATH or in rbenv plugins. With `--sh`, list only shell commands.
|
||||
#
|
||||
# This functionality is mainly meant for scripting. To see usage help for
|
||||
# rbenv, run `rbenv help`.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -17,21 +26,28 @@ elif [ "$1" = "--no-sh" ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ "$(type -t readarray)" = "builtin" ]; then
|
||||
readarray -d : -t paths < <(printf "%s" "$PATH")
|
||||
else
|
||||
# bash 3.x compatibility
|
||||
IFS=: read -r -a paths <<<"$PATH" || true
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
{ for path in ${PATH//:/$'\n'}; do
|
||||
{ for path in "${paths[@]}"; do
|
||||
for command in "${path}/rbenv-"*; do
|
||||
command="${command##*rbenv-}"
|
||||
if [ -n "$sh" ]; then
|
||||
if [ ${command:0:3} = "sh-" ]; then
|
||||
echo ${command##sh-}
|
||||
if [ "${command:0:3}" = "sh-" ]; then
|
||||
echo "${command##sh-}"
|
||||
fi
|
||||
elif [ -n "$nosh" ]; then
|
||||
if [ ${command:0:3} != "sh-" ]; then
|
||||
echo ${command##sh-}
|
||||
if [ "${command:0:3}" != "sh-" ]; then
|
||||
echo "${command##sh-}"
|
||||
fi
|
||||
else
|
||||
echo ${command##sh-}
|
||||
echo "${command##sh-}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: rbenv completions <command> [<args>...]
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
COMMAND="$1"
|
||||
if [ -z "$COMMAND" ]; then
|
||||
echo "usage: rbenv completions COMMAND [arg1 arg2...]" >&2
|
||||
rbenv-help --usage completions >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")"
|
||||
if grep -i "^# provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
|
||||
# Provide rbenv completions
|
||||
if [ "$COMMAND" = "--complete" ]; then
|
||||
exec rbenv-commands
|
||||
fi
|
||||
|
||||
COMMAND_PATH="$(type -P "rbenv-$COMMAND" "rbenv-sh-$COMMAND" | head -n1)"
|
||||
|
||||
# --help is provided automatically
|
||||
echo --help
|
||||
|
||||
if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then
|
||||
shift
|
||||
exec "$COMMAND_PATH" --complete "$@"
|
||||
fi
|
||||
|
||||
@@ -1,25 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Run an executable with the selected Ruby version
|
||||
#
|
||||
# Usage: rbenv exec <command> [<args>...]
|
||||
#
|
||||
# Runs an executable by first preparing PATH so that the selected Ruby
|
||||
# version's `bin' directory is at the front.
|
||||
#
|
||||
# For example, if the currently selected Ruby version is 1.9.3-p327:
|
||||
# rbenv exec bundle install
|
||||
#
|
||||
# is equivalent to:
|
||||
# PATH="$RBENV_ROOT/versions/1.9.3-p327/bin:$PATH" bundle install
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv shims --short
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
RBENV_VERSION="$(rbenv-version-name)"
|
||||
RBENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
echo "usage: rbenv exec COMMAND [arg1 arg2...]" >&2
|
||||
rbenv-help --usage exec >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export RBENV_VERSION
|
||||
RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")"
|
||||
RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}"
|
||||
|
||||
for script in $(rbenv-hooks exec); do
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks exec)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
shift 1
|
||||
export PATH="${RBENV_BIN_PATH}:${PATH}"
|
||||
if [ "$RBENV_VERSION" != "system" ]; then
|
||||
export PATH="${RBENV_BIN_PATH}:${PATH}"
|
||||
fi
|
||||
exec -a "$RBENV_COMMAND" "$RBENV_COMMAND_PATH" "$@"
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the global Ruby version
|
||||
#
|
||||
# Usage: rbenv global <version>
|
||||
#
|
||||
# Sets the global Ruby version. You can override the global version at
|
||||
# any time by setting a directory-specific version with `rbenv local'
|
||||
# or by setting the `RBENV_VERSION' environment variable.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -14,8 +27,5 @@ RBENV_VERSION_FILE="${RBENV_ROOT}/version"
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" ||
|
||||
rbenv-version-file-read "${RBENV_ROOT}/global" ||
|
||||
rbenv-version-file-read "${RBENV_ROOT}/default" ||
|
||||
echo system
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system
|
||||
fi
|
||||
|
||||
@@ -1,88 +1,213 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Display help for a command
|
||||
#
|
||||
# Usage: rbenv help [--usage] COMMAND
|
||||
#
|
||||
# Parses and displays help contents from a command's source file.
|
||||
#
|
||||
# A command is considered documented if it starts with a comment block
|
||||
# that has a `Summary:' or `Usage:' section. Usage instructions can
|
||||
# span multiple lines as long as subsequent lines are indented.
|
||||
# The remainder of the comment block is displayed as extended
|
||||
# documentation.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
print_set_version() {
|
||||
echo "<version> should be a string matching a Ruby version known by rbenv."
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --usage
|
||||
exec rbenv-commands
|
||||
fi
|
||||
|
||||
local versions="$(rbenv-versions --bare)"
|
||||
if [ -z "$versions" ]; then
|
||||
echo "There are currently no Ruby versions installed for rbenv."
|
||||
else
|
||||
echo "The currently installed Ruby versions are:"
|
||||
echo "$versions" | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "The special version string 'system' will use your default system Ruby."
|
||||
command_path() {
|
||||
local command="$1"
|
||||
type -P rbenv-"$command" rbenv-sh-"$command" | head -n1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"") echo "usage: rbenv <command> [<args>]
|
||||
extract_initial_comment_block() {
|
||||
sed -ne "
|
||||
/^#/ !{
|
||||
q
|
||||
}
|
||||
|
||||
Some useful rbenv commands are:
|
||||
commands List all rbenv commands
|
||||
rehash Rehash rbenv shims (run this after installing binaries)
|
||||
global Set or show the global Ruby version
|
||||
local Set or show the local directory-specific Ruby version
|
||||
shell Set or show the shell-specific Ruby version
|
||||
version Show the current Ruby version
|
||||
versions List all Ruby versions known by rbenv
|
||||
which Show the full path for the given Ruby command
|
||||
whence List all Ruby versions with the given command
|
||||
s/^#$/# /
|
||||
|
||||
See 'rbenv help <command>' for information on a specific command.
|
||||
For full documentation, see: https://github.com/sstephenson/rbenv#readme"
|
||||
;;
|
||||
global) echo "usage: rbenv global <version>
|
||||
/^# / {
|
||||
s/^# //
|
||||
p
|
||||
}
|
||||
"
|
||||
}
|
||||
|
||||
Sets the global Ruby version. You can override the global version at
|
||||
any time by setting a directory-specific version with \`rbenv local'
|
||||
or by setting the RBENV_VERSION environment variable.
|
||||
|
||||
$(print_set_version)"
|
||||
;;
|
||||
local) echo "usage: rbenv local <version>
|
||||
rbenv local --unset
|
||||
|
||||
Sets the local directory-specific Ruby version by writing the version
|
||||
name to a file named '.rbenv-version'.
|
||||
|
||||
When you run a Ruby command, rbenv will look for an '.rbenv-version'
|
||||
file in the current directory and each parent directory. If no such
|
||||
file is found in the tree, rbenv will use the global Ruby version
|
||||
specified with \`rbenv global', or the version specified in the
|
||||
RBENV_VERSION environment variable.
|
||||
|
||||
$(print_set_version)"
|
||||
;;
|
||||
shell) echo "usage: rbenv shell <version>
|
||||
rbenv shell --unset
|
||||
|
||||
Sets a shell-specific Ruby version by setting the 'RBENV_VERSION'
|
||||
environment variable in your shell. This version overrides both
|
||||
project-specific versions and the global version.
|
||||
|
||||
$(print_set_version)"
|
||||
;;
|
||||
which) echo "usage: rbenv which <command>
|
||||
|
||||
Displays the full path to the binary that rbenv will execute when you
|
||||
run the given command."
|
||||
;;
|
||||
whence) echo "usage: rbenv whence <command>
|
||||
|
||||
Lists all Ruby versions with the given command installed."
|
||||
;;
|
||||
*)
|
||||
command_path="$(command -v "rbenv-$1" || true)"
|
||||
if [ -n "$command_path" ]; then
|
||||
echo "Sorry, the \`$1' command isn't documented yet."
|
||||
echo
|
||||
echo "You can view the command's source here:"
|
||||
echo "$command_path"
|
||||
echo
|
||||
else
|
||||
echo "rbenv: no such command \`$1'"
|
||||
collect_documentation() {
|
||||
local awk
|
||||
awk="$(type -P gawk)" || awk="$(type -P awk)" || true
|
||||
if [ -z "$awk" ]; then
|
||||
echo "rbenv: cannot find awk" >&2
|
||||
return 1
|
||||
fi
|
||||
esac
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
"$awk" '
|
||||
/^Summary:/ {
|
||||
summary = substr($0, 10)
|
||||
next
|
||||
}
|
||||
|
||||
/^Usage:/ {
|
||||
reading_usage = 1
|
||||
usage = usage "\n" $0
|
||||
next
|
||||
}
|
||||
|
||||
/^( *$| )/ && reading_usage {
|
||||
usage = usage "\n" $0
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
reading_usage = 0
|
||||
help = help "\n" $0
|
||||
}
|
||||
|
||||
function escape(str) {
|
||||
gsub(/[`\\$"]/, "\\\\&", str)
|
||||
return str
|
||||
}
|
||||
|
||||
function trim(str) {
|
||||
sub(/^\n*/, "", str)
|
||||
sub(/\n*$/, "", str)
|
||||
return str
|
||||
}
|
||||
|
||||
END {
|
||||
if (usage || summary) {
|
||||
print "summary=\"" escape(summary) "\""
|
||||
print "usage=\"" escape(trim(usage)) "\""
|
||||
print "help=\"" escape(trim(help)) "\""
|
||||
}
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
documentation_for() {
|
||||
local filename
|
||||
filename="$(command_path "$1")"
|
||||
if [ -n "$filename" ]; then
|
||||
extract_initial_comment_block < "$filename" | collect_documentation
|
||||
fi
|
||||
}
|
||||
|
||||
print_summary() {
|
||||
local command="$1"
|
||||
local summary usage help
|
||||
eval "$(documentation_for "$command")"
|
||||
|
||||
if [ -n "$summary" ]; then
|
||||
printf " %-9s %s\n" "$command" "$summary"
|
||||
fi
|
||||
}
|
||||
|
||||
print_summaries() {
|
||||
for command; do
|
||||
print_summary "$command"
|
||||
done
|
||||
}
|
||||
|
||||
print_help() {
|
||||
local command="$1"
|
||||
local summary usage help
|
||||
eval "$(documentation_for "$command")"
|
||||
[ -n "$help" ] || help="$summary"
|
||||
|
||||
if [ -n "$usage" ] || [ -n "$summary" ]; then
|
||||
if [ -n "$usage" ]; then
|
||||
echo "$usage"
|
||||
else
|
||||
echo "Usage: rbenv ${command}"
|
||||
fi
|
||||
if [ -n "$help" ]; then
|
||||
echo
|
||||
echo "$help"
|
||||
echo
|
||||
fi
|
||||
else
|
||||
echo "Sorry, this command isn't documented yet." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
print_usage() {
|
||||
local command="$1"
|
||||
local summary usage help
|
||||
eval "$(documentation_for "$command")"
|
||||
if [ -n "$usage" ]; then
|
||||
echo "$usage"
|
||||
else
|
||||
echo "Usage: rbenv ${command}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "--complete-commands" ]; then
|
||||
command_prefix="${2:-}"
|
||||
seen=()
|
||||
if [ "$(type -t readarray)" = "builtin" ]; then
|
||||
readarray -d : -t paths < <(printf "%s" "$PATH")
|
||||
else
|
||||
# bash 3.x compatibility
|
||||
IFS=: read -r -a paths <<<"$PATH" || true
|
||||
fi
|
||||
shopt -s nullglob
|
||||
for path in "${paths[@]}"; do
|
||||
for command in "${path}/rbenv-${command_prefix}"*; do
|
||||
command_name="${command##*/}"
|
||||
command_name="${command_name#rbenv-}"
|
||||
command_name="${command_name#sh-}"
|
||||
[[ " ${seen[*]} " != *" ${command_name} "* ]] || continue
|
||||
seen+=("$command_name")
|
||||
summary=""
|
||||
eval "$(extract_initial_comment_block < "$command" | collect_documentation)"
|
||||
[ -n "$summary" ] || continue
|
||||
printf "%s:%s\n" "$command_name" "$summary"
|
||||
done
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
unset usage
|
||||
if [ "$1" = "--usage" ]; then
|
||||
usage="1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z "$1" ] || [ "$1" == "rbenv" ]; then
|
||||
if [ -z "$usage" ] && [ -t 1 ] && type -P man >/dev/null; then
|
||||
MANPATH="${BASH_SOURCE%/*}/../share/man:$MANPATH" exec man rbenv
|
||||
fi
|
||||
echo "Usage: rbenv <command> [<args>...]"
|
||||
[ -n "$usage" ] && exit
|
||||
echo
|
||||
echo "Commands to manage available Ruby versions:"
|
||||
print_summaries versions install uninstall rehash
|
||||
echo
|
||||
echo "Commands to view or change the current Ruby version:"
|
||||
print_summaries version local global shell
|
||||
echo
|
||||
echo "See \`rbenv help <command>' for information on a specific command."
|
||||
echo "For full documentation, see: https://github.com/rbenv/rbenv#readme"
|
||||
else
|
||||
command="$1"
|
||||
if [ -n "$(command_path "$command")" ]; then
|
||||
if [ -n "$usage" ]; then
|
||||
print_usage "$command"
|
||||
else
|
||||
print_help "$command"
|
||||
fi
|
||||
else
|
||||
echo "rbenv: no such command \`$command'" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: List hook scripts for a given rbenv command
|
||||
# Usage: rbenv hooks <command>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -6,39 +9,24 @@ set -e
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo exec
|
||||
echo rehash
|
||||
echo version-name
|
||||
echo version-origin
|
||||
echo which
|
||||
exit
|
||||
fi
|
||||
|
||||
RBENV_COMMAND="$1"
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
echo "usage: rbenv hooks COMMAND" >&2
|
||||
rbenv-help --usage hooks >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) $1
|
||||
}
|
||||
|
||||
realpath() {
|
||||
local cwd="$(pwd)"
|
||||
local base="$(basename $1)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
echo "$(pwd)/$base"
|
||||
cd "$cwd"
|
||||
}
|
||||
IFS=: read -r -a hook_paths <<<"$RBENV_HOOK_PATH"
|
||||
|
||||
shopt -s nullglob
|
||||
for path in ${RBENV_HOOK_PATH//:/$'\n'}; do
|
||||
for script in $path/"$RBENV_COMMAND"/*.bash; do
|
||||
echo $(realpath $script)
|
||||
for path in "${hook_paths[@]}"; do
|
||||
for script in "$path/$RBENV_COMMAND"/*.bash; do
|
||||
echo "$script"
|
||||
done
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
@@ -1,98 +1,222 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Configure the shell environment for rbenv
|
||||
# Usage: rbenv init [<shells>...]
|
||||
# rbenv init - [--no-rehash] [<shell>]
|
||||
#
|
||||
# Modifies shell initialization files to bootstrap rbenv functionality.
|
||||
# Typically, this will add a line that eval's the output of `rbenv init -`.
|
||||
# If no shells are named by arguments, the current shell will be detected
|
||||
# by inspecting the parent process. If a shell is already configured for
|
||||
# rbenv, the init command does nothing and exits with zero status.
|
||||
#
|
||||
# In the `rbenv init -` mode, this outputs a script to be eval'd in the
|
||||
# current shell. Most importantly, that script prepends the rbenv shims
|
||||
# directory to the PATH environment variable. To aid interactive shells,
|
||||
# the script also installs the magic `rbenv()` shell function and loads
|
||||
# shell completions for rbenv commands.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo -
|
||||
echo --no-rehash
|
||||
echo bash
|
||||
echo fish
|
||||
echo ksh
|
||||
echo zsh
|
||||
exit
|
||||
fi
|
||||
|
||||
print=""
|
||||
if [ "$1" = "-" ]; then
|
||||
print=1
|
||||
shift
|
||||
fi
|
||||
|
||||
no_rehash=""
|
||||
if [ "$1" = "--no-rehash" ]; then
|
||||
no_rehash=1
|
||||
shift
|
||||
fi
|
||||
|
||||
shell="$1"
|
||||
if [ -z "$shell" ]; then
|
||||
shell="$(basename "$SHELL")"
|
||||
fi
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) $1
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
root="$(abs_dirname "$0")/.."
|
||||
|
||||
if [ -z "$print" ]; then
|
||||
case "$shell" in
|
||||
bash )
|
||||
profile='~/.bash_profile'
|
||||
shells=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-" )
|
||||
print=1
|
||||
;;
|
||||
zsh )
|
||||
profile='~/.zshrc'
|
||||
;;
|
||||
ksh )
|
||||
profile='~/.profile'
|
||||
"--no-rehash" )
|
||||
no_rehash=1
|
||||
;;
|
||||
* )
|
||||
profile='your profile'
|
||||
shells+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
{ echo "# Load rbenv automatically by adding"
|
||||
echo "# the following to ${profile}:"
|
||||
echo
|
||||
echo 'eval "$(rbenv init -)"'
|
||||
echo
|
||||
} >&2
|
||||
if [ "${#shells[@]}" -eq 0 ]; then
|
||||
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
|
||||
shell="${shell%% *}"
|
||||
shell="${shell##-}"
|
||||
shell="${shell:-$SHELL}"
|
||||
shell="${shell##*/}"
|
||||
shells=("${shell%%-*}")
|
||||
fi
|
||||
|
||||
exit 1
|
||||
root="${BASH_SOURCE:-$0}"
|
||||
root="${root%/*}"
|
||||
root="${root%/*}"
|
||||
|
||||
rbenv_in_path=true
|
||||
if [ -n "$RBENV_ORIG_PATH" ]; then
|
||||
PATH="$RBENV_ORIG_PATH" type -P rbenv >/dev/null || rbenv_in_path=""
|
||||
fi
|
||||
|
||||
if [ -z "$print" ]; then
|
||||
display_path() {
|
||||
if [ "${1/#$HOME\/}" != "$1" ]; then
|
||||
# shellcheck disable=SC2088
|
||||
printf '~/%s' "${1/#$HOME\/}"
|
||||
else
|
||||
printf '%s' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
rbenv_command=rbenv
|
||||
if [ -z "$rbenv_in_path" ]; then
|
||||
rbenv_command="$(display_path "$root/bin/rbenv")"
|
||||
fi
|
||||
|
||||
color_start=""
|
||||
color_end=""
|
||||
if [ -t 1 ]; then
|
||||
color_start=$'\e[33;1m'
|
||||
color_end=$'\e[m'
|
||||
fi
|
||||
|
||||
write_config() {
|
||||
if grep -q "rbenv init" "$1" 2>/dev/null; then
|
||||
printf 'skipping %s%s%s: already configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||
return 0
|
||||
fi
|
||||
mkdir -p "${1%/*}"
|
||||
# shellcheck disable=SC2016
|
||||
printf '\n# Added by `rbenv init` on %s\n%s\n' "$(date)" "$2" >> "$1"
|
||||
printf 'writing %s%s%s: now configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
|
||||
}
|
||||
|
||||
status=0
|
||||
for shell in "${shells[@]}"; do
|
||||
case "$shell" in
|
||||
bash )
|
||||
if [ -f ~/.bashrc ] && [ ! -f ~/.bash_profile ]; then
|
||||
profile="$HOME/.bashrc"
|
||||
else
|
||||
# shellcheck disable=SC2012
|
||||
profile="$(ls ~/.bash_profile ~/.bash_login ~/.profile 2>/dev/null | head -n1)"
|
||||
[ -n "$profile" ] || profile="$HOME/.bash_profile"
|
||||
fi
|
||||
write_config "$profile" \
|
||||
"eval \"\$($rbenv_command init - --no-rehash bash)\""
|
||||
;;
|
||||
zsh )
|
||||
# check zshrc for backward compatibility with older rbenv init
|
||||
if grep -q rbenv "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null; then
|
||||
profile="${ZDOTDIR:-$HOME}/.zshrc"
|
||||
else
|
||||
profile="${ZDOTDIR:-$HOME}/.zprofile"
|
||||
fi
|
||||
write_config "$profile" \
|
||||
"eval \"\$($rbenv_command init - --no-rehash zsh)\""
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
# There are two implementations of Korn shell: AT&T (ksh93) and Mir (mksh).
|
||||
# Systems may have them installed under those names, or as ksh, so those
|
||||
# are recognized here. The obsolete ksh88 (subsumed by ksh93) and pdksh
|
||||
# (subsumed by mksh) are not included, since they are unlikely to still
|
||||
# be in use as interactive shells anywhere.
|
||||
write_config "$HOME/.profile" \
|
||||
"eval \"\$($rbenv_command init - ksh)\""
|
||||
;;
|
||||
fish )
|
||||
write_config "${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" \
|
||||
"status --is-interactive; and $rbenv_command init - --no-rehash fish | source"
|
||||
;;
|
||||
* )
|
||||
printf 'unsupported shell: "%s"\n' "$shell" >&2
|
||||
status=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit $status
|
||||
fi
|
||||
|
||||
mkdir -p "${RBENV_ROOT}/"{shims,versions}
|
||||
|
||||
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
||||
|
||||
shell="${shells[0]}"
|
||||
case "$shell" in
|
||||
bash | zsh )
|
||||
echo "source \"$root/completions/rbenv.${shell}\""
|
||||
;;
|
||||
fish )
|
||||
[ -n "$rbenv_in_path" ] || printf "set -gx PATH '%s/bin' \$PATH\n" "$root"
|
||||
printf "set -gx PATH '%s/shims' \$PATH\n" "$RBENV_ROOT"
|
||||
printf 'set -gx RBENV_SHELL %s\n' "$shell"
|
||||
;;
|
||||
* )
|
||||
# shellcheck disable=SC2016
|
||||
[ -n "$rbenv_in_path" ] || printf 'export PATH="%s/bin:${PATH}"\n' "$root"
|
||||
# shellcheck disable=SC2016
|
||||
printf 'export PATH="%s/shims:${PATH}"\n' "$RBENV_ROOT"
|
||||
printf 'export RBENV_SHELL=%s\n' "$shell"
|
||||
|
||||
completion="${root}/completions/rbenv.${shell}"
|
||||
if [ -r "$completion" ]; then
|
||||
printf "source '%s'\n" "$completion"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$no_rehash" ]; then
|
||||
echo 'rbenv rehash 2>/dev/null'
|
||||
echo 'command rbenv rehash 2>/dev/null'
|
||||
fi
|
||||
|
||||
commands=(`rbenv commands --sh`)
|
||||
IFS=$'\n' read -d '' -r -a commands <<<"$(rbenv-commands --sh)" || true
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
function rbenv
|
||||
set command \$argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
switch "\$command"
|
||||
case ${commands[*]}
|
||||
rbenv "sh-\$command" \$argv|source
|
||||
case '*'
|
||||
command rbenv "\$command" \$argv
|
||||
end
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
ksh | ksh93 | mksh )
|
||||
cat <<EOS
|
||||
function rbenv {
|
||||
typeset command
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
rbenv() {
|
||||
local command
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$shell" != "fish" ]; then
|
||||
IFS="|"
|
||||
cat <<EOS
|
||||
rbenv() {
|
||||
command="\$1"
|
||||
command="\${1:-}"
|
||||
if [ "\$#" -gt 0 ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
case "\$command" in
|
||||
${commands[*]})
|
||||
eval \`rbenv "sh-\$command" "\$@"\`;;
|
||||
eval "\$(rbenv "sh-\$command" "\$@")";;
|
||||
*)
|
||||
command rbenv "\$command" "\$@";;
|
||||
esac
|
||||
}
|
||||
EOS
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the local application-specific Ruby version
|
||||
#
|
||||
# Usage: rbenv local <version>
|
||||
# rbenv local --unset
|
||||
#
|
||||
# Sets the local application-specific Ruby version by writing the
|
||||
# version name to a file named `.ruby-version'.
|
||||
#
|
||||
# When you run a Ruby command, rbenv will look for a `.ruby-version'
|
||||
# file in the current directory and each parent directory. If no such
|
||||
# file is found in the tree, rbenv will use the global Ruby version
|
||||
# specified with `rbenv global'. A version specified with the
|
||||
# `RBENV_VERSION' environment variable takes precedence over local
|
||||
# and global versions.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -10,15 +30,16 @@ if [ "$1" = "--complete" ]; then
|
||||
fi
|
||||
|
||||
RBENV_VERSION="$1"
|
||||
RBENV_VERSION_FILE=".rbenv-version"
|
||||
|
||||
if [ "$RBENV_VERSION" = "--unset" ]; then
|
||||
rm -f "$RBENV_VERSION_FILE"
|
||||
rm -f .ruby-version
|
||||
elif [ -n "$RBENV_VERSION" ]; then
|
||||
rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION"
|
||||
rbenv-version-file-write .ruby-version "$RBENV_VERSION"
|
||||
else
|
||||
rbenv-version-file-read "$RBENV_VERSION_FILE" ||
|
||||
{ echo "rbenv: no local version configured for this directory"
|
||||
if version_file="$(rbenv-version-file "$PWD")"; then
|
||||
rbenv-version-file-read "$version_file"
|
||||
else
|
||||
echo "rbenv: no local version configured for this directory" >&2
|
||||
exit 1
|
||||
} >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Display prefix for a Ruby version
|
||||
# Usage: rbenv prefix [<version>]
|
||||
#
|
||||
# Displays the directory where a Ruby version is installed. If no
|
||||
# version is given, `rbenv prefix' displays the location of the
|
||||
# currently selected version.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -15,9 +22,15 @@ elif [ -z "$RBENV_VERSION" ]; then
|
||||
fi
|
||||
|
||||
if [ "$RBENV_VERSION" = "system" ]; then
|
||||
RUBY_PATH="$(rbenv-which ruby)"
|
||||
echo "${RUBY_PATH%/*}"
|
||||
exit
|
||||
if RUBY_PATH="$(rbenv-which ruby)"; then
|
||||
RUBY_PATH="${RUBY_PATH%/*}"
|
||||
RBENV_PREFIX_PATH="${RUBY_PATH%/bin}"
|
||||
echo "${RBENV_PREFIX_PATH:-/}"
|
||||
exit
|
||||
else
|
||||
echo "rbenv: system version not found in PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Regenerate rbenv shims
|
||||
#
|
||||
# Regenerate shims for every Ruby executable in `$RBENV_ROOT/versions/*/bin'
|
||||
# and write them to the `$RBENV_ROOT/shims' directory. A shell environment
|
||||
# properly set up for rbenv will have this shims directory in PATH, which is
|
||||
# the core mechanism for Ruby version switching.
|
||||
#
|
||||
# Running rbenv rehash should only be necessary after installing new Ruby
|
||||
# versions or gems. Note that this is sometimes done automatically: the
|
||||
# `rbenv install' command from the ruby-build plugin runs rehash after
|
||||
# every successful installation, and a RubyGems plugin that ships with
|
||||
# rbenv runs rehash after every `gem install' command.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -14,8 +27,12 @@ mkdir -p "$SHIM_PATH"
|
||||
# to stderr and exit with a non-zero status.
|
||||
set -o noclobber
|
||||
{ echo > "$PROTOTYPE_SHIM_PATH"
|
||||
} 2>/dev/null ||
|
||||
{ echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
||||
} 2>| /dev/null ||
|
||||
{ if [ -w "$SHIM_PATH" ]; then
|
||||
echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
||||
else
|
||||
echo "rbenv: cannot rehash: $SHIM_PATH isn't writable"
|
||||
fi
|
||||
exit 1
|
||||
} >&2
|
||||
set +o noclobber
|
||||
@@ -28,87 +45,104 @@ remove_prototype_shim() {
|
||||
rm -f "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# Locates rbenv as found in the user's PATH. Otherwise, returns an
|
||||
# absolute path to the rbenv executable itself.
|
||||
rbenv_path() {
|
||||
local found
|
||||
found="$(PATH="$RBENV_ORIG_PATH" type -P rbenv)"
|
||||
if [[ $found == /* ]]; then
|
||||
echo "$found"
|
||||
elif [[ -n "$found" ]]; then
|
||||
echo "$PWD/${found#./}"
|
||||
else
|
||||
# Assume rbenv isn't in PATH.
|
||||
echo "${BASH_SOURCE%/*}/rbenv"
|
||||
fi
|
||||
}
|
||||
|
||||
# The prototype shim file is a script that re-execs itself, passing
|
||||
# its filename and any arguments to `rbenv exec`. This file is
|
||||
# hard-linked for every binary and then removed. The linking technique
|
||||
# is fast, uses less disk space than unique files, and also serves as
|
||||
# a locking mechanism.
|
||||
# hard-linked for every executable and then removed. The linking
|
||||
# technique is fast, uses less disk space than unique files, and also
|
||||
# serves as a locking mechanism.
|
||||
create_prototype_shim() {
|
||||
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "\$RBENV_DEBUG" ] && set -x
|
||||
|
||||
program="\${0##*/}"
|
||||
if [ "\$program" = "ruby" ]; then
|
||||
for arg; do
|
||||
case "\$arg" in
|
||||
-e* | -- ) break ;;
|
||||
*/* )
|
||||
if [ -f "\$arg" ]; then
|
||||
export RBENV_DIR="\${arg%/*}"
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
export RBENV_ROOT="$RBENV_ROOT"
|
||||
exec rbenv exec "\${0##*/}" "\$@"
|
||||
exec "$(rbenv_path)" exec "\$program" "\$@"
|
||||
SH
|
||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||
}
|
||||
|
||||
# If the contents of the prototype shim file differ from the contents
|
||||
# of the first shim in the shims directory, assume rbenv has been
|
||||
# upgraded and the existing shims need to be removed.
|
||||
remove_outdated_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
|
||||
rm -f "$SHIM_PATH"/*
|
||||
fi
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
# List basenames of executables for every Ruby version
|
||||
list_executable_names() {
|
||||
local version file
|
||||
rbenv-versions --bare --skip-aliases | \
|
||||
while read -r version; do
|
||||
for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do
|
||||
echo "${file##*/}"
|
||||
done
|
||||
done
|
||||
if [ -n "$GEM_HOME" ]; then
|
||||
for file in "$GEM_HOME"/bin/*; do
|
||||
echo "${file##*/}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# The basename of each argument passed to `make_shims` will be
|
||||
# registered for installation as a shim. In this way, plugins may call
|
||||
# `make_shims` with a glob to register many shims at once.
|
||||
make_shims() {
|
||||
local shims="$@"
|
||||
|
||||
for file in $shims; do
|
||||
local shim="${file##*/}"
|
||||
register_shim "$shim"
|
||||
local file shim
|
||||
for file; do
|
||||
shim="${file##*/}"
|
||||
registered_shims+=("$shim")
|
||||
done
|
||||
}
|
||||
|
||||
# Create an empty array for the list of registered shims.
|
||||
registered_shims=()
|
||||
|
||||
# We will keep track of shims registered for installation with the
|
||||
# global `reigstered_shims` array and with a global variable for each
|
||||
# shim. The array will let us iterate over all registered shims. The
|
||||
# global variables will let us quickly check whether a shim with the
|
||||
# given name has been registered or not.
|
||||
# Registers the name of a shim to be generated.
|
||||
register_shim() {
|
||||
local shim="$@"
|
||||
local var="$(shim_variable_name "$shim")"
|
||||
|
||||
if [ -z "${!var}" ]; then
|
||||
registered_shims[${#registered_shims[*]}]="$shim"
|
||||
eval "${var}=1"
|
||||
fi
|
||||
registered_shims+=("$1")
|
||||
}
|
||||
|
||||
# To compute the global variable name for a given shim we must first
|
||||
# escape any non-alphanumeric characters. If the shim name is
|
||||
# alphanumeric (including a hyphen or underscore) we can take a
|
||||
# shorter path. Otherwise, we must iterate over each character and
|
||||
# escape the non-alphanumeric ones using `printf`.
|
||||
shim_variable_name() {
|
||||
local shim="$1"
|
||||
local result="_shim_"
|
||||
|
||||
if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then
|
||||
shim="${shim//_/_5f}"
|
||||
shim="${shim//-/_2d}"
|
||||
result+="$shim"
|
||||
else
|
||||
local length="${#shim}"
|
||||
local char i
|
||||
|
||||
for ((i=0; i<length; i++)); do
|
||||
char="${shim:$i:1}"
|
||||
if [[ "$char" =~ [[:alnum:]] ]]; then
|
||||
result+="$char"
|
||||
else
|
||||
result+="$(printf "_%02x" \'"$char")"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
# To install all the registered shims, we iterate over the
|
||||
# `registered_shims` array and create a link if one does not already
|
||||
# exist.
|
||||
# Install all the shims registered via `make_shims` or `register_shim` directly.
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in "${registered_shims[@]}"; do
|
||||
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -117,32 +151,30 @@ install_registered_shims() {
|
||||
# in the directory but has not been registered as a shim should be
|
||||
# removed.
|
||||
remove_stale_shims() {
|
||||
local var
|
||||
for shim in *; do
|
||||
var="$(shim_variable_name "$shim")"
|
||||
[ -z "${!var}" ] && rm -f "$shim"
|
||||
local shim
|
||||
local known_shims=" ${registered_shims[*]} "
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if [[ "$known_shims" != *" ${shim##*/} "* ]]; then
|
||||
rm -f "$shim"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# Change to the shims directory.
|
||||
cd "$SHIM_PATH"
|
||||
|
||||
# Create the prototype shim, then register shims for all known binaries.
|
||||
create_prototype_shim
|
||||
shopt -s nullglob
|
||||
make_shims ../versions/*/bin/*
|
||||
|
||||
# Restore the previous working directory.
|
||||
cd "$OLDPWD"
|
||||
# Create the prototype shim, then register shims for all known
|
||||
# executables.
|
||||
create_prototype_shim
|
||||
remove_outdated_shims
|
||||
# shellcheck disable=SC2207
|
||||
registered_shims=( $(list_executable_names | sort -u) )
|
||||
|
||||
# Allow plugins to register shims.
|
||||
for script in $(rbenv-hooks rehash); do
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks rehash)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
# Change back to the shims directory to install the registered shims
|
||||
# and remove stale shims.
|
||||
cd "$SHIM_PATH"
|
||||
install_registered_shims
|
||||
remove_stale_shims
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
echo $RBENV_ROOT
|
||||
# Summary: Display the root directory where versions and shims are kept
|
||||
echo "$RBENV_ROOT"
|
||||
|
||||
23
libexec/rbenv-sh-rehash
Executable file
23
libexec/rbenv-sh-rehash
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv-rehash --complete
|
||||
fi
|
||||
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
# When rbenv shell integration is enabled, delegate to rbenv-rehash,
|
||||
# then tell the shell to empty its command lookup cache.
|
||||
rbenv-rehash
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
# no rehash support
|
||||
;;
|
||||
* )
|
||||
echo "hash -r 2>/dev/null || true"
|
||||
;;
|
||||
esac
|
||||
@@ -1,4 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Set or show the shell-specific Ruby version
|
||||
#
|
||||
# Usage: rbenv shell <version>
|
||||
# rbenv shell -
|
||||
# rbenv shell --unset
|
||||
#
|
||||
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
||||
# environment variable in your shell. This version overrides local
|
||||
# application-specific versions and the global version.
|
||||
#
|
||||
# <version> should be a string matching a Ruby version known to rbenv.
|
||||
# The special version string `system' will use your default system Ruby.
|
||||
# Run `rbenv versions' for a list of available Ruby versions.
|
||||
#
|
||||
# When `-` is passed instead of the version string, the previously set
|
||||
# version will be restored. With `--unset`, the `RBENV_VERSION`
|
||||
# environment variable gets unset, restoring the environment to the
|
||||
# state before the first `rbenv shell` call.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -10,23 +30,115 @@ if [ "$1" = "--complete" ]; then
|
||||
fi
|
||||
|
||||
version="$1"
|
||||
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
if [ -z "$RBENV_VERSION" ]; then
|
||||
echo "rbenv: no shell-specific version configured" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "echo \"\$RBENV_VERSION\""
|
||||
echo 'echo "$RBENV_VERSION"'
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$version" = "--unset" ]; then
|
||||
echo "unset RBENV_VERSION"
|
||||
exit 1
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -e RBENV_VERSION"
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$version" = "-" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
if set -q RBENV_VERSION_OLD
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]
|
||||
set RBENV_VERSION_OLD_ "\$RBENV_VERSION"
|
||||
set -gx RBENV_VERSION "\$RBENV_VERSION_OLD"
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION_OLD_"
|
||||
set -e RBENV_VERSION_OLD_
|
||||
else
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||
set -e RBENV_VERSION
|
||||
end
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
zsh )
|
||||
cat <<EOS
|
||||
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||
local RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||
unset RBENV_VERSION_OLD_
|
||||
else
|
||||
typeset -g RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||
RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||
unset RBENV_VERSION_OLD_
|
||||
else
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
rbenv-prefix "$version" >/dev/null
|
||||
|
||||
echo "export RBENV_VERSION=\"${version}\""
|
||||
if rbenv-prefix "$version" >/dev/null; then
|
||||
if [ "$version" != "$RBENV_VERSION" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -gx RBENV_VERSION \"$version\""
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: List existing rbenv shims
|
||||
# Usage: rbenv shims [--short]
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -8,6 +11,8 @@ if [ "$1" = "--complete" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
for command in "${RBENV_ROOT}/shims/"*; do
|
||||
if [ "$1" = "--short" ]; then
|
||||
echo "${command##*/}"
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Ruby version and its origin
|
||||
#
|
||||
# Shows the currently selected Ruby version and how it was
|
||||
# selected. To obtain only the version string, use `rbenv
|
||||
# version-name'.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
echo "$(rbenv-version-name) (set by $(rbenv-version-origin))"
|
||||
version_name="$(rbenv-version-name)"
|
||||
version_origin="$(rbenv-version-origin)"
|
||||
|
||||
if [ "$version_origin" = "${RBENV_ROOT}/version" ] && [ ! -e "$version_origin" ]; then
|
||||
echo "$version_name"
|
||||
else
|
||||
echo "$version_name (set by $version_origin)"
|
||||
fi
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file [<dir>]
|
||||
# Summary: Detect the file that sets the current rbenv version
|
||||
#
|
||||
# Detects and prints the location of a `.ruby-version` file that sets the
|
||||
# version for the current working directory. If no file found, this prints
|
||||
# the location of the global version file, even if that file does
|
||||
# not exist.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
root="$RBENV_DIR"
|
||||
while [ -n "$root" ]; do
|
||||
if [ -e "${root}/.rbenv-version" ]; then
|
||||
echo "${root}/.rbenv-version"
|
||||
exit
|
||||
fi
|
||||
root="${root%/*}"
|
||||
done
|
||||
target_dir="$1"
|
||||
|
||||
global_version_file="${RBENV_ROOT}/version"
|
||||
find_local_version_file() {
|
||||
local root="$1"
|
||||
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
||||
if [ -s "${root}/.ruby-version" ]; then
|
||||
echo "${root}/.ruby-version"
|
||||
return 0
|
||||
fi
|
||||
[ -n "$root" ] || break
|
||||
root="${root%/*}"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ -e "$global_version_file" ]; then
|
||||
echo "$global_version_file"
|
||||
elif [ -e "${RBENV_ROOT}/global" ]; then
|
||||
echo "${RBENV_ROOT}/global"
|
||||
elif [ -e "${RBENV_ROOT}/default" ]; then
|
||||
echo "${RBENV_ROOT}/default"
|
||||
if [ -n "$target_dir" ]; then
|
||||
find_local_version_file "$target_dir"
|
||||
else
|
||||
echo "$global_version_file"
|
||||
find_local_version_file "$RBENV_DIR" || {
|
||||
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
|
||||
} || echo "${RBENV_ROOT}/version"
|
||||
fi
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file-read <file>
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
VERSION_FILE="$1"
|
||||
|
||||
if [ -e "$VERSION_FILE" ]; then
|
||||
# Read and print the first non-whitespace word from the specified
|
||||
# version file.
|
||||
version=""
|
||||
while read -a words; do
|
||||
word="${words[0]}"
|
||||
if [ -z "$version" ] && [ -n "$word" ]; then
|
||||
version="$word"
|
||||
fi
|
||||
done < <( cat "$VERSION_FILE" && echo )
|
||||
if [ -s "$VERSION_FILE" ]; then
|
||||
# Read the first word from the specified version file. Avoid reading it whole.
|
||||
IFS="${IFS}"$'\r'
|
||||
read -n 1024 -d "" -r version _ <"$VERSION_FILE" || :
|
||||
|
||||
if [ -n "$version" ]; then
|
||||
if [ "$version" = ".." ] || [[ $version == */* ]]; then
|
||||
echo "rbenv: invalid version in \`$VERSION_FILE'" >&2
|
||||
elif [ -n "$version" ]; then
|
||||
echo "$version"
|
||||
exit
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: rbenv version-file-write <file> <version>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -6,7 +8,7 @@ RBENV_VERSION_FILE="$1"
|
||||
RBENV_VERSION="$2"
|
||||
|
||||
if [ -z "$RBENV_VERSION" ] || [ -z "$RBENV_VERSION_FILE" ]; then
|
||||
echo "usage: rbenv write-version-file FILENAME VERSION" >&2
|
||||
rbenv-help --usage version-file-write >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Show the current Ruby version
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
@@ -7,16 +8,27 @@ if [ -z "$RBENV_VERSION" ]; then
|
||||
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
||||
fi
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
|
||||
echo "system"
|
||||
exit
|
||||
fi
|
||||
|
||||
RBENV_VERSION_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"
|
||||
version_exists() {
|
||||
local version="$1"
|
||||
[ -d "${RBENV_ROOT}/versions/${version}" ]
|
||||
}
|
||||
|
||||
if [ -d "$RBENV_VERSION_PATH" ]; then
|
||||
if version_exists "$RBENV_VERSION"; then
|
||||
echo "$RBENV_VERSION"
|
||||
elif version_exists "${RBENV_VERSION#ruby-}"; then
|
||||
echo "${RBENV_VERSION#ruby-}"
|
||||
else
|
||||
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
|
||||
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Explain how the current Ruby version is set
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
if [ -n "$RBENV_VERSION" ]; then
|
||||
unset RBENV_VERSION_ORIGIN
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-origin)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -n "$RBENV_VERSION_ORIGIN" ]; then
|
||||
echo "$RBENV_VERSION_ORIGIN"
|
||||
elif [ -n "$RBENV_VERSION" ]; then
|
||||
echo "RBENV_VERSION environment variable"
|
||||
else
|
||||
rbenv-version-file
|
||||
|
||||
@@ -1,27 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: List installed Ruby versions
|
||||
# Usage: rbenv versions [--bare] [--skip-aliases]
|
||||
#
|
||||
# Lists all Ruby versions found in `$RBENV_ROOT/versions/*'.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
RBENV_VERSION_NAME="$(rbenv-version-name)"
|
||||
unset bare
|
||||
unset skip_aliases
|
||||
# Provide rbenv completions
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--complete )
|
||||
echo --bare
|
||||
echo --skip-aliases
|
||||
exit ;;
|
||||
--bare ) bare=1 ;;
|
||||
--skip-aliases ) skip_aliases=1 ;;
|
||||
* )
|
||||
rbenv-help --usage versions >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$1" = "--bare" ]; then
|
||||
hit_prefix=""
|
||||
miss_prefix=""
|
||||
print_version="$RBENV_VERSION_NAME"
|
||||
else
|
||||
hit_prefix="* "
|
||||
miss_prefix=" "
|
||||
print_version="$(rbenv-version)"
|
||||
canonicalize_dir() {
|
||||
{ cd "$1" && pwd -P
|
||||
} 2>/dev/null || echo "$1"
|
||||
}
|
||||
|
||||
versions_dir="${RBENV_ROOT}/versions"
|
||||
if [ -n "$skip_aliases" ]; then
|
||||
versions_dir="$(canonicalize_dir "$versions_dir")"
|
||||
fi
|
||||
|
||||
for path in "${RBENV_ROOT}/versions/"*; do
|
||||
if [ -d "$path" ]; then
|
||||
version="${path##*/}"
|
||||
|
||||
if [ "$version" == "$RBENV_VERSION_NAME" ]; then
|
||||
echo "${hit_prefix}${print_version}"
|
||||
else
|
||||
echo "${miss_prefix}${version}"
|
||||
list_versions() {
|
||||
local path
|
||||
local target
|
||||
shopt -s nullglob
|
||||
for path in "$versions_dir"/*; do
|
||||
if [ -d "$path" ]; then
|
||||
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
|
||||
target="$(canonicalize_dir "$path")"
|
||||
[ "${target%/*}" != "$versions_dir" ] || continue
|
||||
fi
|
||||
echo "${path##*/}"
|
||||
fi
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
if [ -n "$bare" ]; then
|
||||
list_versions
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sort_versions() {
|
||||
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
|
||||
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
|
||||
}
|
||||
|
||||
versions="$(
|
||||
if RBENV_VERSION=system rbenv-which ruby >/dev/null 2>&1; then
|
||||
echo system
|
||||
fi
|
||||
done
|
||||
list_versions | sort_versions
|
||||
)"
|
||||
|
||||
if [ -z "$versions" ]; then
|
||||
echo "Warning: no Ruby detected on the system" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_version="$(rbenv-version-name || true)"
|
||||
while read -r version; do
|
||||
if [ "$version" == "$current_version" ]; then
|
||||
echo "* $(rbenv-version 2>/dev/null)"
|
||||
else
|
||||
echo " $version"
|
||||
fi
|
||||
done <<<"$versions"
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: List all Ruby versions that contain the given executable
|
||||
# Usage: rbenv whence [--path] <command>
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
echo --path
|
||||
exec rbenv shims --short
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
if [ "$1" = "--path" ]; then
|
||||
@@ -17,7 +20,7 @@ fi
|
||||
|
||||
whence() {
|
||||
local command="$1"
|
||||
rbenv-versions --bare | while read version; do
|
||||
rbenv-versions --bare | while read -r version; do
|
||||
path="$(rbenv-prefix "$version")/bin/${command}"
|
||||
if [ -x "$path" ]; then
|
||||
[ "$print_paths" ] && echo "$path" || echo "$version"
|
||||
@@ -27,7 +30,7 @@ whence() {
|
||||
|
||||
RBENV_COMMAND="$1"
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
echo "usage: rbenv whence [--path] COMMAND" >&2
|
||||
rbenv-help --usage whence >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Display the full path to an executable
|
||||
#
|
||||
# Usage: rbenv which <command>
|
||||
#
|
||||
# Displays the full path to the executable that rbenv will invoke when
|
||||
# you run the given command.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide rbenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec rbenv shims --short
|
||||
exec rbenv-shims --short
|
||||
fi
|
||||
|
||||
expand_path() {
|
||||
if [ ! -d "$1" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local cwd="$(pwd)"
|
||||
cd "$1"
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
remove_from_path() {
|
||||
local path_to_remove="$(expand_path "$1")"
|
||||
local result=""
|
||||
|
||||
if [ -z "$path_to_remove" ]; then
|
||||
echo "${PATH}"
|
||||
return
|
||||
fi
|
||||
|
||||
for path in ${PATH//:/$'\n'}; do
|
||||
path="$(expand_path "$path" || true)"
|
||||
if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then
|
||||
result="${result}${path}:"
|
||||
fi
|
||||
local path_to_remove="$1"
|
||||
local path_before
|
||||
local result=":${PATH//\~/$HOME}:"
|
||||
while [ "$path_before" != "$result" ]; do
|
||||
path_before="$result"
|
||||
result="${result//:$path_to_remove:/:}"
|
||||
done
|
||||
|
||||
echo "${result%:}"
|
||||
result="${result%:}"
|
||||
echo "${result#:}"
|
||||
}
|
||||
|
||||
RBENV_VERSION="$(rbenv-version-name)"
|
||||
RBENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$RBENV_COMMAND" ]; then
|
||||
echo "usage: rbenv which COMMAND" >&2
|
||||
rbenv-help --usage which >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
|
||||
|
||||
if [ "$RBENV_VERSION" = "system" ]; then
|
||||
PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
|
||||
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")"
|
||||
PATH="$(remove_from_path "${RBENV_ROOT}/shims")" \
|
||||
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
|
||||
else
|
||||
RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
|
||||
fi
|
||||
|
||||
for script in $(rbenv-hooks which); do
|
||||
if [[ ! -x "$RBENV_COMMAND_PATH" && -n "$GEM_HOME" && -x "${GEM_HOME}/bin/${RBENV_COMMAND}" ]]; then
|
||||
RBENV_COMMAND_PATH="${GEM_HOME}/bin/${RBENV_COMMAND}"
|
||||
fi
|
||||
|
||||
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks which)" || true
|
||||
for script in "${scripts[@]}"; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$script"
|
||||
done
|
||||
|
||||
if [ -x "$RBENV_COMMAND_PATH" ]; then
|
||||
echo "$RBENV_COMMAND_PATH"
|
||||
elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
|
||||
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "rbenv: $RBENV_COMMAND: command not found" >&2
|
||||
|
||||
|
||||
1
rbenv.d/exec/gem-rehash.bash
Normal file
1
rbenv.d/exec/gem-rehash.bash
Normal file
@@ -0,0 +1 @@
|
||||
export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB"
|
||||
45
rbenv.d/exec/gem-rehash/rubygems_plugin.rb
Normal file
45
rbenv.d/exec/gem-rehash/rubygems_plugin.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
hook = lambda do |installer|
|
||||
begin
|
||||
# Ignore gems that aren't installed in locations that rbenv searches for binstubs
|
||||
if installer.spec.executables.any? &&
|
||||
[Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir)
|
||||
`rbenv rehash`
|
||||
end
|
||||
rescue
|
||||
warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})"
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(Bundler::Installer) &&
|
||||
Bundler::Installer.private_method_defined?(:install) &&
|
||||
!Bundler::Installer.private_method_defined?(:install_without_rbenv_rehash)
|
||||
Bundler::Installer.class_eval do
|
||||
private
|
||||
|
||||
alias install_without_rbenv_rehash install
|
||||
def install(options)
|
||||
begin
|
||||
if Gem.default_path.include?(Bundler.bundle_path.to_s)
|
||||
bin_dir = Gem.bindir(Bundler.bundle_path.to_s)
|
||||
bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2
|
||||
end
|
||||
rescue
|
||||
warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})"
|
||||
end
|
||||
|
||||
result = install_without_rbenv_rehash(options)
|
||||
|
||||
if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before
|
||||
`rbenv rehash`
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
Gem.post_install(&hook)
|
||||
Gem.post_uninstall(&hook)
|
||||
rescue
|
||||
warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})"
|
||||
end
|
||||
end
|
||||
163
share/man/man1/rbenv.1
generated
Normal file
163
share/man/man1/rbenv.1
generated
Normal file
@@ -0,0 +1,163 @@
|
||||
'\" t
|
||||
.\" Title: rbenv
|
||||
.\" Author: Mislav Marohnić
|
||||
.\" Generator: Asciidoctor 2.0.20
|
||||
.\" Date: 2023-11-08
|
||||
.\" Manual: Rbenv Manual
|
||||
.\" Source: rbenv 1.3.1
|
||||
.\" Language: English
|
||||
.\"
|
||||
.TH "RBENV" "1" "2023-11-08" "rbenv 1.3.1" "Rbenv Manual"
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.ss \n[.ss] 0
|
||||
.nh
|
||||
.ad l
|
||||
.de URL
|
||||
\fI\\$2\fP <\\$1>\\$3
|
||||
..
|
||||
.als MTO URL
|
||||
.if \n[.g] \{\
|
||||
. mso www.tmac
|
||||
. am URL
|
||||
. ad l
|
||||
. .
|
||||
. am MTO
|
||||
. ad l
|
||||
. .
|
||||
. LINKSTYLE blue R < >
|
||||
.\}
|
||||
.SH "NAME"
|
||||
rbenv \- manage your application\*(Aqs Ruby environment
|
||||
.SH "SYNOPSIS"
|
||||
.sp
|
||||
\fBrbenv\fP \fI<command>\fP [\fI<args>\fP...]
|
||||
.SH "DESCRIPTION"
|
||||
.sp
|
||||
rbenv respects the \fI.ruby\-version\fP file in a project directory by making sure that any \fBruby\fP, \fBgem\fP, \fBbundle\fP, or other Ruby command invocation automatically invokes the Ruby version configured for that project.
|
||||
.sp
|
||||
It does so by generating shims for all Ruby executables. As long as rbenv shims directory is prepended to PATH, rbenv automatically ensures transparent switching between Ruby versions.
|
||||
.sp
|
||||
rbenv looks for available Ruby versions in the \fI$RBENV_ROOT/versions\fP directory.
|
||||
.SH "COMMANDS"
|
||||
.sp
|
||||
\fBrbenv global\fP [\fI<version>\fP]
|
||||
.RS 4
|
||||
View or change the global Ruby version
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv local\fP [\fI<version>\fP]
|
||||
.RS 4
|
||||
View or change the local Ruby version
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv shell\fP [\fI<version>\fP]
|
||||
.RS 4
|
||||
View or change the Ruby version for the current shell session
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv version\fP
|
||||
.RS 4
|
||||
View the currently active Ruby version and where it is set from
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv versions\fP
|
||||
.RS 4
|
||||
List all locally installed Ruby versions known to rbenv
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv install\fP [\fI<version>\fP]
|
||||
.RS 4
|
||||
(Provided by the \fBruby\-build\fP plugin) Download and install a new Ruby version
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv rehash\fP
|
||||
.RS 4
|
||||
Regenerate shims for all known Ruby executables
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv which\fP [\fI<command>\fP]
|
||||
.RS 4
|
||||
View the executable path that a command resolves to
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv init\fP
|
||||
.RS 4
|
||||
Help bootstrap rbenv into the current shell environment
|
||||
.RE
|
||||
.sp
|
||||
\fBrbenv help\fP [\fI<command>\fP]
|
||||
.RS 4
|
||||
View help text for any rbenv command
|
||||
.RE
|
||||
.SH "ENVIRONMENT VARIABLES"
|
||||
.sp
|
||||
\fBRBENV_VERSION\fP (default: read from \fI.ruby\-version\fP file)
|
||||
.RS 4
|
||||
The Ruby version name to be used
|
||||
.RE
|
||||
.sp
|
||||
\fBRBENV_ROOT\fP (default: \fI~/.rbenv\fP)
|
||||
.RS 4
|
||||
The location where rbenv discovers Ruby versions, plugins, and other configuration
|
||||
.RE
|
||||
.sp
|
||||
\fBRBENV_DEBUG\fP
|
||||
.RS 4
|
||||
Activates printing debug information about rbenv internals to standard error
|
||||
.RE
|
||||
.sp
|
||||
\fBRBENV_HOOK_PATH\fP
|
||||
.RS 4
|
||||
Colon\-separated list of paths searched for rbenv plugin scripts
|
||||
.RE
|
||||
.sp
|
||||
\fBRBENV_DIR\fP (default: \fI$PWD\fP)
|
||||
.RS 4
|
||||
Directory to traverse bottom\-up to locate the \fI.ruby\-version\fP file
|
||||
.RE
|
||||
.SH "PLUGINS"
|
||||
.sp
|
||||
As its core functionality, rbenv only switches between Ruby versions and does nothing else, but offers a plugin mechanism to hook into and override almost any aspect of its default behavior.
|
||||
.sp
|
||||
The most common plugin for rbenv is \fBruby\-build\fP which facilitates installing new Ruby versions into the \fI$RBENV_ROOT/versions\fP directory.
|
||||
.sp
|
||||
Read more at \c
|
||||
.URL "https://github.com/rbenv/rbenv/wiki/Plugins" "" ""
|
||||
.SH "NOTES"
|
||||
.sp
|
||||
.RS 4
|
||||
.ie n \{\
|
||||
\h'-04'\(bu\h'+03'\c
|
||||
.\}
|
||||
.el \{\
|
||||
. sp -1
|
||||
. IP \(bu 2.3
|
||||
.\}
|
||||
.URL "https://github.com/rbenv/rbenv/discussions" "" ""
|
||||
.RE
|
||||
.sp
|
||||
.RS 4
|
||||
.ie n \{\
|
||||
\h'-04'\(bu\h'+03'\c
|
||||
.\}
|
||||
.el \{\
|
||||
. sp -1
|
||||
. IP \(bu 2.3
|
||||
.\}
|
||||
.URL "https://github.com/rbenv/rbenv/wiki" "" ""
|
||||
.RE
|
||||
.sp
|
||||
.RS 4
|
||||
.ie n \{\
|
||||
\h'-04'\(bu\h'+03'\c
|
||||
.\}
|
||||
.el \{\
|
||||
. sp -1
|
||||
. IP \(bu 2.3
|
||||
.\}
|
||||
.URL "https://github.com/rbenv/ruby\-build#readme" "" ""
|
||||
.RE
|
||||
.SH "AUTHOR"
|
||||
.sp
|
||||
Mislav Marohnić
|
||||
87
share/man/man1/rbenv.1.adoc
Normal file
87
share/man/man1/rbenv.1.adoc
Normal file
@@ -0,0 +1,87 @@
|
||||
= rbenv(1)
|
||||
Mislav Marohnić
|
||||
:doctype: manpage
|
||||
:man manual: Rbenv Manual
|
||||
:man source: rbenv {version}
|
||||
:man-linkstyle: pass:[blue R < >]
|
||||
|
||||
== Name
|
||||
|
||||
rbenv - manage your application's Ruby environment
|
||||
|
||||
== Synopsis
|
||||
|
||||
*rbenv* _<command>_ [_<args>_...]
|
||||
|
||||
== Description
|
||||
|
||||
rbenv respects the _.ruby-version_ file in a project directory by making sure that any *ruby*, *gem*, *bundle*, or other Ruby command invocation automatically invokes the Ruby version configured for that project.
|
||||
|
||||
It does so by generating shims for all Ruby executables. As long as rbenv shims directory is prepended to PATH, rbenv automatically ensures transparent switching between Ruby versions.
|
||||
|
||||
rbenv looks for available Ruby versions in the _$RBENV_ROOT/versions_ directory.
|
||||
|
||||
== Commands
|
||||
|
||||
*rbenv global* [_<version>_]::
|
||||
View or change the global Ruby version
|
||||
|
||||
*rbenv local* [_<version>_]::
|
||||
View or change the local Ruby version
|
||||
|
||||
*rbenv shell* [_<version>_]::
|
||||
View or change the Ruby version for the current shell session
|
||||
|
||||
*rbenv version*::
|
||||
View the currently active Ruby version and where it is set from
|
||||
|
||||
*rbenv versions*::
|
||||
List all locally installed Ruby versions known to rbenv
|
||||
|
||||
*rbenv install* [_<version>_]::
|
||||
(Provided by the *ruby-build* plugin) Download and install a new Ruby version
|
||||
|
||||
*rbenv rehash*::
|
||||
Regenerate shims for all known Ruby executables
|
||||
|
||||
*rbenv which* [_<command>_]::
|
||||
View the executable path that a command resolves to
|
||||
|
||||
*rbenv init*::
|
||||
Help bootstrap rbenv into the current shell environment
|
||||
|
||||
*rbenv help* [_<command>_]::
|
||||
View help text for any rbenv command
|
||||
|
||||
== Environment Variables
|
||||
|
||||
*RBENV_VERSION* (default: read from _.ruby-version_ file)::
|
||||
The Ruby version name to be used
|
||||
|
||||
*RBENV_ROOT* (default: _~/.rbenv_)::
|
||||
The location where rbenv discovers Ruby versions, plugins, and other configuration
|
||||
|
||||
*RBENV_DEBUG*::
|
||||
Activates printing debug information about rbenv internals to standard error
|
||||
|
||||
*RBENV_HOOK_PATH*::
|
||||
Colon-separated list of paths searched for rbenv plugin scripts
|
||||
|
||||
*RBENV_DIR* (default: _$PWD_)::
|
||||
Directory to traverse bottom-up to locate the _.ruby-version_ file
|
||||
|
||||
== Plugins
|
||||
|
||||
As its core functionality, rbenv only switches between Ruby versions and does nothing else, but offers a plugin mechanism to hook into and override almost any aspect of its default behavior.
|
||||
|
||||
The most common plugin for rbenv is *ruby-build* which facilitates installing new Ruby versions into the _$RBENV_ROOT/versions_ directory.
|
||||
|
||||
Read more at https://github.com/rbenv/rbenv/wiki/Plugins
|
||||
|
||||
== Notes
|
||||
|
||||
* https://github.com/rbenv/rbenv/discussions
|
||||
|
||||
* https://github.com/rbenv/rbenv/wiki
|
||||
|
||||
* https://github.com/rbenv/ruby-build#readme
|
||||
8
src/Makefile.in
Normal file
8
src/Makefile.in
Normal file
@@ -0,0 +1,8 @@
|
||||
../libexec/rbenv-realpath.dylib:
|
||||
@echo "Warning: this Makefile is obsolete and kept only for backwards compatibility." >&2
|
||||
@echo "You can remove the \`configure && make ...' step from your rbenv setup." >&2
|
||||
|
||||
clean:
|
||||
rm -f *.o ../libexec/*.dylib
|
||||
|
||||
.PHONY: ../libexec/rbenv-realpath.dylib clean
|
||||
7
src/configure
vendored
Executable file
7
src/configure
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Warning: this configure script is obsolete and kept only for backwards compatibility.
|
||||
set -e
|
||||
|
||||
src_dir="${0%/*}"
|
||||
|
||||
cp "$src_dir"/Makefile.in "$src_dir"/Makefile
|
||||
55
test/--version.bats
Normal file
55
test/--version.bats
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
export GIT_DIR="${RBENV_TEST_DIR}/.git"
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME"
|
||||
git config --global user.name "Tester"
|
||||
git config --global user.email "tester@test.local"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
git commit --quiet --allow-empty -m "empty"
|
||||
}
|
||||
|
||||
@test "default version" {
|
||||
assert [ ! -e "$RBENV_ROOT" ]
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "doesn't read version from non-rbenv repo" {
|
||||
git init
|
||||
git remote add origin https://github.com/homebrew/homebrew.git
|
||||
git_commit
|
||||
git tag v1.0
|
||||
|
||||
run rbenv---version
|
||||
assert_success
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "reads version from git repo" {
|
||||
git init
|
||||
git remote add origin https://github.com/rbenv/rbenv.git
|
||||
git_commit
|
||||
git tag v0.4.1
|
||||
git_commit
|
||||
git_commit
|
||||
|
||||
run rbenv---version
|
||||
assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
@test "prints default version if no tags in git repo" {
|
||||
git init
|
||||
git remote add origin https://github.com/rbenv/rbenv.git
|
||||
git_commit
|
||||
|
||||
run rbenv---version
|
||||
[[ $output == "rbenv "?.?.? ]]
|
||||
}
|
||||
39
test/commands.bats
Normal file
39
test/commands.bats
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "commands" {
|
||||
run rbenv-commands
|
||||
assert_success
|
||||
assert_line "init"
|
||||
assert_line "rehash"
|
||||
assert_line "shell"
|
||||
refute_line "sh-shell"
|
||||
assert_line "echo"
|
||||
}
|
||||
|
||||
@test "commands --sh" {
|
||||
run rbenv-commands --sh
|
||||
assert_success
|
||||
refute_line "init"
|
||||
assert_line "shell"
|
||||
}
|
||||
|
||||
@test "commands in path with spaces" {
|
||||
path="${RBENV_TEST_DIR}/my commands"
|
||||
cmd="${path}/rbenv-sh-hello"
|
||||
mkdir -p "$path"
|
||||
touch "$cmd"
|
||||
chmod +x "$cmd"
|
||||
|
||||
PATH="${path}:$PATH" run rbenv-commands --sh
|
||||
assert_success
|
||||
assert_line "hello"
|
||||
}
|
||||
|
||||
@test "commands --no-sh" {
|
||||
run rbenv-commands --no-sh
|
||||
assert_success
|
||||
assert_line "init"
|
||||
refute_line "shell"
|
||||
}
|
||||
51
test/completions.bats
Normal file
51
test/completions.bats
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_command() {
|
||||
bin="${RBENV_TEST_DIR}/bin"
|
||||
mkdir -p "$bin"
|
||||
echo "$2" > "${bin}/$1"
|
||||
chmod +x "${bin}/$1"
|
||||
}
|
||||
|
||||
@test "command with no completion support" {
|
||||
create_command "rbenv-hello" "#!$BASH
|
||||
echo hello"
|
||||
run rbenv-completions hello
|
||||
assert_success "--help"
|
||||
}
|
||||
|
||||
@test "command with completion support" {
|
||||
create_command "rbenv-hello" "#!$BASH
|
||||
# Provide rbenv completions
|
||||
if [[ \$1 = --complete ]]; then
|
||||
echo hello
|
||||
else
|
||||
exit 1
|
||||
fi"
|
||||
run rbenv-completions hello
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
--help
|
||||
hello
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "forwards extra arguments" {
|
||||
create_command "rbenv-hello" "#!$BASH
|
||||
# provide rbenv completions
|
||||
if [[ \$1 = --complete ]]; then
|
||||
shift 1
|
||||
for arg; do echo \$arg; done
|
||||
else
|
||||
exit 1
|
||||
fi"
|
||||
run rbenv-completions hello happy world
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
--help
|
||||
happy
|
||||
world
|
||||
OUT
|
||||
}
|
||||
109
test/exec.bats
Normal file
109
test/exec.bats
Normal file
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
name="${1?}"
|
||||
shift 1
|
||||
bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin"
|
||||
mkdir -p "$bin"
|
||||
{ if [ $# -eq 0 ]; then cat -
|
||||
else echo "$@"
|
||||
fi
|
||||
} | sed -Ee '1s/^ +//' > "${bin}/$name"
|
||||
chmod +x "${bin}/$name"
|
||||
}
|
||||
|
||||
@test "fails with invalid version" {
|
||||
export RBENV_VERSION="2.0"
|
||||
run rbenv-exec ruby -v
|
||||
assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "fails with invalid version set from file" {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
echo 1.9 > .ruby-version
|
||||
run rbenv-exec rspec
|
||||
assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)"
|
||||
}
|
||||
|
||||
@test "completes with names of executables" {
|
||||
export RBENV_VERSION="2.0"
|
||||
create_executable "ruby" "#!/bin/sh"
|
||||
create_executable "rake" "#!/bin/sh"
|
||||
|
||||
rbenv-rehash
|
||||
run rbenv-completions exec
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
--help
|
||||
rake
|
||||
ruby
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook exec hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export RBENV_VERSION=system
|
||||
IFS=$' \t\n' run rbenv-exec env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "forwards all arguments" {
|
||||
export RBENV_VERSION="2.0"
|
||||
create_executable "ruby" <<SH
|
||||
#!$BASH
|
||||
echo \$0
|
||||
for arg; do
|
||||
# hack to avoid bash builtin echo which can't output '-e'
|
||||
printf " %s\\n" "\$arg"
|
||||
done
|
||||
SH
|
||||
|
||||
run rbenv-exec ruby -w "/path to/ruby script.rb" -- extra args
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_ROOT}/versions/2.0/bin/ruby
|
||||
-w
|
||||
/path to/ruby script.rb
|
||||
--
|
||||
extra
|
||||
args
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports ruby -S <cmd>" {
|
||||
export RBENV_VERSION="2.0"
|
||||
|
||||
# emulate `ruby -S' behavior
|
||||
create_executable "ruby" <<SH
|
||||
#!$BASH
|
||||
if [[ \$1 == "-S"* ]]; then
|
||||
found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)"
|
||||
# assert that the found executable has ruby for shebang
|
||||
if head -n1 "\$found" | grep ruby >/dev/null; then
|
||||
\$BASH "\$found"
|
||||
else
|
||||
echo "ruby: no Ruby script found in input (LoadError)" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo 'ruby 2.0 (rbenv test)'
|
||||
fi
|
||||
SH
|
||||
|
||||
create_executable "rake" <<SH
|
||||
#!/usr/bin/env ruby
|
||||
echo hello rake
|
||||
SH
|
||||
|
||||
rbenv-rehash
|
||||
run ruby -S rake
|
||||
assert_success "hello rake"
|
||||
}
|
||||
31
test/global.bats
Normal file
31
test/global.bats
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "default" {
|
||||
run rbenv-global
|
||||
assert_success
|
||||
assert_output "system"
|
||||
}
|
||||
|
||||
@test "read RBENV_ROOT/version" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
echo "1.2.3" > "$RBENV_ROOT/version"
|
||||
run rbenv-global
|
||||
assert_success
|
||||
assert_output "1.2.3"
|
||||
}
|
||||
|
||||
@test "set RBENV_ROOT/version" {
|
||||
mkdir -p "$RBENV_ROOT/versions/1.2.3"
|
||||
run rbenv-global "1.2.3"
|
||||
assert_success
|
||||
run rbenv-global
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "fail setting invalid RBENV_ROOT/version" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
run rbenv-global "1.2.3"
|
||||
assert_failure "rbenv: version \`1.2.3' not installed"
|
||||
}
|
||||
133
test/help.bats
Normal file
133
test/help.bats
Normal file
@@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "without args shows summary of common commands" {
|
||||
run rbenv-help
|
||||
assert_success
|
||||
assert_line "Usage: rbenv <command> [<args>...]"
|
||||
assert_line "Commands to manage available Ruby versions:"
|
||||
}
|
||||
|
||||
@test "usage flag" {
|
||||
run rbenv-help --usage
|
||||
assert_success
|
||||
assert_output "Usage: rbenv <command> [<args>...]"
|
||||
}
|
||||
|
||||
@test "invalid command" {
|
||||
run rbenv-help hello
|
||||
assert_failure "rbenv: no such command \`hello'"
|
||||
}
|
||||
|
||||
@test "shows help for a specific command" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This command is useful for saying hello.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This command is useful for saying hello.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "replaces missing extended help with summary text" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
Says "hello" to you, from rbenv
|
||||
SH
|
||||
}
|
||||
|
||||
@test "extracts only usage" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This extended help won't be shown.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help --usage hello
|
||||
assert_success "Usage: rbenv hello <world>"
|
||||
}
|
||||
|
||||
@test "empty usage section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help --usage hello
|
||||
assert_success "Usage: rbenv hello"
|
||||
}
|
||||
|
||||
@test "multiline usage section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# rbenv hi [everybody]
|
||||
# rbenv hola --translate
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# Help text.
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
rbenv hi [everybody]
|
||||
rbenv hola --translate
|
||||
|
||||
Help text.
|
||||
SH
|
||||
}
|
||||
|
||||
@test "multiline extended help section" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH
|
||||
#!shebang
|
||||
# Usage: rbenv hello <world>
|
||||
# Summary: Says "hello" to you, from rbenv
|
||||
# This is extended help text.
|
||||
# It can contain multiple lines.
|
||||
#
|
||||
# And paragraphs.
|
||||
|
||||
echo hello
|
||||
SH
|
||||
|
||||
run rbenv-help hello
|
||||
assert_success
|
||||
assert_output <<SH
|
||||
Usage: rbenv hello <world>
|
||||
|
||||
This is extended help text.
|
||||
It can contain multiple lines.
|
||||
|
||||
And paragraphs.
|
||||
SH
|
||||
}
|
||||
70
test/hooks.bats
Normal file
70
test/hooks.bats
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "prints usage help given no argument" {
|
||||
run rbenv-hooks
|
||||
assert_failure "Usage: rbenv hooks <command>"
|
||||
}
|
||||
|
||||
@test "prints list of hooks" {
|
||||
path1="${RBENV_TEST_DIR}/rbenv.d"
|
||||
path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
|
||||
RBENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
create_hook exec "ahoy.bash"
|
||||
create_hook exec "invalid.sh"
|
||||
create_hook which "boom.bash"
|
||||
RBENV_HOOK_PATH="$path2"
|
||||
create_hook exec "bueno.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports hook paths with spaces" {
|
||||
path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
|
||||
path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
|
||||
RBENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
RBENV_HOOK_PATH="$path2"
|
||||
create_hook exec "ahoy.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "does not canonicalize paths" {
|
||||
RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d"
|
||||
create_hook exec "hello.bash"
|
||||
mkdir -p "$HOME"
|
||||
|
||||
RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
|
||||
assert_success "${RBENV_TEST_DIR}/home/../rbenv.d/exec/hello.bash"
|
||||
}
|
||||
|
||||
@test "does not resolve symlinks" {
|
||||
path="${RBENV_TEST_DIR}/rbenv.d"
|
||||
mkdir -p "${path}/exec"
|
||||
mkdir -p "$HOME"
|
||||
touch "${HOME}/hola.bash"
|
||||
ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
|
||||
touch "${path}/exec/bright.sh"
|
||||
ln -s "bright.sh" "${path}/exec/world.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/world.bash
|
||||
OUT
|
||||
}
|
||||
164
test/init.bats
Executable file
164
test/init.bats
Executable file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "creates shims and versions directories" {
|
||||
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-init -
|
||||
assert_success
|
||||
assert [ -d "${RBENV_ROOT}/shims" ]
|
||||
assert [ -d "${RBENV_ROOT}/versions" ]
|
||||
}
|
||||
|
||||
@test "auto rehash" {
|
||||
run rbenv-init -
|
||||
assert_success
|
||||
assert_line "command rbenv rehash 2>/dev/null"
|
||||
}
|
||||
|
||||
@test "setup shell completions" {
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
run rbenv-init - bash
|
||||
assert_success
|
||||
assert_line "source '${root}/test/../completions/rbenv.bash'"
|
||||
}
|
||||
|
||||
@test "detect parent shell" {
|
||||
SHELL=/bin/false run rbenv-init -
|
||||
assert_success
|
||||
assert_line "export RBENV_SHELL=bash"
|
||||
}
|
||||
|
||||
@test "detect parent shell from script" {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
cat > myscript.sh <<OUT
|
||||
#!/bin/sh
|
||||
eval "\$(rbenv-init -)"
|
||||
echo \$RBENV_SHELL
|
||||
OUT
|
||||
chmod +x myscript.sh
|
||||
run ./myscript.sh
|
||||
assert_success "sh"
|
||||
}
|
||||
|
||||
@test "skip shell completions (fish)" {
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
run rbenv-init - fish
|
||||
assert_success
|
||||
local line="$(grep '^source' <<<"$output")"
|
||||
[ -z "$line" ] || flunk "did not expect line: $line"
|
||||
}
|
||||
|
||||
@test "set up bash" {
|
||||
assert [ ! -e ~/.bash_profile ]
|
||||
run rbenv-init bash
|
||||
assert_success "writing ~/.bash_profile: now configured for rbenv."
|
||||
run cat ~/.bash_profile
|
||||
# shellcheck disable=SC2016
|
||||
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
||||
}
|
||||
|
||||
@test "set up bash (bashrc)" {
|
||||
mkdir -p "$HOME"
|
||||
touch ~/.bashrc
|
||||
assert [ ! -e ~/.bash_profile ]
|
||||
run rbenv-init bash
|
||||
assert_success "writing ~/.bashrc: now configured for rbenv."
|
||||
run cat ~/.bashrc
|
||||
# shellcheck disable=SC2016
|
||||
assert_line 'eval "$(rbenv init - --no-rehash bash)"'
|
||||
}
|
||||
|
||||
@test "set up zsh" {
|
||||
unset ZDOTDIR
|
||||
assert [ ! -e ~/.zprofile ]
|
||||
run rbenv-init zsh
|
||||
assert_success "writing ~/.zprofile: now configured for rbenv."
|
||||
run cat ~/.zprofile
|
||||
# shellcheck disable=SC2016
|
||||
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
||||
}
|
||||
|
||||
@test "set up zsh (zshrc)" {
|
||||
unset ZDOTDIR
|
||||
mkdir -p "$HOME"
|
||||
cat > ~/.zshrc <<<"# rbenv"
|
||||
run rbenv-init zsh
|
||||
assert_success "writing ~/.zshrc: now configured for rbenv."
|
||||
run cat ~/.zshrc
|
||||
# shellcheck disable=SC2016
|
||||
assert_line 'eval "$(rbenv init - --no-rehash zsh)"'
|
||||
}
|
||||
|
||||
@test "set up fish" {
|
||||
unset XDG_CONFIG_HOME
|
||||
run rbenv-init fish
|
||||
assert_success "writing ~/.config/fish/config.fish: now configured for rbenv."
|
||||
run cat ~/.config/fish/config.fish
|
||||
assert_line 'status --is-interactive; and rbenv init - --no-rehash fish | source'
|
||||
}
|
||||
|
||||
@test "set up multiple shells at once" {
|
||||
unset ZDOTDIR
|
||||
unset XDG_CONFIG_HOME
|
||||
run rbenv-init bash zsh fish
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
writing ~/.bash_profile: now configured for rbenv.
|
||||
writing ~/.zprofile: now configured for rbenv.
|
||||
writing ~/.config/fish/config.fish: now configured for rbenv.
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "option to skip rehash" {
|
||||
run rbenv-init - --no-rehash
|
||||
assert_success
|
||||
refute_line "rbenv rehash 2>/dev/null"
|
||||
}
|
||||
|
||||
@test "adds shims to PATH" {
|
||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||
run rbenv-init - bash
|
||||
assert_success
|
||||
assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
||||
}
|
||||
|
||||
@test "adds shims to PATH (fish)" {
|
||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||
run rbenv-init - fish
|
||||
assert_success
|
||||
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
||||
}
|
||||
|
||||
@test "can add shims to PATH more than once" {
|
||||
export PATH="${RBENV_ROOT}/shims:$PATH"
|
||||
run rbenv-init - bash
|
||||
assert_success
|
||||
assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
|
||||
}
|
||||
|
||||
@test "can add shims to PATH more than once (fish)" {
|
||||
export PATH="${RBENV_ROOT}/shims:$PATH"
|
||||
run rbenv-init - fish
|
||||
assert_success
|
||||
assert_line 0 "set -gx PATH '${RBENV_ROOT}/shims' \$PATH"
|
||||
}
|
||||
|
||||
@test "outputs sh-compatible syntax" {
|
||||
run rbenv-init - bash
|
||||
assert_success
|
||||
assert_line ' case "$command" in'
|
||||
|
||||
run rbenv-init - zsh
|
||||
assert_success
|
||||
assert_line ' case "$command" in'
|
||||
}
|
||||
|
||||
@test "outputs fish-specific syntax (fish)" {
|
||||
run rbenv-init - fish
|
||||
assert_success
|
||||
assert_line ' switch "$command"'
|
||||
refute_line ' case "$command" in'
|
||||
}
|
||||
9
test/libexec/rbenv-echo
Executable file
9
test/libexec/rbenv-echo
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: rbenv echo [-F<char>] VAR
|
||||
|
||||
if [[ $1 == -F* ]]; then
|
||||
sep="${1:2}"
|
||||
echo "${!2}" | tr "${sep:-:}" $'\n'
|
||||
else
|
||||
echo "${!1}"
|
||||
fi
|
||||
59
test/local.bats
Normal file
59
test/local.bats
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||
cd "${RBENV_TEST_DIR}/myproject"
|
||||
}
|
||||
|
||||
@test "no version" {
|
||||
assert [ ! -e "${PWD}/.ruby-version" ]
|
||||
run rbenv-local
|
||||
assert_failure "rbenv: no local version configured for this directory"
|
||||
}
|
||||
|
||||
@test "local version" {
|
||||
echo "1.2.3" > .ruby-version
|
||||
run rbenv-local
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "discovers version file in parent directory" {
|
||||
echo "1.2.3" > .ruby-version
|
||||
mkdir -p "subdir" && cd "subdir"
|
||||
run rbenv-local
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "ignores RBENV_DIR" {
|
||||
echo "1.2.3" > .ruby-version
|
||||
mkdir -p "$HOME"
|
||||
echo "2.0-home" > "${HOME}/.ruby-version"
|
||||
RBENV_DIR="$HOME" run rbenv-local
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "sets local version" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
run rbenv-local 1.2.3
|
||||
assert_success ""
|
||||
assert [ "$(cat .ruby-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "changes local version" {
|
||||
echo "1.0-pre" > .ruby-version
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
run rbenv-local
|
||||
assert_success "1.0-pre"
|
||||
run rbenv-local 1.2.3
|
||||
assert_success ""
|
||||
assert [ "$(cat .ruby-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "unsets local version" {
|
||||
touch .ruby-version
|
||||
run rbenv-local --unset
|
||||
assert_success ""
|
||||
assert [ ! -e .ruby-version ]
|
||||
}
|
||||
45
test/prefix.bats
Normal file
45
test/prefix.bats
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "prefix" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||
cd "${RBENV_TEST_DIR}/myproject"
|
||||
echo "1.2.3" > .ruby-version
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
run rbenv-prefix
|
||||
assert_success "${RBENV_ROOT}/versions/1.2.3"
|
||||
}
|
||||
|
||||
@test "prefix for invalid version" {
|
||||
RBENV_VERSION="1.2.3" run rbenv-prefix
|
||||
assert_failure "rbenv: version \`1.2.3' not installed"
|
||||
}
|
||||
|
||||
@test "prefix for system" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||
touch "${RBENV_TEST_DIR}/bin/ruby"
|
||||
chmod +x "${RBENV_TEST_DIR}/bin/ruby"
|
||||
RBENV_VERSION="system" run rbenv-prefix
|
||||
assert_success "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "prefix for system in /" {
|
||||
mkdir -p "${BATS_TEST_DIRNAME}/libexec"
|
||||
cat >"${BATS_TEST_DIRNAME}/libexec/rbenv-which" <<OUT
|
||||
#!/bin/sh
|
||||
echo /bin/ruby
|
||||
OUT
|
||||
chmod +x "${BATS_TEST_DIRNAME}/libexec/rbenv-which"
|
||||
RBENV_VERSION="system" run rbenv-prefix
|
||||
assert_success "/"
|
||||
rm -f "${BATS_TEST_DIRNAME}/libexec/rbenv-which"
|
||||
}
|
||||
|
||||
@test "prefix for invalid system" {
|
||||
PATH="$(path_without ruby)" run rbenv-prefix system
|
||||
assert_failure <<EOF
|
||||
rbenv: ruby: command not found
|
||||
rbenv: system version not found in PATH"
|
||||
EOF
|
||||
}
|
||||
82
test/rbenv.bats
Normal file
82
test/rbenv.bats
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "blank invocation" {
|
||||
run rbenv
|
||||
assert_failure
|
||||
assert_line 0 "$(rbenv---version)"
|
||||
}
|
||||
|
||||
@test "invalid command" {
|
||||
run rbenv does-not-exist
|
||||
assert_failure
|
||||
assert_output "rbenv: no such command \`does-not-exist'"
|
||||
}
|
||||
|
||||
@test "default RBENV_ROOT" {
|
||||
RBENV_ROOT="" HOME=/home/mislav run rbenv root
|
||||
assert_success
|
||||
assert_output "/home/mislav/.rbenv"
|
||||
}
|
||||
|
||||
@test "inherited RBENV_ROOT" {
|
||||
RBENV_ROOT=/opt/rbenv run rbenv root
|
||||
assert_success
|
||||
assert_output "/opt/rbenv"
|
||||
}
|
||||
|
||||
@test "default RBENV_DIR" {
|
||||
run rbenv echo RBENV_DIR
|
||||
assert_output "$(pwd)"
|
||||
}
|
||||
|
||||
@test "inherited RBENV_DIR" {
|
||||
dir="${BATS_TMPDIR}/myproject"
|
||||
mkdir -p "$dir"
|
||||
RBENV_DIR="$dir" run rbenv echo RBENV_DIR
|
||||
assert_output "$dir"
|
||||
}
|
||||
|
||||
@test "invalid RBENV_DIR" {
|
||||
dir="${BATS_TMPDIR}/does-not-exist"
|
||||
assert [ ! -d "$dir" ]
|
||||
RBENV_DIR="$dir" run rbenv echo RBENV_DIR
|
||||
assert_failure
|
||||
assert_output "rbenv: cannot change working directory to \`$dir'"
|
||||
}
|
||||
|
||||
@test "adds its own libexec to PATH" {
|
||||
run rbenv echo "PATH"
|
||||
assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH"
|
||||
}
|
||||
|
||||
@test "adds plugin bin dirs to PATH" {
|
||||
mkdir -p "$RBENV_ROOT"/plugins/ruby-build/bin
|
||||
mkdir -p "$RBENV_ROOT"/plugins/rbenv-each/bin
|
||||
run rbenv echo -F: "PATH"
|
||||
assert_success
|
||||
assert_line 0 "${BATS_TEST_DIRNAME%/*}/libexec"
|
||||
assert_line 1 "${RBENV_ROOT}/plugins/ruby-build/bin"
|
||||
assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin"
|
||||
}
|
||||
|
||||
@test "RBENV_HOOK_PATH includes etc/rbenv.d folders" {
|
||||
mkdir -p "$RBENV_ROOT"/plugins/rbenv-foo/etc/rbenv.d
|
||||
run rbenv echo -F: "RBENV_HOOK_PATH"
|
||||
assert_line 7 "${RBENV_ROOT}/plugins/rbenv-foo/etc/rbenv.d"
|
||||
}
|
||||
|
||||
@test "RBENV_HOOK_PATH preserves value from environment" {
|
||||
RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH"
|
||||
assert_success
|
||||
assert_line 0 "/my/hook/path"
|
||||
assert_line 1 "/other/hooks"
|
||||
assert_line 2 "${RBENV_ROOT}/rbenv.d"
|
||||
}
|
||||
|
||||
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
|
||||
unset RBENV_HOOK_PATH
|
||||
run rbenv echo "RBENV_HOOK_PATH"
|
||||
assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/etc/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
|
||||
}
|
||||
163
test/rehash.bats
Executable file
163
test/rehash.bats
Executable file
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local exe="${RBENV_ROOT}/versions/${1}/bin/${2}"
|
||||
[ -n "$2" ] || exe="$1"
|
||||
mkdir -p "${exe%/*}"
|
||||
touch "$exe"
|
||||
chmod +x "$exe"
|
||||
}
|
||||
|
||||
@test "empty rehash" {
|
||||
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
assert [ -d "${RBENV_ROOT}/shims" ]
|
||||
rmdir "${RBENV_ROOT}/shims"
|
||||
}
|
||||
|
||||
@test "non-writable shims directory" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
chmod -w "${RBENV_ROOT}/shims"
|
||||
run rbenv-rehash
|
||||
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
||||
}
|
||||
|
||||
@test "rehash in progress" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
touch "${RBENV_ROOT}/shims/.rbenv-shim"
|
||||
run rbenv-rehash
|
||||
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
|
||||
}
|
||||
|
||||
@test "creates shims" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.8" "rake"
|
||||
create_executable "2.0" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
run ls "${RBENV_ROOT}/shims"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
rake
|
||||
rspec
|
||||
ruby
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "removes outdated shims" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
touch "${RBENV_ROOT}/shims/oldshim1"
|
||||
chmod +x "${RBENV_ROOT}/shims/oldshim1"
|
||||
|
||||
create_executable "2.0" "rake"
|
||||
create_executable "2.0" "ruby"
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ]
|
||||
}
|
||||
|
||||
@test "do exact matches when removing stale shims" {
|
||||
create_executable "2.0" "unicorn_rails"
|
||||
create_executable "2.0" "rspec-core"
|
||||
|
||||
rbenv-rehash
|
||||
|
||||
cp "$RBENV_ROOT"/shims/{rspec-core,rspec}
|
||||
cp "$RBENV_ROOT"/shims/{rspec-core,rails}
|
||||
cp "$RBENV_ROOT"/shims/{rspec-core,uni}
|
||||
chmod +x "$RBENV_ROOT"/shims/{rspec,rails,uni}
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rails" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/uni" ]
|
||||
}
|
||||
|
||||
@test "binary install locations containing spaces" {
|
||||
create_executable "dirname1 p247" "ruby"
|
||||
create_executable "dirname2 preview1" "rspec"
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
run ls "${RBENV_ROOT}/shims"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
rspec
|
||||
ruby
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "no shims for user-installed gems" {
|
||||
create_executable "2.7.5" "ruby"
|
||||
create_executable "3.1.2" "ruby"
|
||||
create_executable "${HOME}/.gem/ruby/2.7.0/bin/lolcat"
|
||||
create_executable "${HOME}/.gem/ruby/3.1.0/bin/pinecone"
|
||||
|
||||
run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
||||
}
|
||||
|
||||
@test "explicit gem home" {
|
||||
create_executable "${HOME}/mygems/bin/lolcat"
|
||||
create_executable "${HOME}/mygems/bin/pinecone"
|
||||
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/lolcat" ]
|
||||
assert [ ! -e "${RBENV_ROOT}/shims/pinecone" ]
|
||||
|
||||
GEM_HOME="${HOME}/mygems" run rbenv-rehash
|
||||
assert_success ""
|
||||
|
||||
run ls "${RBENV_ROOT}/shims"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
lolcat
|
||||
pinecone
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook rehash hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
exit
|
||||
SH
|
||||
|
||||
IFS=$' \t\n' run rbenv-rehash
|
||||
assert_success
|
||||
assert_output "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "sh-rehash in bash" {
|
||||
create_executable "2.0" "ruby"
|
||||
RBENV_SHELL=bash run rbenv-sh-rehash
|
||||
assert_success "hash -r 2>/dev/null || true"
|
||||
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
||||
}
|
||||
|
||||
@test "sh-rehash in fish" {
|
||||
create_executable "2.0" "ruby"
|
||||
RBENV_SHELL=fish run rbenv-sh-rehash
|
||||
assert_success ""
|
||||
assert [ -x "${RBENV_ROOT}/shims/ruby" ]
|
||||
}
|
||||
4
test/run
Executable file
4
test/run
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
exec bats ${CI:+--tap} "${@:-test}"
|
||||
101
test/shell.bats
Normal file
101
test/shell.bats
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "shell integration disabled" {
|
||||
run rbenv shell
|
||||
assert_failure "rbenv: shell integration not enabled. Run \`rbenv init' for instructions."
|
||||
}
|
||||
|
||||
@test "shell integration enabled" {
|
||||
eval "$(rbenv init -)"
|
||||
run rbenv shell
|
||||
assert_success "rbenv: no shell-specific version configured"
|
||||
}
|
||||
|
||||
@test "no shell version" {
|
||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||
cd "${RBENV_TEST_DIR}/myproject"
|
||||
echo "1.2.3" > .ruby-version
|
||||
RBENV_VERSION="" run rbenv-sh-shell
|
||||
assert_failure "rbenv: no shell-specific version configured"
|
||||
}
|
||||
|
||||
@test "shell version" {
|
||||
RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell
|
||||
assert_success 'echo "$RBENV_VERSION"'
|
||||
}
|
||||
|
||||
@test "shell version (fish)" {
|
||||
RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell
|
||||
assert_success 'echo "$RBENV_VERSION"'
|
||||
}
|
||||
|
||||
@test "shell revert" {
|
||||
RBENV_SHELL=bash run rbenv-sh-shell -
|
||||
assert_success
|
||||
assert_line 0 'if [ -n "${RBENV_VERSION_OLD+x}" ]; then'
|
||||
}
|
||||
|
||||
@test "shell revert (fish)" {
|
||||
RBENV_SHELL=fish run rbenv-sh-shell -
|
||||
assert_success
|
||||
assert_line 0 'if set -q RBENV_VERSION_OLD'
|
||||
}
|
||||
|
||||
@test "shell unset" {
|
||||
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||
unset RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell unset (fish)" {
|
||||
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||
set -e RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change invalid version" {
|
||||
run rbenv-sh-shell 1.2.3
|
||||
assert_failure
|
||||
assert_output <<SH
|
||||
rbenv: version \`1.2.3' not installed
|
||||
false
|
||||
SH
|
||||
}
|
||||
|
||||
@test "shell change version" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||
export RBENV_VERSION="1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version (zsh)" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=zsh run rbenv-sh-shell 1.2.3
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
typeset -g RBENV_VERSION_OLD="\${RBENV_VERSION-}"
|
||||
export RBENV_VERSION="1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version (fish)" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=fish run rbenv-sh-shell 1.2.3
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
||||
set -gx RBENV_VERSION "1.2.3"
|
||||
OUT
|
||||
}
|
||||
29
test/shims.bats
Normal file
29
test/shims.bats
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "no shims" {
|
||||
run rbenv-shims
|
||||
assert_success
|
||||
assert [ -z "$output" ]
|
||||
}
|
||||
|
||||
@test "shims" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
touch "${RBENV_ROOT}/shims/ruby"
|
||||
touch "${RBENV_ROOT}/shims/irb"
|
||||
run rbenv-shims
|
||||
assert_success
|
||||
assert_line "${RBENV_ROOT}/shims/ruby"
|
||||
assert_line "${RBENV_ROOT}/shims/irb"
|
||||
}
|
||||
|
||||
@test "shims --short" {
|
||||
mkdir -p "${RBENV_ROOT}/shims"
|
||||
touch "${RBENV_ROOT}/shims/ruby"
|
||||
touch "${RBENV_ROOT}/shims/irb"
|
||||
run rbenv-shims --short
|
||||
assert_success
|
||||
assert_line "irb"
|
||||
assert_line "ruby"
|
||||
}
|
||||
131
test/test_helper.bash
Normal file
131
test/test_helper.bash
Normal file
@@ -0,0 +1,131 @@
|
||||
unset RBENV_VERSION
|
||||
unset RBENV_DIR
|
||||
|
||||
# guard against executing this block twice due to bats internals
|
||||
if [ -z "$RBENV_TEST_DIR" ]; then
|
||||
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
|
||||
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
|
||||
|
||||
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
|
||||
export HOME="${RBENV_TEST_DIR}/home"
|
||||
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
|
||||
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||||
PATH="${RBENV_TEST_DIR}/bin:$PATH"
|
||||
PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH"
|
||||
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
||||
PATH="${RBENV_ROOT}/shims:$PATH"
|
||||
export PATH
|
||||
|
||||
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
|
||||
unset xdg_var
|
||||
fi
|
||||
|
||||
teardown() {
|
||||
rm -rf "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
flunk() {
|
||||
{ if [ "$#" -eq 0 ]; then cat -
|
||||
else echo "$@"
|
||||
fi
|
||||
} | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
assert_success() {
|
||||
if [ "$status" -ne 0 ]; then
|
||||
flunk "command failed with exit status $status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_failure() {
|
||||
if [ "$status" -eq 0 ]; then
|
||||
flunk "expected failed exit status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_equal() {
|
||||
if [ "$1" != "$2" ]; then
|
||||
{ echo "expected: $1"
|
||||
echo "actual: $2"
|
||||
} | flunk
|
||||
fi
|
||||
}
|
||||
|
||||
assert_output() {
|
||||
local expected
|
||||
if [ $# -eq 0 ]; then expected="$(cat -)"
|
||||
else expected="$1"
|
||||
fi
|
||||
assert_equal "$expected" "$output"
|
||||
}
|
||||
|
||||
assert_line() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
assert_equal "$2" "${lines[$1]}"
|
||||
else
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then return 0; fi
|
||||
done
|
||||
flunk "expected line \`$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
refute_line() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
local num_lines="${#lines[@]}"
|
||||
if [ "$1" -lt "$num_lines" ]; then
|
||||
flunk "output has $num_lines lines"
|
||||
fi
|
||||
else
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then
|
||||
flunk "expected to not find line \`$line'"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
assert() {
|
||||
if ! "$@"; then
|
||||
flunk "failed: $@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Output a modified PATH that ensures that the given executable is not present,
|
||||
# but in which system utils necessary for rbenv operation are still available.
|
||||
path_without() {
|
||||
local exe="$1"
|
||||
local path=":${PATH}:"
|
||||
local found alt util
|
||||
for found in $(type -aP "$exe"); do
|
||||
found="${found%/*}"
|
||||
if [ "$found" != "${RBENV_ROOT}/shims" ]; then
|
||||
alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
|
||||
mkdir -p "$alt"
|
||||
for util in bash head cut readlink greadlink sed sort awk; do
|
||||
if [ -x "${found}/$util" ]; then
|
||||
ln -s "${found}/$util" "${alt}/$util"
|
||||
fi
|
||||
done
|
||||
path="${path/:${found}:/:${alt}:}"
|
||||
fi
|
||||
done
|
||||
path="${path#:}"
|
||||
echo "${path%:}"
|
||||
}
|
||||
|
||||
create_hook() {
|
||||
mkdir -p "${RBENV_HOOK_PATH}/$1"
|
||||
touch "${RBENV_HOOK_PATH}/$1/$2"
|
||||
if [ ! -t 0 ]; then
|
||||
cat > "${RBENV_HOOK_PATH}/$1/$2"
|
||||
fi
|
||||
}
|
||||
88
test/version-file-read.bats
Normal file
88
test/version-file-read.bats
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "${RBENV_TEST_DIR}/myproject"
|
||||
cd "${RBENV_TEST_DIR}/myproject"
|
||||
}
|
||||
|
||||
@test "fails without arguments" {
|
||||
run rbenv-version-file-read
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "fails for invalid file" {
|
||||
run rbenv-version-file-read "non-existent"
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "fails for blank file" {
|
||||
echo > my-version
|
||||
run rbenv-version-file-read my-version
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@test "reads simple version file" {
|
||||
cat > my-version <<<"1.9.3"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "ignores leading spaces" {
|
||||
cat > my-version <<<" 1.9.3"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "reads only the first word from file" {
|
||||
cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3-p194@tag"
|
||||
}
|
||||
|
||||
@test "loads only the first line in file" {
|
||||
cat > my-version <<IN
|
||||
1.8.7 one
|
||||
1.9.3 two
|
||||
IN
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.8.7"
|
||||
}
|
||||
|
||||
@test "ignores leading blank lines" {
|
||||
cat > my-version <<IN
|
||||
|
||||
1.9.3
|
||||
IN
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "handles the file with no trailing newline" {
|
||||
echo -n "1.8.7" > my-version
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.8.7"
|
||||
}
|
||||
|
||||
@test "ignores carriage returns" {
|
||||
cat > my-version <<< $'1.9.3\r'
|
||||
run rbenv-version-file-read my-version
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "prevents directory traversal" {
|
||||
cat > my-version <<<".."
|
||||
run rbenv-version-file-read my-version
|
||||
assert_failure "rbenv: invalid version in \`my-version'"
|
||||
|
||||
cat > my-version <<<"../foo"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_failure "rbenv: invalid version in \`my-version'"
|
||||
}
|
||||
|
||||
@test "disallows path segments in version string" {
|
||||
cat > my-version <<<"foo/bar"
|
||||
run rbenv-version-file-read my-version
|
||||
assert_failure "rbenv: invalid version in \`my-version'"
|
||||
}
|
||||
30
test/version-file-write.bats
Normal file
30
test/version-file-write.bats
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "invocation without 2 arguments prints usage" {
|
||||
run rbenv-version-file-write
|
||||
assert_failure "Usage: rbenv version-file-write <file> <version>"
|
||||
run rbenv-version-file-write "one" ""
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "setting nonexistent version fails" {
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
run rbenv-version-file-write ".ruby-version" "1.8.7"
|
||||
assert_failure "rbenv: version \`1.8.7' not installed"
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
}
|
||||
|
||||
@test "writes value to arbitrary file" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.8.7"
|
||||
assert [ ! -e "my-version" ]
|
||||
run rbenv-version-file-write "${PWD}/my-version" "1.8.7"
|
||||
assert_success ""
|
||||
assert [ "$(cat my-version)" = "1.8.7" ]
|
||||
}
|
||||
75
test/version-file.bats
Normal file
75
test/version-file.bats
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
create_file() {
|
||||
mkdir -p "$(dirname "$1")"
|
||||
echo "system" > "$1"
|
||||
}
|
||||
|
||||
@test "detects global 'version' file" {
|
||||
create_file "${RBENV_ROOT}/version"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "prints global file if no version files exist" {
|
||||
assert [ ! -e "${RBENV_ROOT}/version" ]
|
||||
assert [ ! -e ".ruby-version" ]
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "in current directory" {
|
||||
create_file ".ruby-version"
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "in parent directory" {
|
||||
create_file ".ruby-version"
|
||||
mkdir -p project
|
||||
cd project
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "topmost file has precedence" {
|
||||
create_file ".ruby-version"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "RBENV_DIR has precedence over PWD" {
|
||||
create_file "widget/.ruby-version"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/widget/.ruby-version"
|
||||
}
|
||||
|
||||
@test "PWD is searched if RBENV_DIR yields no results" {
|
||||
mkdir -p "widget/blank"
|
||||
create_file "project/.ruby-version"
|
||||
cd project
|
||||
RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "finds version file in target directory" {
|
||||
create_file "project/.ruby-version"
|
||||
run rbenv-version-file "${PWD}/project"
|
||||
assert_success "${RBENV_TEST_DIR}/project/.ruby-version"
|
||||
}
|
||||
|
||||
@test "fails when no version file in target directory" {
|
||||
run rbenv-version-file "$PWD"
|
||||
assert_failure ""
|
||||
}
|
||||
82
test/version-name.bats
Normal file
82
test/version-name.bats
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "no version selected" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-version-name
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "system version is not checked for existence" {
|
||||
RBENV_VERSION=system run rbenv-version-name
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "RBENV_VERSION can be overridden by hook" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
create_hook version-name test.bash <<<"RBENV_VERSION=1.9.3"
|
||||
|
||||
RBENV_VERSION=1.8.7 run rbenv-version-name
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook version-name hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export RBENV_VERSION=system
|
||||
IFS=$' \t\n' run rbenv-version-name env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "RBENV_VERSION has precedence over local" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
|
||||
cat > ".ruby-version" <<<"1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success "1.8.7"
|
||||
|
||||
RBENV_VERSION=1.9.3 run rbenv-version-name
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "local file has precedence over global" {
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3"
|
||||
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success "1.8.7"
|
||||
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-version-name
|
||||
assert_success "1.9.3"
|
||||
}
|
||||
|
||||
@test "missing version" {
|
||||
RBENV_VERSION=1.2 run rbenv-version-name
|
||||
assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "version with prefix in name" {
|
||||
create_version "1.8.7"
|
||||
cat > ".ruby-version" <<<"ruby-1.8.7"
|
||||
run rbenv-version-name
|
||||
assert_success
|
||||
assert_output "1.8.7"
|
||||
}
|
||||
56
test/version-origin.bats
Normal file
56
test/version-origin.bats
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "reports global file even if it doesn't exist" {
|
||||
assert [ ! -e "${RBENV_ROOT}/version" ]
|
||||
run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects global file" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
touch "${RBENV_ROOT}/version"
|
||||
run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects RBENV_VERSION" {
|
||||
RBENV_VERSION=1 run rbenv-version-origin
|
||||
assert_success "RBENV_VERSION environment variable"
|
||||
}
|
||||
|
||||
@test "detects local file" {
|
||||
echo "system" > .ruby-version
|
||||
run rbenv-version-origin
|
||||
assert_success "${PWD}/.ruby-version"
|
||||
}
|
||||
|
||||
@test "reports from hook" {
|
||||
create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin"
|
||||
|
||||
RBENV_VERSION=1 run rbenv-version-origin
|
||||
assert_success "plugin"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook version-origin hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export RBENV_VERSION=system
|
||||
IFS=$' \t\n' run rbenv-version-origin env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" {
|
||||
RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin
|
||||
assert_success "${RBENV_ROOT}/version"
|
||||
}
|
||||
47
test/version.bats
Normal file
47
test/version.bats
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@test "no version selected" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-version
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "set by RBENV_VERSION" {
|
||||
create_version "1.9.3"
|
||||
RBENV_VERSION=1.9.3 run rbenv-version
|
||||
assert_success "1.9.3 (set by RBENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "set by local file" {
|
||||
create_version "1.9.3"
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-version
|
||||
assert_success "1.9.3 (set by ${PWD}/.ruby-version)"
|
||||
}
|
||||
|
||||
@test "set by global file" {
|
||||
create_version "1.9.3"
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.9.3"
|
||||
run rbenv-version
|
||||
assert_success "1.9.3 (set by ${RBENV_ROOT}/version)"
|
||||
}
|
||||
|
||||
@test "prefer local over global file" {
|
||||
create_version "1.9.3"
|
||||
create_version "3.0.0"
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
cat > "${RBENV_ROOT}/version" <<<"3.0.0"
|
||||
run rbenv-version
|
||||
assert_success "1.9.3 (set by ${PWD}/.ruby-version)"
|
||||
}
|
||||
162
test/versions.bats
Normal file
162
test/versions.bats
Normal file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_version() {
|
||||
mkdir -p "${RBENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
}
|
||||
|
||||
stub_system_ruby() {
|
||||
local stub="${RBENV_TEST_DIR}/bin/ruby"
|
||||
mkdir -p "$(dirname "$stub")"
|
||||
touch "$stub" && chmod +x "$stub"
|
||||
}
|
||||
|
||||
@test "no versions installed" {
|
||||
stub_system_ruby
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-versions
|
||||
assert_success "* system"
|
||||
}
|
||||
|
||||
@test "not even system ruby available" {
|
||||
PATH="$(path_without ruby)" run rbenv-versions
|
||||
assert_failure
|
||||
assert_output "Warning: no Ruby detected on the system"
|
||||
}
|
||||
|
||||
@test "bare output no versions installed" {
|
||||
assert [ ! -d "${RBENV_ROOT}/versions" ]
|
||||
run rbenv-versions --bare
|
||||
assert_success ""
|
||||
}
|
||||
|
||||
@test "single version installed" {
|
||||
stub_system_ruby
|
||||
create_version "1.9"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
* system
|
||||
1.9
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "single version bare" {
|
||||
create_version "1.9"
|
||||
run rbenv-versions --bare
|
||||
assert_success "1.9"
|
||||
}
|
||||
|
||||
@test "multiple versions" {
|
||||
stub_system_ruby
|
||||
create_version "1.8.7"
|
||||
create_version "1.9.3-p13"
|
||||
create_version "1.9.3-p2"
|
||||
create_version "2.2.10"
|
||||
create_version "2.2.3"
|
||||
create_version "2.2.3-pre.2"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
* system
|
||||
1.8.7
|
||||
1.9.3-p2
|
||||
1.9.3-p13
|
||||
2.2.3-pre.2
|
||||
2.2.3
|
||||
2.2.10
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "indicates current version" {
|
||||
stub_system_ruby
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
RBENV_VERSION=1.9.3 run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by RBENV_VERSION environment variable)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "bare doesn't indicate current version" {
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
RBENV_VERSION=1.9.3 run rbenv-versions --bare
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
1.9.3
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "globally selected version" {
|
||||
stub_system_ruby
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.9.3"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by ${RBENV_ROOT}/version)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "per-project version" {
|
||||
stub_system_ruby
|
||||
create_version "1.9.3"
|
||||
create_version "2.0.0"
|
||||
cat > ".ruby-version" <<<"1.9.3"
|
||||
run rbenv-versions
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
system
|
||||
* 1.9.3 (set by ${RBENV_TEST_DIR}/.ruby-version)
|
||||
2.0.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "ignores non-directories under versions" {
|
||||
create_version "1.9"
|
||||
touch "${RBENV_ROOT}/versions/hello"
|
||||
|
||||
run rbenv-versions --bare
|
||||
assert_success "1.9"
|
||||
}
|
||||
|
||||
@test "lists symlinks under versions" {
|
||||
create_version "1.8.7"
|
||||
ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8"
|
||||
|
||||
run rbenv-versions --bare
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
1.8
|
||||
1.8.7
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "doesn't list symlink aliases when --skip-aliases" {
|
||||
create_version "1.8.7"
|
||||
ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8"
|
||||
mkdir moo
|
||||
ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9"
|
||||
|
||||
run rbenv-versions --bare --skip-aliases
|
||||
assert_success
|
||||
|
||||
assert_output <<OUT
|
||||
1.8.7
|
||||
1.9
|
||||
OUT
|
||||
}
|
||||
30
test/whence.bats
Normal file
30
test/whence.bats
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
||||
mkdir -p "$bin"
|
||||
touch "${bin}/$2"
|
||||
chmod +x "${bin}/$2"
|
||||
}
|
||||
|
||||
@test "finds versions where present" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.8" "rake"
|
||||
create_executable "2.0" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
run rbenv-whence ruby
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
1.8
|
||||
2.0
|
||||
OUT
|
||||
|
||||
run rbenv-whence rake
|
||||
assert_success "1.8"
|
||||
|
||||
run rbenv-whence rspec
|
||||
assert_success "2.0"
|
||||
}
|
||||
150
test/which.bats
Normal file
150
test/which.bats
Normal file
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
create_executable() {
|
||||
local bin
|
||||
if [[ $1 == */* ]]; then bin="$1"
|
||||
else bin="${RBENV_ROOT}/versions/${1}/bin"
|
||||
fi
|
||||
mkdir -p "$bin"
|
||||
touch "${bin}/$2"
|
||||
chmod +x "${bin}/$2"
|
||||
}
|
||||
|
||||
@test "outputs path to executable" {
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
RBENV_VERSION=1.8 run rbenv-which ruby
|
||||
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
||||
|
||||
RBENV_VERSION=2.0 run rbenv-which rspec
|
||||
assert_success "${RBENV_ROOT}/versions/2.0/bin/rspec"
|
||||
}
|
||||
|
||||
@test "searches PATH for system version" {
|
||||
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||
|
||||
RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||
}
|
||||
|
||||
@test "searches PATH for system version (shims prepended)" {
|
||||
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||
|
||||
PATH="${RBENV_ROOT}/shims:$PATH" RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||
}
|
||||
|
||||
@test "searches PATH for system version (shims appended)" {
|
||||
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||
|
||||
PATH="$PATH:${RBENV_ROOT}/shims" RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||
}
|
||||
|
||||
@test "searches PATH for system version (shims spread)" {
|
||||
create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans"
|
||||
create_executable "${RBENV_ROOT}/shims" "kill-all-humans"
|
||||
|
||||
PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/shims:/tmp/non-existent:$PATH:${RBENV_ROOT}/shims" \
|
||||
RBENV_VERSION=system run rbenv-which kill-all-humans
|
||||
assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans"
|
||||
}
|
||||
|
||||
@test "doesn't include current directory in PATH search" {
|
||||
bats_require_minimum_version 1.5.0
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
touch kill-all-humans
|
||||
chmod +x kill-all-humans
|
||||
PATH="$(path_without "kill-all-humans")" RBENV_VERSION=system run -127 rbenv-which kill-all-humans
|
||||
assert_failure "rbenv: kill-all-humans: command not found"
|
||||
}
|
||||
|
||||
@test "version not installed" {
|
||||
create_executable "2.0" "rspec"
|
||||
RBENV_VERSION=1.9 run rbenv-which rspec
|
||||
assert_failure "rbenv: version \`1.9' is not installed (set by RBENV_VERSION environment variable)"
|
||||
}
|
||||
|
||||
@test "no executable found" {
|
||||
bats_require_minimum_version 1.5.0
|
||||
create_executable "1.8" "rspec"
|
||||
RBENV_VERSION=1.8 run -127 rbenv-which rake
|
||||
assert_failure "rbenv: rake: command not found"
|
||||
}
|
||||
|
||||
@test "no executable found for system version" {
|
||||
bats_require_minimum_version 1.5.0
|
||||
PATH="$(path_without "rake")" RBENV_VERSION=system run -127 rbenv-which rake
|
||||
assert_failure "rbenv: rake: command not found"
|
||||
}
|
||||
|
||||
@test "executable found in other versions" {
|
||||
bats_require_minimum_version 1.5.0
|
||||
create_executable "1.8" "ruby"
|
||||
create_executable "1.9" "rspec"
|
||||
create_executable "2.0" "rspec"
|
||||
|
||||
RBENV_VERSION=1.8 run -127 rbenv-which rspec
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
rbenv: rspec: command not found
|
||||
|
||||
The \`rspec' command exists in these Ruby versions:
|
||||
1.9
|
||||
2.0
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "executable not found in user gems" {
|
||||
bats_require_minimum_version 1.5.0
|
||||
create_executable "2.7.6" "ruby"
|
||||
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
|
||||
GEM_HOME='' RBENV_VERSION=2.7.6 run -127 rbenv-which rake
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "executable found in gem home" {
|
||||
create_executable "2.7.6" "ruby"
|
||||
create_executable "${HOME}/mygems/bin" "rake"
|
||||
create_executable "${HOME}/.gem/ruby/2.7.0/bin" "rake"
|
||||
GEM_HOME="${HOME}/mygems" RBENV_VERSION=2.7.6 run rbenv-which rake
|
||||
assert_success "${HOME}/mygems/bin/rake"
|
||||
}
|
||||
|
||||
@test "executable found in gem home (system ruby)" {
|
||||
create_executable "${HOME}/mygems/bin" "rbenv-test-lolcat"
|
||||
create_executable "${HOME}/.gem/ruby/2.6.0/bin" "rbenv-test-lolcat"
|
||||
GEM_HOME="${HOME}/mygems" RBENV_VERSION=system run rbenv-which rbenv-test-lolcat
|
||||
assert_success "${HOME}/mygems/bin/rbenv-test-lolcat"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook which hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
exit
|
||||
SH
|
||||
|
||||
IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything
|
||||
assert_success
|
||||
assert_output "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "discovers version from rbenv-version-name" {
|
||||
mkdir -p "$RBENV_ROOT"
|
||||
cat > "${RBENV_ROOT}/version" <<<"1.8"
|
||||
create_executable "1.8" "ruby"
|
||||
|
||||
mkdir -p "$RBENV_TEST_DIR"
|
||||
cd "$RBENV_TEST_DIR"
|
||||
|
||||
RBENV_VERSION='' run rbenv-which ruby
|
||||
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
|
||||
}
|
||||
Reference in New Issue
Block a user