mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
591 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09c558685a | ||
|
|
e4b743cced | ||
|
|
9128b7df7f | ||
|
|
90d4cbe67e | ||
|
|
625348122c | ||
|
|
27c2b98f5f | ||
|
|
344a241c28 | ||
|
|
fdda6ef8bd | ||
|
|
c78426f033 | ||
|
|
9e208584ed | ||
|
|
5be38f2b3a | ||
|
|
b7fc4f3760 | ||
|
|
bbad75fb6c | ||
|
|
a090b78e8d | ||
|
|
0a4d830ee1 | ||
|
|
f3b4b60aa8 | ||
|
|
012e7106de | ||
|
|
bbdf78cd97 | ||
|
|
6b4b4c78cf | ||
|
|
ee1cc9f415 | ||
|
|
053e40572c | ||
|
|
47f69075a0 | ||
|
|
b4beb1a5cb | ||
|
|
738489f2bb | ||
|
|
d57ba5e30b | ||
|
|
ca24e00d75 | ||
|
|
513c1cf0c7 | ||
|
|
d13d3a9902 | ||
|
|
c529c02ac0 | ||
|
|
745fd16452 | ||
|
|
f4514f5c60 | ||
|
|
a5acabd923 | ||
|
|
e65aa04ad7 | ||
|
|
d0afc47bfb | ||
|
|
ce743b2058 | ||
|
|
88bb9381b2 | ||
|
|
876ded6dfe | ||
|
|
5a4ba76293 | ||
|
|
31bb577075 | ||
|
|
10aab82539 | ||
|
|
1c4b7d33b1 | ||
|
|
8ff0d06d34 | ||
|
|
6cf9965e42 | ||
|
|
c45a56d66b | ||
|
|
a8300b7a44 | ||
|
|
98122860cc | ||
|
|
dd8174f545 | ||
|
|
5350212e53 | ||
|
|
4f7e669271 | ||
|
|
165538b4bd | ||
|
|
6338fd78f7 | ||
|
|
181f7722b3 | ||
|
|
41863470ba | ||
|
|
c4637da860 | ||
|
|
382aa8f6de | ||
|
|
a460e1ada3 | ||
|
|
aaef0d316f | ||
|
|
76bb6d6138 | ||
|
|
2536ea12cb | ||
|
|
cb3b0e661d | ||
|
|
2cee0139e4 | ||
|
|
132485a660 | ||
|
|
d55ee38c7f | ||
|
|
e214ea1c59 | ||
|
|
85ae64b981 | ||
|
|
4a87cef46f | ||
|
|
8c00dc2b6b | ||
|
|
38aa9a447a | ||
|
|
6dc796bb29 | ||
|
|
d8e566d0e9 | ||
|
|
5820efa513 | ||
|
|
e05fe0ba05 | ||
|
|
134a33f6e0 | ||
|
|
cc9ef11985 | ||
|
|
9ad2347258 | ||
|
|
dbefea339f | ||
|
|
9260888d1c | ||
|
|
eaa188bb63 | ||
|
|
dc8b7d6b03 | ||
|
|
84392ffc0d | ||
|
|
c6828bf32b | ||
|
|
31552722a8 | ||
|
|
d7d4d7830b | ||
|
|
dbf2351d3a | ||
|
|
9731625230 | ||
|
|
a572533c89 | ||
|
|
8ec8d1f32a | ||
|
|
21b23f8e54 | ||
|
|
fce889235c | ||
|
|
f41a3914a5 | ||
|
|
c643ac4827 | ||
|
|
97e02eae7d | ||
|
|
516bfe7ba3 | ||
|
|
9463492ac1 | ||
|
|
2f14ef61ff | ||
|
|
2e39ab59d7 | ||
|
|
ac4e4a2b6c | ||
|
|
13d1df659f | ||
|
|
4afecbe400 | ||
|
|
bb625a76d9 | ||
|
|
b027aa103c | ||
|
|
59269a431b | ||
|
|
c8f2584d87 | ||
|
|
24d7cf6618 | ||
|
|
1fdf489cae | ||
|
|
0614ca434a | ||
|
|
8085adb8a2 | ||
|
|
3d88da7b2a | ||
|
|
ee46dba585 | ||
|
|
a505ca69d9 | ||
|
|
428f76db80 | ||
|
|
b6ebf7cb60 | ||
|
|
6257be6371 | ||
|
|
9800dc4697 | ||
|
|
b8e4bd2029 | ||
|
|
941032b707 | ||
|
|
fe99f6fa11 | ||
|
|
6103628129 | ||
|
|
cbd3b1bc9b | ||
|
|
04db3c6211 | ||
|
|
858b8b190b | ||
|
|
7af01a4afb | ||
|
|
9e4a3d50f0 | ||
|
|
44fd6f4381 | ||
|
|
8ab3a3d9aa | ||
|
|
8bdcc10c8f | ||
|
|
6369fca253 | ||
|
|
9b771a96f0 | ||
|
|
f8f2421ac3 | ||
|
|
9e6d1b24c8 | ||
|
|
587e7127eb | ||
|
|
6b522bd770 | ||
|
|
edc901d107 | ||
|
|
e88a2ba7d4 | ||
|
|
629afba526 | ||
|
|
f92cc84631 | ||
|
|
6ea6d1b29f | ||
|
|
39afe3fc2a | ||
|
|
3584fa15ec | ||
|
|
6091b051fb | ||
|
|
a053aeddf8 | ||
|
|
50ece89ab9 | ||
|
|
197f8b88bf | ||
|
|
c8d0608369 | ||
|
|
1b03bc2404 | ||
|
|
b26ea8462e | ||
|
|
323469723b | ||
|
|
d7fa9bc056 | ||
|
|
256a55b33b | ||
|
|
53f1e6eed2 | ||
|
|
0b8a7dc4a2 | ||
|
|
cf9804f2a0 | ||
|
|
bc90c7c199 | ||
|
|
3e93bdf31b | ||
|
|
bc236109fd | ||
|
|
07ad6da7e8 | ||
|
|
ea1721bcb0 | ||
|
|
2486a36af3 | ||
|
|
6a1ebb11df | ||
|
|
1fd3a405e6 | ||
|
|
91e4dc83fc | ||
|
|
a4ea6a9d19 | ||
|
|
0e5f20a97d | ||
|
|
bc67e01e52 | ||
|
|
eba57d84a6 | ||
|
|
3d1936e9c7 | ||
|
|
932f0a757f | ||
|
|
cddb781127 | ||
|
|
220f3f2384 | ||
|
|
9ac062acef | ||
|
|
765a38e534 | ||
|
|
c2e78a3104 | ||
|
|
1eb665832a | ||
|
|
64e9d07b1b | ||
|
|
d23635f66d | ||
|
|
4640627f6e | ||
|
|
83bf166a1f | ||
|
|
f881502f84 | ||
|
|
32291172bf | ||
|
|
eb7f8b6d33 | ||
|
|
d8c0634524 | ||
|
|
11e97f4eb0 | ||
|
|
813d78e46a | ||
|
|
2931277608 | ||
|
|
6b3ec44ee9 | ||
|
|
19e502c64e | ||
|
|
a9a0cd8297 | ||
|
|
88c3b9c989 | ||
|
|
804b8696a4 | ||
|
|
b5d23ef38b | ||
|
|
c190a65c69 | ||
|
|
bf4b27e679 | ||
|
|
d73516c0a9 | ||
|
|
ac95da3afc | ||
|
|
5be3fb86b9 | ||
|
|
4dd332c95e | ||
|
|
fea7bda58f | ||
|
|
88f689e167 | ||
|
|
5743da5588 | ||
|
|
1310ea2729 | ||
|
|
2acf349d4e | ||
|
|
acedc2dcf2 | ||
|
|
c40d8cbda4 | ||
|
|
07bd160861 | ||
|
|
2c9d4dfdd4 | ||
|
|
df7b68480c | ||
|
|
31ccf2f813 | ||
|
|
480211f0ee | ||
|
|
59e65cbda2 | ||
|
|
649b7c132d | ||
|
|
b6bc8a6828 | ||
|
|
f2d249fdc7 | ||
|
|
c28d4e41cf | ||
|
|
1572e483c2 | ||
|
|
f8ea4f44e8 | ||
|
|
e3dcc5327a | ||
|
|
bd24bdd411 | ||
|
|
7335ef5792 | ||
|
|
3266fb5441 | ||
|
|
ab96772436 | ||
|
|
c7ace08193 | ||
|
|
f82598ca2d | ||
|
|
b29d4affd8 | ||
|
|
6594af3729 | ||
|
|
6df9ac7c37 | ||
|
|
73f58b90a0 | ||
|
|
23d7ed3187 | ||
|
|
a2e03ce3cb | ||
|
|
15b643fc11 | ||
|
|
150fba5ecd | ||
|
|
c507bf25de | ||
|
|
dbaa28492e | ||
|
|
960cd3da69 | ||
|
|
82d6bab57c | ||
|
|
24baf14e53 | ||
|
|
5fcf7149d4 | ||
|
|
4d4ec52df8 | ||
|
|
69e7f4af19 | ||
|
|
61990deb36 | ||
|
|
0ec1ce005c | ||
|
|
f0cb57d8ac | ||
|
|
930f67f474 | ||
|
|
1de812d5a8 | ||
|
|
c272de7cba | ||
|
|
5edc465802 | ||
|
|
ec195a4e15 | ||
|
|
bb2d57dcbf | ||
|
|
02c4760ace | ||
|
|
51a1f25247 | ||
|
|
895efe7b05 | ||
|
|
83f5581da4 | ||
|
|
884ebb6dab | ||
|
|
c274551db6 | ||
|
|
f796336a12 | ||
|
|
3b944fe7e8 | ||
|
|
afd0bd7cb0 | ||
|
|
a5c17d77bf | ||
|
|
d33caca6c7 | ||
|
|
c23bde74ec | ||
|
|
ecffcf1667 | ||
|
|
26682256b3 | ||
|
|
5838ee1263 | ||
|
|
b7cb7d10f9 | ||
|
|
521659db4b | ||
|
|
a3a150faf2 | ||
|
|
ce5c441f0f | ||
|
|
99de03ea32 | ||
|
|
d463eddb8b | ||
|
|
ed3535db8a | ||
|
|
2fe369831c | ||
|
|
86fb9737dc | ||
|
|
d15e88cb68 | ||
|
|
83e44c7d8e | ||
|
|
fde3bda453 | ||
|
|
1a5aba47c7 | ||
|
|
6b4ed722b1 | ||
|
|
1ce325b31e | ||
|
|
f5d38f2696 | ||
|
|
bd5b011ecd | ||
|
|
8fd77cbb5b | ||
|
|
c1653ff654 | ||
|
|
22b2b7c6c5 | ||
|
|
d5bc78d98b | ||
|
|
a3799e0350 | ||
|
|
35b926c445 | ||
|
|
2e2e762743 | ||
|
|
266c13df18 | ||
|
|
633e74ef80 | ||
|
|
1fa8a8f4a6 | ||
|
|
d07d18258b | ||
|
|
a004fc3592 | ||
|
|
4b883524d8 | ||
|
|
15556ad0d6 | ||
|
|
27c5df22cf | ||
|
|
03f4ab4bd5 | ||
|
|
f1c982608f | ||
|
|
c18e027ad5 | ||
|
|
dd9dd142c9 | ||
|
|
2f517111ef | ||
|
|
9311e4255e | ||
|
|
61c7bfc128 | ||
|
|
14eb6df45e | ||
|
|
698e003fcd | ||
|
|
cc2c061289 | ||
|
|
9d33b3f72a | ||
|
|
0027aa3d1e | ||
|
|
1292540bb5 | ||
|
|
4631c07483 | ||
|
|
d895d4a9f0 | ||
|
|
d3da62d53a | ||
|
|
b644b17599 | ||
|
|
36475f80e9 | ||
|
|
52b02850ca | ||
|
|
7ca3d7ac8e | ||
|
|
3756fce553 | ||
|
|
9386f640a5 | ||
|
|
bcfb4f2a07 | ||
|
|
aa7c0f1ce8 | ||
|
|
2a5f08c15a | ||
|
|
70fc085862 | ||
|
|
09cc530299 | ||
|
|
966818c23d | ||
|
|
7c9f827bfe | ||
|
|
2a300c6661 | ||
|
|
53570b1505 | ||
|
|
11f0f812c5 | ||
|
|
620402a833 | ||
|
|
3f7e2589cd | ||
|
|
ed26a1d3bb | ||
|
|
ae1debbc92 | ||
|
|
622e018570 | ||
|
|
a2a8518f74 | ||
|
|
7182f6d799 | ||
|
|
646d6a929c | ||
|
|
6f9a2ee50a | ||
|
|
98e9e09588 | ||
|
|
9541471f87 | ||
|
|
c1fee8793d | ||
|
|
e61ee94e26 | ||
|
|
9116905b24 | ||
|
|
64950f4524 | ||
|
|
8973af82c5 | ||
|
|
f415d43c3b | ||
|
|
8f9858ba2f | ||
|
|
ba42910595 | ||
|
|
78c789e1cb | ||
|
|
b5059bc8a4 | ||
|
|
05fe69eb92 | ||
|
|
06b3f49c49 | ||
|
|
1063e5d0e4 | ||
|
|
7f77c395e3 | ||
|
|
e2a18894b3 | ||
|
|
0714e41148 | ||
|
|
5cc971facd | ||
|
|
b402cef338 | ||
|
|
a9b6bfdddd | ||
|
|
a604dfbb97 | ||
|
|
e9d170176d | ||
|
|
304296972b | ||
|
|
d0eae2cbfd | ||
|
|
4d90ce7b40 | ||
|
|
48ede1a00a | ||
|
|
c261ae32d2 | ||
|
|
e8ea3ccd58 | ||
|
|
7bcd7c2752 | ||
|
|
7dbabe84e4 | ||
|
|
3dadb349eb | ||
|
|
e43ce15736 | ||
|
|
6297285527 | ||
|
|
2c863b9f2c | ||
|
|
221ce5afb3 | ||
|
|
1297c39a31 | ||
|
|
4c944910fa | ||
|
|
deac1fc188 | ||
|
|
29b1b2fb5e | ||
|
|
af3db9a4fe | ||
|
|
a26817d604 | ||
|
|
167a8c9edc | ||
|
|
97eb537f38 | ||
|
|
37b0bcd7c1 | ||
|
|
5b56ea1816 | ||
|
|
602aae7839 | ||
|
|
05eb4ece44 | ||
|
|
5840c3e13a | ||
|
|
cd5294dfb4 | ||
|
|
88b83be07b | ||
|
|
65a28912eb | ||
|
|
d8a2ceea43 | ||
|
|
c32ca6a8e6 | ||
|
|
c9f55c1063 | ||
|
|
1127a290f4 | ||
|
|
bd5cf2e809 | ||
|
|
9002e60adf | ||
|
|
bd2fe4ce9b | ||
|
|
e6d5633671 | ||
|
|
e098f7b285 | ||
|
|
3deb17e841 | ||
|
|
15f6a41a75 | ||
|
|
75b6736cf4 | ||
|
|
80196c9abc | ||
|
|
becdf220fd | ||
|
|
dcde77cd09 | ||
|
|
f03dd8d216 | ||
|
|
a5d55ba16d | ||
|
|
2936f4f32c | ||
|
|
e2686d8819 | ||
|
|
b2606c0421 | ||
|
|
e3e0d70c0e | ||
|
|
f42a0475e4 | ||
|
|
a834d037bc | ||
|
|
cccd072ed1 | ||
|
|
5f0e688b50 | ||
|
|
ec8930c144 | ||
|
|
3e46bcec93 | ||
|
|
5d13704e04 | ||
|
|
52f8578984 | ||
|
|
09c6432854 | ||
|
|
796bfbd7af | ||
|
|
56dd5dfff4 | ||
|
|
3eb77bf53f | ||
|
|
89826983eb | ||
|
|
697051d1fd | ||
|
|
67266dc25c | ||
|
|
817e93ac94 | ||
|
|
1650b8552f | ||
|
|
ec1396c9ee | ||
|
|
ec3dba01b2 | ||
|
|
8ce1f0b047 | ||
|
|
6fbfcfc0d7 | ||
|
|
5a9b7b230c | ||
|
|
522fc94d12 | ||
|
|
deaba44835 | ||
|
|
de7483a114 | ||
|
|
d9dcc5ed44 | ||
|
|
1c73e75982 | ||
|
|
920b9c5872 | ||
|
|
1880b83c37 | ||
|
|
46cb0de347 | ||
|
|
7562781c9d | ||
|
|
2a146852ef | ||
|
|
361801aaaa | ||
|
|
2aa4d47312 | ||
|
|
2dda197980 | ||
|
|
6043d9cf89 | ||
|
|
a3fc9dee32 | ||
|
|
d637cb33da | ||
|
|
f5c0695605 | ||
|
|
21130b0c49 | ||
|
|
a5ad186547 | ||
|
|
5e7a48a865 | ||
|
|
2386fa2355 | ||
|
|
723f363c07 | ||
|
|
a98dbb67b9 | ||
|
|
28cf7dc39e | ||
|
|
744ccb7cc9 | ||
|
|
db584544f4 | ||
|
|
f4718dcdf2 | ||
|
|
4ec1b5d4e2 | ||
|
|
6e0626d3af | ||
|
|
dd51dd14af | ||
|
|
7cd412dc57 | ||
|
|
1870b96578 | ||
|
|
2e4df706f6 | ||
|
|
1141acfd4c | ||
|
|
53c1b32e02 | ||
|
|
f2451c1e29 | ||
|
|
a551ff2b1b | ||
|
|
7174c76bf0 | ||
|
|
6708ad19c5 | ||
|
|
fb0301f8b8 | ||
|
|
c84145751a | ||
|
|
b72f9bea43 | ||
|
|
9c6fa90857 | ||
|
|
83d1f2b480 | ||
|
|
19aae6dbd8 | ||
|
|
aa3a262caa | ||
|
|
b6afa30c39 | ||
|
|
75a44d856e | ||
|
|
41207e4861 | ||
|
|
acdef09e00 | ||
|
|
d29b57f597 | ||
|
|
0237e1dafd | ||
|
|
a92993228f | ||
|
|
6a97901691 | ||
|
|
39aa8b32b1 | ||
|
|
1bf524c1b7 | ||
|
|
a734488a4b | ||
|
|
94e2339842 | ||
|
|
5263b3f61e | ||
|
|
962b9c6548 | ||
|
|
48c36d628a | ||
|
|
e2a80151ae | ||
|
|
2572c7139b | ||
|
|
e7cda4f363 | ||
|
|
54c6848d75 | ||
|
|
9a07e8f372 | ||
|
|
e8957009c7 | ||
|
|
62017452e9 | ||
|
|
16f424d25d | ||
|
|
95d593dd51 | ||
|
|
545893df73 | ||
|
|
680f2098f1 | ||
|
|
376c808b50 | ||
|
|
4cf6396e4c | ||
|
|
17170f5d6e | ||
|
|
19cb1fb592 | ||
|
|
c30fbd1d8d | ||
|
|
6bc9ee3420 | ||
|
|
4192449112 | ||
|
|
f1efd6b4e7 | ||
|
|
21cfef45d6 | ||
|
|
ae7dda10ce | ||
|
|
646632de1d | ||
|
|
770ea563ee | ||
|
|
946affe60d | ||
|
|
89543e999d | ||
|
|
fc17ce0150 | ||
|
|
441c118b63 | ||
|
|
ac55534055 | ||
|
|
821de39b27 | ||
|
|
ede2dd2d3a | ||
|
|
08d32a1522 | ||
|
|
d956ed0760 | ||
|
|
6fe25a08d7 | ||
|
|
222b8e6743 | ||
|
|
d6908dd9c2 | ||
|
|
ac2ab6501d | ||
|
|
8bfbc8c61d | ||
|
|
ff90170738 | ||
|
|
6ebb1df8fe | ||
|
|
ff500b46c9 | ||
|
|
72d56bd614 | ||
|
|
ad1945c278 | ||
|
|
82b45b460e | ||
|
|
1e574bb70c | ||
|
|
537c32b6b6 | ||
|
|
f44ae0535e | ||
|
|
910d6282c4 | ||
|
|
20e322bf9b | ||
|
|
edd3142d1f | ||
|
|
097b96ea44 | ||
|
|
5ccd0025a0 | ||
|
|
d358a352c0 | ||
|
|
e63567d51c | ||
|
|
f41ef2198b | ||
|
|
61bd3ae1c6 | ||
|
|
5ef5bd7c31 | ||
|
|
7f98193beb | ||
|
|
d2c3dbc665 | ||
|
|
2f75b07d08 | ||
|
|
280619a4e8 | ||
|
|
6db6df882c | ||
|
|
db411ca515 | ||
|
|
3fb3613d34 | ||
|
|
30f47dfc5e | ||
|
|
27fc963631 | ||
|
|
d8de72ca77 | ||
|
|
ef5f356da2 | ||
|
|
1919deab1f | ||
|
|
fd0971542f | ||
|
|
d7b4aa0ff3 | ||
|
|
79bc6041c9 | ||
|
|
8be8016a76 | ||
|
|
d4a143a425 | ||
|
|
bf0f56d04e | ||
|
|
0e7c6bdcc7 | ||
|
|
7e8ff69a14 | ||
|
|
eee3dd297e | ||
|
|
5afe17d147 | ||
|
|
664a0bd559 | ||
|
|
4422b958c3 | ||
|
|
295879cced | ||
|
|
e073441c36 | ||
|
|
27e9f77a49 | ||
|
|
f8ea82d7dc | ||
|
|
890db6eaaf | ||
|
|
99395856ff | ||
|
|
9cf68ac868 | ||
|
|
2ddcb51df3 | ||
|
|
9875be3327 | ||
|
|
a182502af0 | ||
|
|
86504af149 | ||
|
|
1825609d8d | ||
|
|
43ff216fa6 | ||
|
|
ff54332b66 | ||
|
|
84da2f32ec | ||
|
|
b7a272fe6d | ||
|
|
9e5a581307 | ||
|
|
f34f1fd78d | ||
|
|
a476d4c587 | ||
|
|
21f8ed50db |
90
CHANGES
90
CHANGES
@@ -1,3 +1,91 @@
|
||||
CHANGES FROM 1.0 TO 1.1, 05 November 2009
|
||||
|
||||
* New run-shell (alias run) command to run an external command without a
|
||||
window, capture it's stdout, and send it to output mode.
|
||||
* Ability to define multiple prefix keys.
|
||||
* Internal locking mechanism removed. Instead, detach each client and run the
|
||||
external command specified in the new session option lock-command (by default
|
||||
lock -np), thus allowing the system password to be used.
|
||||
* set-password command, and -U command line flag removed per the above change.
|
||||
* Add support for -c command line flag to execute a shell command.
|
||||
* New lock-client (alias lockc), and lock-session (alias locks) commands to
|
||||
lock a particular client, or all clients attached to a session.
|
||||
* Support C-n/C-p/C-v/M-v with emacs keys in choice mode.
|
||||
* Use : for goto line rather than g in vi mode.
|
||||
* Try to guess which client to use when no target client was specified. Finds
|
||||
the current session, and if only one client is present, use it. Otherwise,
|
||||
return the most recently used client.
|
||||
* Make C-Down/C-Up in copy mode scroll the screen down/up one line without
|
||||
moving the cursor.
|
||||
* Scroll mode superseded by copy mode.
|
||||
* New synchronize-panes window option to send all input to all other panes in
|
||||
the same window.
|
||||
* New lock-server session option to lock, when off (on by default), each
|
||||
session when it has been idle for the lock-after-time setting. When on, the
|
||||
entire server locks when all sessions have been idle for their individual
|
||||
lock-after-time setting.
|
||||
* Add support for grouped sessions which have independent name, options,
|
||||
current window, but where the linked windows are synchronized (ie creating,
|
||||
killing windows are mirrored between the sessions). A grouped session may be
|
||||
created by passing -t to new-session.
|
||||
* New mouse-select-pane session option to select the current pane with the
|
||||
mouse.
|
||||
* Queue, and run commands in the background for if-shell, status-left,
|
||||
status-right, and #() by starting each once every status-interval. Adds the
|
||||
capability to call some programs which would previously cause the server to
|
||||
hang (eg sleep/tmux). It also avoids running commands excessively (ie if used
|
||||
multiple times, it will be run only once).
|
||||
* When a window is zombified and automatic-rename is on, append [dead] to the
|
||||
name.
|
||||
* Split list-panes (alias lsp) off from list-windows.
|
||||
* New pipe-pane (alias pipep) to redirect a pane output to an external command.
|
||||
* Support for automatic-renames for Solaris.
|
||||
* Permit attributes to be turned off in #[] by prefixing with no (eg nobright).
|
||||
* Add H/M/L in vi mode, and M-R/M-r in emacs to move the cursor to the top,
|
||||
middle, and bottom of the screen.
|
||||
* -a option added to kill-pane to kill all except current pane.
|
||||
* The -d command line flag is now gone (can be replaced by terminal-overrides).
|
||||
Just use op/AX to detect default colours.
|
||||
* input/tty/utf8 improvements.
|
||||
* xterm-keys rewrite.
|
||||
* Additional code reduction, and bug fixes.
|
||||
|
||||
CHANGES FROM 0.9 TO 1.0, 20 Sept 2009
|
||||
|
||||
* Option to alter the format of the window title set by tmux.
|
||||
* Backoff for a while after multiple incorrect password attempts.
|
||||
* Quick display of pane numbers (C-b q).
|
||||
* Better choose-window, choose-session commands and a new choose-client command.
|
||||
* Option to request multiple responses when using command-prompt.
|
||||
* Improved environment handling.
|
||||
* Combine wrapped lines when pasting.
|
||||
* Option to override terminal settings (terminal-overrides).
|
||||
* Use the full range of ACS characters for drawing pane separator lines.
|
||||
* Customisable mode keys.
|
||||
* Status line colour options, with embedded colours in status-left/right, and
|
||||
an option to centre the window list.
|
||||
* Much improved layouts, including both horizontal and vertical splitting.
|
||||
* Optional visual bell, activity and content indications.
|
||||
* Set the utf8 and status-utf8 options when the server is started with -u.
|
||||
* display-message command to show a message in the status line, by default some
|
||||
information about the current window.
|
||||
* Improved current process detection on NetBSD.
|
||||
* unlink-window -k is now the same as kill-window.
|
||||
* attach-session now works from inside tmux.
|
||||
* A system-wide configuration file, /etc/tmux.conf.
|
||||
* A number of new commands in copy mode, including searching.
|
||||
* Panes are now specified using the target (-t) notation.
|
||||
* -t now accepts fnmatch(3) patterns and looks for prefixes.
|
||||
* Translate \r into \n when pasting.
|
||||
* Support for binding commands to keys without the prefix key
|
||||
* Support for alternate screen (terminfo smcup/rmcup).
|
||||
* Maintain data that goes off screen after reducing the window size, so it can
|
||||
be restored when the size is increased again.
|
||||
* New if-shell command to test a shell command before running a tmux command.
|
||||
* tmux now works as the shell.
|
||||
* Man page reorganisation.
|
||||
* Many minor additions, much code tidying and several bug fixes.
|
||||
|
||||
CHANGES FROM 0.8 TO 0.9, 01 July 2009
|
||||
|
||||
* Major changes to build infrastructure: cleanup of makefiles and addition
|
||||
@@ -1322,7 +1410,7 @@ The list of older changes is below.
|
||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||
customisation.
|
||||
|
||||
$Id: CHANGES,v 1.299 2009-07-01 22:15:16 nicm Exp $
|
||||
$Id: CHANGES,v 1.301 2009-11-05 12:35:47 tcunha Exp $
|
||||
|
||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||
|
||||
61
FAQ
61
FAQ
@@ -42,16 +42,17 @@ include as much of the following information as possible:
|
||||
|
||||
Please send feature requests by email to nicm@users.sourceforge.net.
|
||||
|
||||
* Why do you use the screen termcap inside tmux? It sucks.
|
||||
* Why do you use the screen terminal description inside tmux? It sucks.
|
||||
|
||||
It is already widely available. It is planned to change to something else
|
||||
such as xterm-color at some point, if possible.
|
||||
It is already widely available. It is planned to change to something else such
|
||||
as xterm-xfree86 at some point, if possible.
|
||||
|
||||
* I don't see any colour in my terminal! Help!
|
||||
|
||||
On some platforms, common termcaps such as xterm do not include colour. screen
|
||||
ignores this, tmux does not. If the terminal emulator in use supports colour,
|
||||
use a termcap which correctly lists this, such as xterm-color.
|
||||
On some platforms, common terminal descriptions such as xterm do not include
|
||||
colour. screen ignores this, tmux does not. If the terminal emulator in use
|
||||
supports colour, use a value for TERM which correctly lists this, such as
|
||||
xterm-color.
|
||||
|
||||
* tmux freezes my terminal when I attach to a session. I even have to kill -9
|
||||
the shell it was started from to recover!
|
||||
@@ -92,13 +93,22 @@ checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
||||
be used to check if this is detected correctly; if not, the -u command-line
|
||||
flag may be specified when creating or attaching a client to a tmux session:
|
||||
|
||||
$ tmux -u new
|
||||
$ tmux -u new
|
||||
|
||||
* How do I use a 256 colour terminal?
|
||||
|
||||
tmux will attempt to detect a 256 colour terminal both by looking at the Co
|
||||
termcap entry and, as this is broken for some terminals such as xterm-256color,
|
||||
by looking for the string "256col" in the termcap name.
|
||||
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
||||
to add the following to ~/.tmux.conf:
|
||||
|
||||
set -g default-terminal "screen-256color"
|
||||
|
||||
Note that some platforms do not support "screen-256color" ("infocmp
|
||||
screen-256color" will return an error) - in this case see the next entry in
|
||||
this FAQ.
|
||||
|
||||
tmux attempts to detect a 256 colour terminal both by looking at the colors
|
||||
terminfo entry and by looking for the string "256col" in the TERM environment
|
||||
variable.
|
||||
|
||||
If both these methods fail, the -2 flag may be passed to tmux when attaching
|
||||
to a session to indicate the terminal supports 256 colours.
|
||||
@@ -106,22 +116,18 @@ to a session to indicate the terminal supports 256 colours.
|
||||
* vim or $otherprogram doesn't display 256 colours. What's up?
|
||||
|
||||
Some programs attempt to detect the number of colours a terminal is capable of
|
||||
by checking the Co termcap entry. However, this is not reliable, and in any
|
||||
case is missing from the "screen" termcap used inside tmux.
|
||||
by checking the colors terminfo or Co termcap entry. However, this is not
|
||||
reliable, and in any case is missing from the "screen" terminal description
|
||||
used inside tmux.
|
||||
|
||||
There are three options to allow programs to recognise they are running on
|
||||
a 256-colour terminal inside tmux:
|
||||
There are two options (aside from using "screen-256color") to allow programs to
|
||||
recognise they are running on a 256-colour terminal inside tmux:
|
||||
|
||||
- Manually force the application to use 256 colours always or if TERM is set to
|
||||
screen. For vim, you can do this by overriding the t_Co option, see
|
||||
http://vim.wikia.com/wiki/256_colors_in_vim.
|
||||
- If the platform includes it, using the "screen-256color" termcap (set
|
||||
TERM=screen-256color). "infocmp screen-256color" can be used to check if this
|
||||
is supported. It is not currently possible to set this globally inside tmux
|
||||
but it may be done in a shell startup script by checking if TERM is screen
|
||||
and exporting TERM=screen-256color instead.
|
||||
- Creating a custom terminfo file that includes Co#256 in ~/.terminfo and using
|
||||
it instead. These may be compiled with tic(1).
|
||||
- Creating a custom terminfo file that includes colors#256 in ~/.terminfo and
|
||||
using it instead. These may be compiled with tic(1).
|
||||
|
||||
* How do I make Ctrl-PgUp and Ctrl-PgDn work in vim?
|
||||
|
||||
@@ -187,11 +193,12 @@ Automatic window renaming may use a lot of CPU, particularly on slow computers:
|
||||
if this is a problem, turn it off with "setw -g automatic-rename off". If this
|
||||
doesn't fix it, please report the problem.
|
||||
|
||||
* How do I prevent tmux from resizing my PuTTY window?
|
||||
* I use PuTTY and my tmux window pane separators are all qqqqqqqqq's!
|
||||
|
||||
This isn't tmux's fault, but happens because the initialisation strings for the
|
||||
terminal in use (set through TERM) request it. PuTTY can be told to ignore such
|
||||
requests: in the configuration window under Terminal -> Features, check the
|
||||
"Disable remote-controlled terminal resizing" box.
|
||||
PuTTY is using a character set translation that doesn't support ACS line
|
||||
drawing. With a Unicode font, try setting PuTTY to use a different translation
|
||||
on the Window -> Translation configuration page. For example, change UTF-8 to
|
||||
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
|
||||
line drawing characters in the lower part of the same configuration page.
|
||||
|
||||
$Id: FAQ,v 1.23 2009-07-01 19:49:56 nicm Exp $
|
||||
$Id: FAQ,v 1.29 2009-08-08 20:46:26 nicm Exp $
|
||||
|
||||
53
GNUmakefile
53
GNUmakefile
@@ -1,22 +1,35 @@
|
||||
# $Id: GNUmakefile,v 1.107 2009-07-01 22:10:06 nicm Exp $
|
||||
# $Id: GNUmakefile,v 1.120 2009-11-05 12:30:55 tcunha Exp $
|
||||
#
|
||||
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
VERSION= 0.9
|
||||
VERSION= 1.1
|
||||
|
||||
#FDEBUG= 1
|
||||
|
||||
CC?= gcc
|
||||
CC?= cc
|
||||
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||
LDFLAGS+= -L/usr/local/lib
|
||||
LIBS+= -lncurses
|
||||
LIBS+=
|
||||
|
||||
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||
# most platforms...
|
||||
ifeq ($(shell (LC_ALL=C $(CC) -v 2>&1|awk '/gcc version 4/') || true), )
|
||||
CPPFLAGS:= -I. -I- $(CPPFLAGS)
|
||||
else
|
||||
CPPFLAGS:= -iquote. $(CPPFLAGS)
|
||||
# Sun CC
|
||||
ifneq ($(shell ($(CC) -V 2>&1|awk '/Sun C/' || true)), )
|
||||
CFLAGS+=-erroff=E_EMPTY_DECLARATION
|
||||
FDEBUG=
|
||||
endif
|
||||
|
||||
ifdef FDEBUG
|
||||
@@ -27,6 +40,17 @@ CFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
CFLAGS+= -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
endif
|
||||
|
||||
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||
# most platforms...
|
||||
ifeq ($(shell (LC_ALL=C $(CC) -v 2>&1|awk '/gcc version 4|clang/') || true), )
|
||||
CPPFLAGS:= -I. -I- $(CPPFLAGS)
|
||||
else
|
||||
CPPFLAGS:= -iquote. $(CPPFLAGS)
|
||||
ifdef FDEBUG
|
||||
CFLAGS+= -Wno-pointer-sign
|
||||
endif
|
||||
endif
|
||||
|
||||
PREFIX?= /usr/local
|
||||
INSTALLDIR= install -d
|
||||
INSTALLBIN= install -g bin -o root -m 555
|
||||
@@ -45,9 +69,12 @@ depend: $(SRCS)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -MM $(SRCS) > .depend
|
||||
|
||||
clean:
|
||||
rm -f tmux *.o .depend *~ *.core *.log compat/*.o
|
||||
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||
|
||||
clean-all: clean
|
||||
clean-depend:
|
||||
rm -f .depend
|
||||
|
||||
clean-all: clean clean-depend
|
||||
rm -f config.h config.mk
|
||||
|
||||
install: all
|
||||
@@ -55,3 +82,5 @@ install: all
|
||||
$(INSTALLBIN) tmux $(DESTDIR)$(PREFIX)/bin/tmux
|
||||
$(INSTALLDIR) $(DESTDIR)$(PREFIX)/man/man1
|
||||
$(INSTALLMAN) tmux.1 $(DESTDIR)$(PREFIX)/man/man1/tmux.1
|
||||
|
||||
-include .depend
|
||||
|
||||
49
Makefile
49
Makefile
@@ -1,25 +1,31 @@
|
||||
# $Id: Makefile,v 1.142 2009-07-01 22:10:06 nicm Exp $
|
||||
# $Id: Makefile,v 1.153 2009-11-05 12:30:55 tcunha Exp $
|
||||
#
|
||||
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
.PHONY: clean
|
||||
|
||||
VERSION= 0.9
|
||||
VERSION= 1.1
|
||||
|
||||
#FDEBUG= 1
|
||||
|
||||
CC?= cc
|
||||
CFLAGS+= -DBUILD="\"$(VERSION)\""
|
||||
LDFLAGS+= -L/usr/local/lib
|
||||
LIBS+= -lncurses
|
||||
|
||||
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||
# most platforms...
|
||||
CCV!= (LC_ALL=C ${CC} -v 2>&1|awk '/gcc version 4/') || true
|
||||
.if empty(CCV)
|
||||
CPPFLAGS:= -I. -I- -I/usr/local/include ${CPPFLAGS}
|
||||
.else
|
||||
CPPFLAGS:= -iquote. -I/usr/local/include ${CPPFLAGS}
|
||||
.endif
|
||||
LIBS+=
|
||||
|
||||
.ifdef FDEBUG
|
||||
CFLAGS+= -g -ggdb -DDEBUG
|
||||
@@ -29,6 +35,18 @@ CFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
CFLAGS+= -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
.endif
|
||||
|
||||
# This sort of sucks but gets rid of the stupid warning and should work on
|
||||
# most platforms...
|
||||
CCV!= (LC_ALL=C ${CC} -v 2>&1|awk '/gcc version 4|clang/') || true
|
||||
.if empty(CCV)
|
||||
CPPFLAGS:= -I. -I- -I/usr/local/include ${CPPFLAGS}
|
||||
.else
|
||||
CPPFLAGS:= -iquote. -I/usr/local/include ${CPPFLAGS}
|
||||
.ifdef FDEBUG
|
||||
CFLAGS+= -Wno-pointer-sign
|
||||
.endif
|
||||
.endif
|
||||
|
||||
PREFIX?= /usr/local
|
||||
INSTALLDIR= install -d
|
||||
INSTALLBIN= install -g bin -o root -m 555
|
||||
@@ -50,9 +68,12 @@ depend:
|
||||
mkdep ${CPPFLAGS} ${CFLAGS} ${SRCS:M*.c}
|
||||
|
||||
clean:
|
||||
rm -f tmux *.o .depend *~ *.core *.log compat/*.o
|
||||
rm -f tmux *.o *~ *.core *.log compat/*.o compat/*~
|
||||
|
||||
clean-all: clean
|
||||
clean-depend:
|
||||
rm -f .depend
|
||||
|
||||
clean-all: clean clean-depend
|
||||
rm -f config.h config.mk
|
||||
|
||||
install: all
|
||||
|
||||
33
NOTES
33
NOTES
@@ -4,15 +4,17 @@ tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||
|
||||
This 0.9 release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||
run on Solaris and AIX (although they hasn't been tested in a while). It is
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux and OS X and may still
|
||||
run on Solaris and AIX (although they haven't been tested in a while). It is
|
||||
usable, although there remain a number of missing features and some remaining
|
||||
bugs are expected.
|
||||
|
||||
If upgrading from 0.5, PLEASE NOTE the following configuration file changes: it
|
||||
is now required to pass the -g flag to set-option or set-window-option to set
|
||||
global options; remain-by-default and utf8-default are now gone, use global
|
||||
window options (set-window-option -g) instead.
|
||||
If upgrading from 1.0, PLEASE NOTE:
|
||||
- The internal locking mechanism has gone, so the set-password command and -U
|
||||
command line option have been removed.
|
||||
- The -d command line flag was dropped. It will now automatically detect the
|
||||
default colours by using op/AX. Nevertheless, if needed, the
|
||||
terminal-overrides session option can replace it.
|
||||
|
||||
tmux consists of a server part and multiple clients. The server is created when
|
||||
required and runs continuously unless killed by the user. Clients access the
|
||||
@@ -37,21 +39,14 @@ The following is a summary of major features implemented in this version:
|
||||
- Support for VT100 line drawing characters.
|
||||
- A large command set.
|
||||
- Vertical window splitting and layout.
|
||||
- Automatic server locking on inactivity.
|
||||
- Automatic server locking on inactivity by running an external command.
|
||||
- A configuration file.
|
||||
- UTF-8 support.
|
||||
|
||||
And major missing features:
|
||||
|
||||
- No support for programs changing termios(4) settings or other tty(4) ioctls.
|
||||
|
||||
A more extensive, but rough, todo list is included in the TODO file.
|
||||
|
||||
tmux also depends on several features of the client terminal (TERM), if these
|
||||
are missing it may refuse to run, or not behave correctly. Known working are
|
||||
TERM=screen (tmux in screen), xterm, xterm-color and rxvt. Note that TERM=xterm
|
||||
does not support colour on OpenBSD. screen ignores this, tmux does not: use
|
||||
xterm-color or rxvt for colour.
|
||||
are missing it may refuse to run, or not behave correctly.
|
||||
|
||||
tmux supports UTF-8. To use it, the utf8 option must be set on each window;
|
||||
this may be turned on for all windows by setting it as a global option, see
|
||||
@@ -85,6 +80,12 @@ welcome. Please send by email to:
|
||||
|
||||
nicm@users.sf.net
|
||||
|
||||
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
|
||||
license. Files under examples/ remain copyright their authors unless otherwise
|
||||
stated in the file but permission has been received to distribute them with
|
||||
tmux. All other files have a license and copyright notice at their
|
||||
start. Please contact me with any queries.
|
||||
|
||||
-- Nicholas Marriott <nicm@users.sf.net>
|
||||
|
||||
$Id: NOTES,v 1.48 2009-07-01 19:49:56 nicm Exp $
|
||||
$Id: NOTES,v 1.51 2009-11-05 12:35:47 tcunha Exp $
|
||||
|
||||
119
TODO
119
TODO
@@ -1,5 +1,4 @@
|
||||
- window creation/idle time
|
||||
- could use bsearch all over the place or get rid of smaller tables (clientmsg)
|
||||
- better errors when creating new windows/sessions (how?)
|
||||
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||
- it would be nice to have multichar commands eg C-b K K
|
||||
@@ -7,86 +6,92 @@
|
||||
extend list-clients to list clients attached to a session (-a for all?)
|
||||
bring back detach-session to detach all clients on a session?
|
||||
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||
- bind non prefix keys
|
||||
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||
in $x time (need window creation/use times)
|
||||
- lift SHRT_MAX limits for history?
|
||||
- audit copy/scroll and other modes for problems with very small windows
|
||||
- better mode features: search, back word, forward word, etc
|
||||
- flags to centre screen in window
|
||||
- better terminal emulation (identify, insert mode, some other bits)
|
||||
- audit for leftover/unused code
|
||||
- better terminal emulation
|
||||
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||
session not being watched?
|
||||
- tidy up window modes
|
||||
- next prev word etc in command prompt; also ^K
|
||||
- next prev word etc in command prompt
|
||||
- many more info() displays for various things
|
||||
- vi half page scroll
|
||||
- backspace should perhaps wrap backwards over newlines which were not moved
|
||||
down by a newline: screen and the OS X terminal does this but xterm and most
|
||||
others do not. this might be hard: a flag for each grid line (top bit of size
|
||||
maybe)? a single flag is insufficient as can't then tell when to /stop/
|
||||
unwrapping
|
||||
- input.c is too complicated. simplify?
|
||||
- use a better termcap internally instead of screen, perhaps xterm
|
||||
- kill all but current pane
|
||||
- fix rxvt cursor fg issue (text under cursor can have non-white fg)
|
||||
- key handling sucks a bit and may need to be reworked
|
||||
- some people find first window being 0 rather than 1 is awkward on the
|
||||
keyboard
|
||||
- client sx/sy should be in tty, then can let the terminal wrap at edge
|
||||
to allow xterm to pick up it should be one line for its c/p
|
||||
- should be able to move to a hidden pane and it would be moved into view. pane
|
||||
number in status line/top-right would be cool for this
|
||||
- command to run something without a window at all - output to
|
||||
window-more. what for? isnt this the same as doing it w/ splitw/neww now?
|
||||
- would be nice if tmux could be the shell (tmux attach, but hard link to tmux
|
||||
binary as "tmuxsh" or wrapper script?) problems with tty dev permissions
|
||||
- support other mouse modes (highlight etc) and use it in copy mode
|
||||
- set-remain-on-exit is a bit of a hack, some way to do it generically?
|
||||
- set-option should be set-session-option and should be overall global options
|
||||
for stuff like mode keys?
|
||||
also quiet, utf8 and maybe other flags?
|
||||
-g is a bit unexpected in conf file
|
||||
- clear window title on exit
|
||||
- refer to windows by name etc (duplicates? fnmatch?)
|
||||
- the output code (tty.c) could do with optimisation depending on term
|
||||
capibilities
|
||||
capabilities
|
||||
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||
to avoid quoting
|
||||
|
||||
- goto line and search history in copy/scroll modes
|
||||
- a command to display the status line briefly when it is turned off
|
||||
- clone session command
|
||||
- make command sequences more usable: don't require space after ;, handle
|
||||
errors better
|
||||
- might be nice if attach-session behaved like switch-client inside an
|
||||
existing client
|
||||
- key to switch to copy mode from scroll mode
|
||||
- attach should have a flag to create session if it doesn't exist
|
||||
- layout/split stuff:
|
||||
** NEW layout design:
|
||||
1. finish rewrite manual with tree of layout_cell
|
||||
2. convert automatic layout modes to produce a tree and make
|
||||
them one-off operations
|
||||
3. move any size/position details from window_pane to layout_cell
|
||||
3.5. fix -p/-l on split
|
||||
4. a way to address panes by name ("top-left") and position ("0,0")
|
||||
TO TEST: force-width/height OK, respawn-window, rotate-window OK, break-pane??
|
||||
** rename split-window -> split-pane
|
||||
- fix UTF-8 guesswork on sparc64, improve tty checks
|
||||
- choice and more mode would be better per client than per window?
|
||||
- hooks to which commands may be attached, for example: tmux add-hook
|
||||
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
|
||||
$HOME/.tmux-session.conf
|
||||
- get it passing all the vttest tests that don't require resizing the terminal
|
||||
- esc seq to set window title should be documented and should set
|
||||
automatic-rename
|
||||
- way to set socket path from config file
|
||||
- XXX once env stuff is in, default-path and VISUAL/EDITOR should be picked up
|
||||
when session is started
|
||||
- what about utmp etc? can tmux update it like screen? setgid?
|
||||
- warts on current naming:
|
||||
- display-time but message-fg/bg/attr
|
||||
- list-* vs show-*
|
||||
- server-info
|
||||
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
|
||||
- split-window -> split-pane??
|
||||
- tidy up and prioritise todo list ;-)
|
||||
- neww and attach can create a session if none exists?
|
||||
would work fine with config file since
|
||||
- a way for force-width/height to apply to only one pane (how?)
|
||||
- command to list what is actually running in each window with command line,
|
||||
pid (need some adaption of the osdep code)
|
||||
- string option to change/remove the symbols (*-+ etc) in status line
|
||||
* or to set entire format, eg window-list-format '#N:#W#P' or something,
|
||||
then could use embedded colours
|
||||
- support for bce
|
||||
- it would be nice if the start/end line keys in copy mode were aware of
|
||||
wrapped lines
|
||||
- some way to force a screen to use the entire terminal even if it is forced
|
||||
to be smaller by other clients. pan smaller terminal? (like screen F)
|
||||
- close/redirect stderr when popen to child proc for #() in status line
|
||||
- if-shell-command command to run a tmux command if a shell command returns true
|
||||
- hooks to which commands may be attached, for example:
|
||||
tmux add-hook "new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file $HOME/.tmux-session.conf
|
||||
- get it passing all the vttest tests that don't require resizing the terminal
|
||||
- does tmux require a exmple conf? where does it go?
|
||||
- there are an awful lot of commands. maybe separate man page for conf
|
||||
file/commands -similar to ssh/ssh_config?
|
||||
- esc seq to set window title should be documented and should set automatic-rename
|
||||
- *** get rid of PANE_HIDDEN -- initially just check for outside window
|
||||
- way to set socket path from config file
|
||||
- the "window with one pane" vs window distinction is weird, eg you can't kill-pane the last pane
|
||||
-- idea of a "view" onto a window, need base x/y offsets
|
||||
for redraw
|
||||
- handle resize better in copy mode
|
||||
- way to copy stuff that is off screen due to resize
|
||||
- a way to address panes by name ("top-left") and position ("0,0")
|
||||
- commands should be able to succeed or fail and have || or && for command
|
||||
lists
|
||||
- support the mouse wheel to scroll through history
|
||||
- some way to KEEP a command running continually and just use its LAST line of
|
||||
output
|
||||
- bind commands to mouse buttons
|
||||
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||
the terminal - www/ruby-addressable; make regress
|
||||
- copy mode needs a tidy/cleanup
|
||||
- things like display-message will leak job entries if #() is used
|
||||
- message log
|
||||
- an option to NOT remove message when key pressed
|
||||
- would be nice to be able to press 0-9a-zA-Z to select window in choose-window
|
||||
mode, also to start typing and it searches
|
||||
- the wrapping stuff should work when redrawn from scroll mode too (screen_write_copy)
|
||||
- ability to save history (to buffer?)
|
||||
- multiple keys could be done with tables, ie have prefixes go and instead
|
||||
bind -n ^A prefix-table "default"
|
||||
where prefix-table sets command lookup table and sets prefix flag, then next key
|
||||
is looked up in that table
|
||||
- check fix UTF-8 and split-window? should be okay
|
||||
- UTF-8 should be a pointer into a combined string buffer
|
||||
- check irssi (term_charset) works with UTF-8
|
||||
- rectangle copy/paste
|
||||
- half page/up down are missing from key table
|
||||
- support esc-esc to quit in modes
|
||||
|
||||
194
arg.c
194
arg.c
@@ -1,194 +0,0 @@
|
||||
/* $Id: arg.c,v 1.6 2009-06-25 15:25:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct client *arg_lookup_client(const char *);
|
||||
struct session *arg_lookup_session(const char *);
|
||||
|
||||
struct client *
|
||||
arg_lookup_client(const char *name)
|
||||
{
|
||||
struct client *c;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && strcmp(name, c->tty.path) == 0)
|
||||
return (c);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct session *
|
||||
arg_lookup_session(const char *name)
|
||||
{
|
||||
struct session *s, *newest = NULL;
|
||||
struct timeval *tv;
|
||||
u_int i;
|
||||
|
||||
tv = NULL;
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL || fnmatch(name, s->name, 0) != 0)
|
||||
continue;
|
||||
|
||||
if (tv == NULL || timercmp(&s->tv, tv, >)) {
|
||||
newest = s;
|
||||
tv = &s->tv;
|
||||
}
|
||||
}
|
||||
|
||||
return (newest);
|
||||
}
|
||||
|
||||
struct client *
|
||||
arg_parse_client(const char *arg)
|
||||
{
|
||||
struct client *c;
|
||||
char *arg2;
|
||||
size_t n;
|
||||
|
||||
if (arg != NULL && (arg[0] != ':' || arg[1] != '\0')) {
|
||||
arg2 = xstrdup(arg);
|
||||
|
||||
/* Trim a trailing : if any from the argument. */
|
||||
n = strlen(arg2);
|
||||
if (n && arg2[n - 1] == ':')
|
||||
arg2[n - 1] = '\0';
|
||||
|
||||
/* Try and look up the client name. */
|
||||
c = arg_lookup_client(arg2);
|
||||
xfree(arg2);
|
||||
return (c);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct session *
|
||||
arg_parse_session(const char *arg)
|
||||
{
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
char *arg2;
|
||||
size_t n;
|
||||
|
||||
if (arg != NULL && (arg[0] != ':' || arg[1] != '\0')) {
|
||||
arg2 = xstrdup(arg);
|
||||
|
||||
/* Trim a trailing : if any from the argument. */
|
||||
n = strlen(arg2);
|
||||
if (n && arg2[n - 1] == ':')
|
||||
arg2[n - 1] = '\0';
|
||||
|
||||
/* See if the argument matches a session. */
|
||||
if ((s = arg_lookup_session(arg2)) != NULL) {
|
||||
xfree(arg2);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* If not try a client. */
|
||||
if ((c = arg_lookup_client(arg2)) != NULL) {
|
||||
xfree(arg2);
|
||||
return (c->session);
|
||||
}
|
||||
|
||||
xfree(arg2);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
arg_parse_window(const char *arg, struct session **s, int *idx)
|
||||
{
|
||||
char *arg2, *ptr;
|
||||
const char *errstr;
|
||||
|
||||
*idx = -1;
|
||||
|
||||
/* Handle no argument or a single :. */
|
||||
if (arg == NULL || (arg[0] == ':' && arg[1] == '\0')) {
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find the separator if any. */
|
||||
arg2 = xstrdup(arg);
|
||||
ptr = strrchr(arg2, ':');
|
||||
|
||||
/*
|
||||
* If it is first, this means no session name, so use current session
|
||||
* and try to convert the rest as index.
|
||||
*/
|
||||
if (ptr == arg2) {
|
||||
*idx = strtonum(ptr + 1, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xfree(arg2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
xfree(arg2);
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* If missing, try as an index, else look up immediately. */
|
||||
if (ptr == NULL) {
|
||||
*idx = strtonum(arg2, 0, INT_MAX, &errstr);
|
||||
if (errstr == NULL) {
|
||||
/* This is good as an index; use current session. */
|
||||
xfree(arg2);
|
||||
*s = arg_parse_session(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
*idx = -1;
|
||||
goto lookup;
|
||||
}
|
||||
|
||||
/* If last, strip it and look up as a session. */
|
||||
if (ptr[1] == '\0') {
|
||||
*ptr = '\0';
|
||||
goto lookup;
|
||||
}
|
||||
|
||||
/* Present but not first and not last. Break and convert both. */
|
||||
*ptr = '\0';
|
||||
*idx = strtonum(ptr + 1, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xfree(arg2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
lookup:
|
||||
/* Look up as session. */
|
||||
*s = arg_parse_session(arg2);
|
||||
xfree(arg2);
|
||||
if (*s == NULL)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
6
array.h
6
array.h
@@ -1,4 +1,4 @@
|
||||
/* $Id: array.h,v 1.7 2008-09-29 16:58:02 nicm Exp $ */
|
||||
/* $Id: array.h,v 1.9 2009-11-02 21:34:32 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -85,7 +85,7 @@
|
||||
ARRAY_ITEMSIZE(a) * ((a)->num - (i) - 1)); \
|
||||
} \
|
||||
(a)->num--; \
|
||||
if ((a)->num == 0) \
|
||||
if ((a)->num == 0) \
|
||||
ARRAY_FREE(a); \
|
||||
} while (0)
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
|
||||
#define ARRAY_CONCAT(a, b) do { \
|
||||
ARRAY_ENSURE(a, (b)->num); \
|
||||
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)) \
|
||||
memcpy((a)->list + (a)->num, (b)->list, (b)->num * ARRAY_ITEMSIZE(a)); \
|
||||
(a)->num += (b)->num; \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: buffer-poll.c,v 1.14 2009-06-25 16:22:36 nicm Exp $ */
|
||||
/* $Id: buffer-poll.c,v 1.18 2009-10-23 17:49:47 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -25,17 +25,15 @@
|
||||
|
||||
/* Fill buffers from socket based on poll results. */
|
||||
int
|
||||
buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out)
|
||||
buffer_poll(int fd, int events, struct buffer *in, struct buffer *out)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP))
|
||||
if (events & (POLLERR|POLLNVAL))
|
||||
return (-1);
|
||||
#endif
|
||||
if (pfd->revents & POLLIN) {
|
||||
if (in != NULL && events & POLLIN) {
|
||||
buffer_ensure(in, BUFSIZ);
|
||||
n = read(pfd->fd, BUFFER_IN(in), BUFFER_FREE(in));
|
||||
n = read(fd, BUFFER_IN(in), BUFFER_FREE(in));
|
||||
if (n == 0)
|
||||
return (-1);
|
||||
if (n == -1) {
|
||||
@@ -43,9 +41,10 @@ buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out)
|
||||
return (-1);
|
||||
} else
|
||||
buffer_add(in, n);
|
||||
}
|
||||
if (BUFFER_USED(out) > 0 && pfd->revents & POLLOUT) {
|
||||
n = write(pfd->fd, BUFFER_OUT(out), BUFFER_USED(out));
|
||||
} else if (events & POLLHUP)
|
||||
return (-1);
|
||||
if (out != NULL && BUFFER_USED(out) > 0 && events & POLLOUT) {
|
||||
n = write(fd, BUFFER_OUT(out), BUFFER_USED(out));
|
||||
if (n == -1) {
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
return (-1);
|
||||
|
||||
7
buffer.c
7
buffer.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: buffer.c,v 1.7 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: buffer.c,v 1.8 2009-08-21 21:09:13 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -100,9 +100,6 @@ buffer_remove(struct buffer *b, size_t size)
|
||||
void
|
||||
buffer_write(struct buffer *b, const void *data, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
fatalx("zero size");
|
||||
|
||||
buffer_ensure(b, size);
|
||||
memcpy(BUFFER_IN(b), data, size);
|
||||
buffer_add(b, size);
|
||||
@@ -127,7 +124,7 @@ buffer_write8(struct buffer *b, uint8_t n)
|
||||
{
|
||||
buffer_ensure(b, 1);
|
||||
BUFFER_IN(b)[0] = n;
|
||||
buffer_add(b, 1);
|
||||
b->size++;
|
||||
}
|
||||
|
||||
/* Extract an 8-bit value. */
|
||||
|
||||
34
cfg.c
34
cfg.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cfg.c,v 1.18 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cfg.c,v 1.23 2009-10-28 23:12:38 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -51,25 +51,15 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
}
|
||||
|
||||
int
|
||||
load_cfg(const char *path, char **cause)
|
||||
load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
|
||||
{
|
||||
FILE *f;
|
||||
FILE *f;
|
||||
u_int n;
|
||||
struct stat sb;
|
||||
char *buf, *line, *ptr;
|
||||
char *buf, *line, *ptr;
|
||||
size_t len;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
|
||||
if (stat(path, &sb) != 0) {
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (!S_ISREG(sb.st_mode)) {
|
||||
xasprintf(cause, "%s: not a regular file", path);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
return (1);
|
||||
@@ -97,16 +87,20 @@ load_cfg(const char *path, char **cause)
|
||||
continue;
|
||||
cfg_cause = NULL;
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = NULL;
|
||||
ctx.curclient = NULL;
|
||||
if (ctxin == NULL) {
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = NULL;
|
||||
ctx.cmdclient = NULL;
|
||||
} else {
|
||||
ctx.msgdata = ctxin->msgdata;
|
||||
ctx.curclient = ctxin->curclient;
|
||||
ctx.cmdclient = ctxin->cmdclient;
|
||||
}
|
||||
|
||||
ctx.error = cfg_error;
|
||||
ctx.print = cfg_print;
|
||||
ctx.info = cfg_print;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cfg_cause = NULL;
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
@@ -122,6 +116,8 @@ load_cfg(const char *path, char **cause)
|
||||
return (0);
|
||||
|
||||
error:
|
||||
if (line != NULL)
|
||||
xfree(line);
|
||||
fclose(f);
|
||||
|
||||
xasprintf(&ptr, "%s: %s at line %u", path, *cause, n);
|
||||
|
||||
92
client-fn.c
92
client-fn.c
@@ -1,92 +0,0 @@
|
||||
/* $Id: client-fn.c,v 1.6 2009-03-04 17:24:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void
|
||||
client_fill_session(struct msg_command_data *data)
|
||||
{
|
||||
char *env, *ptr1, *ptr2, buf[256];
|
||||
size_t len;
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
|
||||
data->pid = -1;
|
||||
if ((env = getenv("TMUX")) == NULL)
|
||||
return;
|
||||
|
||||
if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
|
||||
return;
|
||||
for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
|
||||
;
|
||||
if (*ptr1 != ',')
|
||||
return;
|
||||
ptr1++;
|
||||
ptr2++;
|
||||
|
||||
len = ptr2 - ptr1 - 1;
|
||||
if (len > (sizeof buf) - 1)
|
||||
return;
|
||||
memcpy(buf, ptr1, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
ll = strtonum(buf, 0, LONG_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return;
|
||||
data->pid = ll;
|
||||
|
||||
ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return;
|
||||
data->idx = ll;
|
||||
}
|
||||
|
||||
void
|
||||
client_write_server(
|
||||
struct client_ctx *cctx, enum hdrtype type, void *buf, size_t len)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len;
|
||||
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
|
||||
|
||||
if (buf != NULL && len > 0)
|
||||
buffer_write(cctx->srv_out, buf, len);
|
||||
}
|
||||
|
||||
void
|
||||
client_write_server2(struct client_ctx *cctx,
|
||||
enum hdrtype type, void *buf1, size_t len1, void *buf2, size_t len2)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len1 + len2;
|
||||
buffer_write(cctx->srv_out, &hdr, sizeof hdr);
|
||||
|
||||
if (buf1 != NULL && len1 > 0)
|
||||
buffer_write(cctx->srv_out, buf1, len1);
|
||||
if (buf2 != NULL && len2 > 0)
|
||||
buffer_write(cctx->srv_out, buf2, len2);
|
||||
}
|
||||
159
client-msg.c
159
client-msg.c
@@ -1,159 +0,0 @@
|
||||
/* $Id: client-msg.c,v 1.19 2009-06-25 15:25:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
int client_msg_fn_detach(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_error(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_shutdown(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_exited(struct hdr *, struct client_ctx *, char **);
|
||||
int client_msg_fn_suspend(struct hdr *, struct client_ctx *, char **);
|
||||
|
||||
struct client_msg {
|
||||
enum hdrtype type;
|
||||
int (*fn)(struct hdr *, struct client_ctx *, char **);
|
||||
};
|
||||
struct client_msg client_msg_table[] = {
|
||||
{ MSG_DETACH, client_msg_fn_detach },
|
||||
{ MSG_ERROR, client_msg_fn_error },
|
||||
{ MSG_EXIT, client_msg_fn_exit },
|
||||
{ MSG_EXITED, client_msg_fn_exited },
|
||||
{ MSG_SHUTDOWN, client_msg_fn_shutdown },
|
||||
{ MSG_SUSPEND, client_msg_fn_suspend },
|
||||
};
|
||||
|
||||
int
|
||||
client_msg_dispatch(struct client_ctx *cctx, char **error)
|
||||
{
|
||||
struct hdr hdr;
|
||||
struct client_msg *msg;
|
||||
u_int i;
|
||||
|
||||
if (BUFFER_USED(cctx->srv_in) < sizeof hdr)
|
||||
return (1);
|
||||
memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
|
||||
if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
|
||||
return (1);
|
||||
buffer_remove(cctx->srv_in, sizeof hdr);
|
||||
|
||||
for (i = 0; i < nitems(client_msg_table); i++) {
|
||||
msg = client_msg_table + i;
|
||||
if (msg->type == hdr.type) {
|
||||
if (msg->fn(&hdr, cctx, error) != 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
|
||||
{
|
||||
if (hdr->size == SIZE_MAX)
|
||||
fatalx("bad MSG_ERROR size");
|
||||
|
||||
*error = xmalloc(hdr->size + 1);
|
||||
buffer_read(cctx->srv_in, *error, hdr->size);
|
||||
(*error)[hdr->size] = '\0';
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_detach(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_DETACH size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_DETACH;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_shutdown(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_SHUTDOWN size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_SHUTDOWN;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_exit(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
client_write_server(cctx, MSG_EXITING, NULL, 0);
|
||||
cctx->flags |= CCTX_EXIT;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_exited(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_EXITED size");
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_suspend(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_SUSPEND size");
|
||||
|
||||
memset(&act, 0, sizeof act);
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_RESTART;
|
||||
|
||||
act.sa_handler = SIG_DFL;
|
||||
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
act.sa_handler = sighandler;
|
||||
if (sigaction(SIGCONT, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
kill(getpid(), SIGTSTP);
|
||||
|
||||
return (0);
|
||||
}
|
||||
338
client.c
338
client.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: client.c,v 1.53 2009-07-01 23:06:32 nicm Exp $ */
|
||||
/* $Id: client.c,v 1.84 2009-11-02 21:41:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -33,21 +33,23 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void client_handle_winch(struct client_ctx *);
|
||||
struct imsgbuf client_ibuf;
|
||||
const char *client_exitmsg;
|
||||
|
||||
int
|
||||
client_init(char *path, struct client_ctx *cctx, int start_server, int flags)
|
||||
void client_send_identify(int);
|
||||
void client_send_environ(void);
|
||||
void client_write_server(enum msgtype, void *, size_t);
|
||||
int client_dispatch(void);
|
||||
void client_suspend(void);
|
||||
|
||||
struct imsgbuf *
|
||||
client_init(char *path, int cmdflags, int flags)
|
||||
{
|
||||
struct sockaddr_un sa;
|
||||
struct stat sb;
|
||||
struct msg_identify_data data;
|
||||
struct winsize ws;
|
||||
size_t size;
|
||||
int mode;
|
||||
struct buffer *b;
|
||||
char *name;
|
||||
struct sockaddr_un sa;
|
||||
size_t size;
|
||||
int fd, mode;
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
char rpathbuf[MAXPATHLEN];
|
||||
char rpathbuf[MAXPATHLEN];
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
@@ -56,19 +58,6 @@ client_init(char *path, struct client_ctx *cctx, int start_server, int flags)
|
||||
setproctitle("client (%s)", rpathbuf);
|
||||
#endif
|
||||
|
||||
if (lstat(path, &sb) != 0) {
|
||||
if (start_server && errno == ENOENT) {
|
||||
if ((cctx->srv_fd = server_start(path)) == -1)
|
||||
goto start_failed;
|
||||
goto server_started;
|
||||
}
|
||||
goto not_found;
|
||||
}
|
||||
if (!S_ISSOCK(sb.st_mode)) {
|
||||
errno = ENOTSOCK;
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
memset(&sa, 0, sizeof sa);
|
||||
sa.sun_family = AF_UNIX;
|
||||
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
||||
@@ -77,15 +66,19 @@ client_init(char *path, struct client_ctx *cctx, int start_server, int flags)
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
if ((cctx->srv_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
fatal("socket");
|
||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
fatal("socket failed");
|
||||
|
||||
if (connect(
|
||||
cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||
if (errno == ECONNREFUSED) {
|
||||
if (unlink(path) != 0 || !start_server)
|
||||
if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||
if (!(cmdflags & CMD_STARTSERVER))
|
||||
goto not_found;
|
||||
switch (errno) {
|
||||
case ECONNREFUSED:
|
||||
if (unlink(path) != 0)
|
||||
goto not_found;
|
||||
if ((cctx->srv_fd = server_start(path)) == -1)
|
||||
/* FALLTHROUGH */
|
||||
case ENOENT:
|
||||
if ((fd = server_start(path)) == -1)
|
||||
goto start_failed;
|
||||
goto server_started;
|
||||
}
|
||||
@@ -93,141 +86,240 @@ client_init(char *path, struct client_ctx *cctx, int start_server, int flags)
|
||||
}
|
||||
|
||||
server_started:
|
||||
if ((mode = fcntl(cctx->srv_fd, F_GETFL)) == -1)
|
||||
if ((mode = fcntl(fd, F_GETFL)) == -1)
|
||||
fatal("fcntl failed");
|
||||
if (fcntl(cctx->srv_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||
if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||
fatal("fcntl failed");
|
||||
cctx->srv_in = buffer_create(BUFSIZ);
|
||||
cctx->srv_out = buffer_create(BUFSIZ);
|
||||
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
fatal("fcntl failed");
|
||||
imsg_init(&client_ibuf, fd);
|
||||
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||
fatal("ioctl(TIOCGWINSZ)");
|
||||
data.version = PROTOCOL_VERSION;
|
||||
data.flags = flags;
|
||||
data.sx = ws.ws_col;
|
||||
data.sy = ws.ws_row;
|
||||
*data.tty = '\0';
|
||||
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||
*data.cwd = '\0';
|
||||
if (cmdflags & CMD_SENDENVIRON)
|
||||
client_send_environ();
|
||||
if (isatty(STDIN_FILENO))
|
||||
client_send_identify(flags);
|
||||
|
||||
if ((name = ttyname(STDIN_FILENO)) == NULL)
|
||||
fatal("ttyname failed");
|
||||
if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty)
|
||||
fatalx("ttyname failed");
|
||||
|
||||
b = buffer_create(BUFSIZ);
|
||||
cmd_send_string(b, getenv("TERM"));
|
||||
client_write_server2(cctx, MSG_IDENTIFY,
|
||||
&data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b));
|
||||
buffer_destroy(b);
|
||||
}
|
||||
|
||||
return (0);
|
||||
return (&client_ibuf);
|
||||
|
||||
start_failed:
|
||||
log_warnx("server failed to start");
|
||||
return (1);
|
||||
return (NULL);
|
||||
|
||||
not_found:
|
||||
log_warn("server not found");
|
||||
return (1);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
client_main(struct client_ctx *cctx)
|
||||
void
|
||||
client_send_identify(int flags)
|
||||
{
|
||||
struct msg_identify_data data;
|
||||
struct winsize ws;
|
||||
char *term;
|
||||
int fd;
|
||||
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||
fatal("ioctl(TIOCGWINSZ)");
|
||||
data.flags = flags;
|
||||
|
||||
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||
*data.cwd = '\0';
|
||||
|
||||
term = getenv("TERM");
|
||||
if (term == NULL ||
|
||||
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
|
||||
*data.term = '\0';
|
||||
|
||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||
fatal("dup failed");
|
||||
imsg_compose(&client_ibuf,
|
||||
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
||||
}
|
||||
|
||||
void
|
||||
client_send_environ(void)
|
||||
{
|
||||
struct msg_environ_data data;
|
||||
char **var;
|
||||
|
||||
for (var = environ; *var != NULL; var++) {
|
||||
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
|
||||
continue;
|
||||
client_write_server(MSG_ENVIRON, &data, sizeof data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
client_write_server(enum msgtype type, void *buf, size_t len)
|
||||
{
|
||||
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
||||
}
|
||||
|
||||
__dead void
|
||||
client_main(void)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
char *error;
|
||||
int xtimeout; /* Yay for ncurses namespace! */
|
||||
int n, nfds;
|
||||
|
||||
siginit();
|
||||
|
||||
logfile("client");
|
||||
|
||||
error = NULL;
|
||||
while (!sigterm) {
|
||||
/*
|
||||
* imsg_read in the first client poll loop (before the terminal has
|
||||
* been initialiased) may have read messages into the buffer after the
|
||||
* MSG_READY switched to here. Process anything outstanding now so poll
|
||||
* doesn't hang waiting for messages that have already arrived.
|
||||
*/
|
||||
if (client_dispatch() != 0)
|
||||
goto out;
|
||||
|
||||
for (;;) {
|
||||
if (sigterm) {
|
||||
client_exitmsg = "terminated";
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
}
|
||||
if (sigchld) {
|
||||
waitpid(WAIT_ANY, NULL, WNOHANG);
|
||||
sigchld = 0;
|
||||
waitpid(WAIT_ANY, NULL, WNOHANG);
|
||||
continue;
|
||||
}
|
||||
if (sigwinch) {
|
||||
sigwinch = 0;
|
||||
client_write_server(MSG_RESIZE, NULL, 0);
|
||||
continue;
|
||||
}
|
||||
if (sigwinch)
|
||||
client_handle_winch(cctx);
|
||||
if (sigcont) {
|
||||
siginit();
|
||||
client_write_server(cctx, MSG_WAKEUP, NULL, 0);
|
||||
sigcont = 0;
|
||||
siginit();
|
||||
client_write_server(MSG_WAKEUP, NULL, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (client_msg_dispatch(cctx, &error)) {
|
||||
case -1:
|
||||
goto out;
|
||||
case 0:
|
||||
/* May be more in buffer, don't let poll block. */
|
||||
xtimeout = 0;
|
||||
break;
|
||||
default:
|
||||
/* Out of data, poll may block. */
|
||||
xtimeout = INFTIM;
|
||||
break;
|
||||
}
|
||||
|
||||
pfd.fd = cctx->srv_fd;
|
||||
pfd.fd = client_ibuf.fd;
|
||||
pfd.events = POLLIN;
|
||||
if (BUFFER_USED(cctx->srv_out) > 0)
|
||||
if (client_ibuf.w.queued > 0)
|
||||
pfd.events |= POLLOUT;
|
||||
|
||||
if (poll(&pfd, 1, xtimeout) == -1) {
|
||||
if ((nfds = poll(&pfd, 1, INFTIM)) == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
continue;
|
||||
fatal("poll failed");
|
||||
}
|
||||
if (nfds == 0)
|
||||
continue;
|
||||
|
||||
if (buffer_poll(&pfd, cctx->srv_in, cctx->srv_out) != 0)
|
||||
goto server_dead;
|
||||
if (pfd.revents & (POLLERR|POLLHUP|POLLNVAL))
|
||||
fatalx("socket error");
|
||||
|
||||
if (pfd.revents & POLLIN) {
|
||||
if ((n = imsg_read(&client_ibuf)) == -1 || n == 0) {
|
||||
client_exitmsg = "lost server";
|
||||
break;
|
||||
}
|
||||
if (client_dispatch() != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pfd.revents & POLLOUT) {
|
||||
if (msgbuf_write(&client_ibuf.w) < 0) {
|
||||
client_exitmsg = "lost server";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (sigterm) {
|
||||
printf("[terminated]\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_SHUTDOWN) {
|
||||
printf("[server exited]\n");
|
||||
return (0);
|
||||
/* Print the exit message, if any, and exit. */
|
||||
if (client_exitmsg != NULL) {
|
||||
if (!login_shell)
|
||||
printf("[%s]\n", client_exitmsg);
|
||||
exit(1);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_EXIT) {
|
||||
printf("[exited]\n");
|
||||
return (0);
|
||||
int
|
||||
client_dispatch(void)
|
||||
{
|
||||
struct imsg imsg;
|
||||
struct msg_lock_data lockdata;
|
||||
ssize_t n, datalen;
|
||||
|
||||
for (;;) {
|
||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||
fatalx("imsg_get failed");
|
||||
if (n == 0)
|
||||
return (0);
|
||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||
|
||||
switch (imsg.hdr.type) {
|
||||
case MSG_DETACH:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_DETACH size");
|
||||
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
client_exitmsg = "detached";
|
||||
break;
|
||||
case MSG_EXIT:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
client_exitmsg = "exited";
|
||||
break;
|
||||
case MSG_EXITED:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_EXITED size");
|
||||
|
||||
imsg_free(&imsg);
|
||||
return (-1);
|
||||
case MSG_SHUTDOWN:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_SHUTDOWN size");
|
||||
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
client_exitmsg = "server exited";
|
||||
break;
|
||||
case MSG_SUSPEND:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_SUSPEND size");
|
||||
|
||||
client_suspend();
|
||||
break;
|
||||
case MSG_LOCK:
|
||||
if (datalen != sizeof lockdata)
|
||||
fatalx("bad MSG_LOCK size");
|
||||
memcpy(&lockdata, imsg.data, sizeof lockdata);
|
||||
|
||||
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
|
||||
system(lockdata.cmd);
|
||||
client_write_server(MSG_UNLOCK, NULL, 0);
|
||||
break;
|
||||
default:
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
imsg_free(&imsg);
|
||||
}
|
||||
|
||||
if (cctx->flags & CCTX_DETACH) {
|
||||
printf("[detached]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("[error: %s]\n", error);
|
||||
return (1);
|
||||
|
||||
server_dead:
|
||||
printf("[lost server]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
client_handle_winch(struct client_ctx *cctx)
|
||||
client_suspend(void)
|
||||
{
|
||||
struct msg_resize_data data;
|
||||
struct winsize ws;
|
||||
struct sigaction act;
|
||||
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||
fatal("ioctl failed");
|
||||
memset(&act, 0, sizeof act);
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = SA_RESTART;
|
||||
|
||||
data.sx = ws.ws_col;
|
||||
data.sy = ws.ws_row;
|
||||
client_write_server(cctx, MSG_RESIZE, &data, sizeof data);
|
||||
act.sa_handler = SIG_DFL;
|
||||
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
sigwinch = 0;
|
||||
act.sa_handler = sighandler;
|
||||
if (sigaction(SIGCONT, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
kill(getpid(), SIGTSTP);
|
||||
}
|
||||
|
||||
16
clock.c
16
clock.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: clock.c,v 1.4 2009-05-04 17:58:25 nicm Exp $ */
|
||||
/* $Id: clock.c,v 1.7 2009-09-11 14:13:52 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -112,8 +112,6 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
|
||||
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||
|
||||
screen_write_clearscreen(ctx);
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
gc.fg = colour;
|
||||
|
||||
if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
|
||||
if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
|
||||
@@ -121,7 +119,8 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
|
||||
y = screen_size_y(s) / 2;
|
||||
screen_write_cursormove(ctx, x, y);
|
||||
|
||||
gc.fg = colour;
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
colour_set_fg(&gc, colour);
|
||||
screen_write_puts(ctx, &gc, "%s", tim);
|
||||
}
|
||||
return;
|
||||
@@ -130,6 +129,8 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
|
||||
x = (screen_size_x(s) / 2) - 3 * strlen(tim);
|
||||
y = (screen_size_y(s) / 2) - 3;
|
||||
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
colour_set_bg(&gc, colour);
|
||||
for (ptr = tim; *ptr != '\0'; ptr++) {
|
||||
if (*ptr >= '0' && *ptr <= '9')
|
||||
idx = *ptr - '0';
|
||||
@@ -147,13 +148,10 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
|
||||
}
|
||||
|
||||
for (j = 0; j < 5; j++) {
|
||||
screen_write_cursormove(ctx, x, y + j);
|
||||
for (i = 0; i < 5; i++) {
|
||||
screen_write_cursormove(ctx, x + i, y + j);
|
||||
if (clock_table[idx][j][i])
|
||||
gc.attr |= GRID_ATTR_REVERSE;
|
||||
else
|
||||
gc.attr &= ~GRID_ATTR_REVERSE;
|
||||
screen_write_putc(ctx, &gc, ' ');
|
||||
screen_write_putc(ctx, &gc, ' ');
|
||||
}
|
||||
}
|
||||
x += 6;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-attach-session.c,v 1.26 2009-06-25 16:34:50 nicm Exp $ */
|
||||
/* $Id: cmd-attach-session.c,v 1.32 2009-08-09 17:48:55 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_attach_session_entry = {
|
||||
"attach-session", "attach",
|
||||
"[-d] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_DFLAG|CMD_CANTNEST|CMD_STARTSERVER,
|
||||
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, CMD_CHFLAG('d'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_attach_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,10 +42,10 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
char *cause;
|
||||
|
||||
if (ctx->curclient != NULL)
|
||||
return (0);
|
||||
struct client *c;
|
||||
const char *update;
|
||||
char *overrides, *cause;
|
||||
u_int i;
|
||||
|
||||
if (ARRAY_LENGTH(&sessions) == 0) {
|
||||
ctx->error(ctx, "no sessions");
|
||||
@@ -56,24 +54,53 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||
return (0);
|
||||
|
||||
if (ctx->cmdclient == NULL) {
|
||||
if (data->chflags & CMD_CHFLAG('d')) {
|
||||
/*
|
||||
* Can't use server_write_session in case attaching to
|
||||
* the same session as currently attached to.
|
||||
*/
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (c == ctx->curclient)
|
||||
continue;
|
||||
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ctx->curclient->session = s;
|
||||
server_redraw_client(ctx->curclient);
|
||||
} else {
|
||||
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
overrides =
|
||||
options_get_string(&s->options, "terminal-overrides");
|
||||
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->chflags & CMD_CHFLAG('d'))
|
||||
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||
|
||||
ctx->cmdclient->session = s;
|
||||
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||
|
||||
update = options_get_string(&s->options, "update-environment");
|
||||
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
}
|
||||
|
||||
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
|
||||
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||
ctx->cmdclient->session = s;
|
||||
|
||||
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||
recalculate_sizes();
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
|
||||
return (1);
|
||||
return (1); /* 1 means don't tell command client to exit */
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-bind-key.c,v 1.21 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-bind-key.c,v 1.25 2009-07-28 23:19:06 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -26,26 +28,28 @@
|
||||
|
||||
int cmd_bind_key_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_bind_key_send(struct cmd *, struct buffer *);
|
||||
void cmd_bind_key_recv(struct cmd *, struct buffer *);
|
||||
void cmd_bind_key_free(struct cmd *);
|
||||
size_t cmd_bind_key_print(struct cmd *, char *, size_t);
|
||||
|
||||
int cmd_bind_key_table(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
struct cmd_bind_key_data {
|
||||
int key;
|
||||
int can_repeat;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
int command_key;
|
||||
char *tablename;
|
||||
char *modecmd;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
"bind-key", "bind",
|
||||
"[-r] key command [arguments]",
|
||||
0,
|
||||
"[-cnr] [-t key-table] key command [arguments]",
|
||||
0, 0,
|
||||
NULL,
|
||||
cmd_bind_key_parse,
|
||||
cmd_bind_key_exec,
|
||||
cmd_bind_key_send,
|
||||
cmd_bind_key_recv,
|
||||
cmd_bind_key_free,
|
||||
cmd_bind_key_print
|
||||
};
|
||||
@@ -54,17 +58,29 @@ int
|
||||
cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_bind_key_data *data;
|
||||
int opt;
|
||||
int opt, no_prefix = 0;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->can_repeat = 0;
|
||||
data->cmdlist = NULL;
|
||||
data->command_key = 0;
|
||||
data->tablename = NULL;
|
||||
data->modecmd = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "r")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "cnrt:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
data->command_key = 1;
|
||||
break;
|
||||
case 'n':
|
||||
no_prefix = 1;
|
||||
break;
|
||||
case 'r':
|
||||
data->can_repeat = 1;
|
||||
break;
|
||||
case 't':
|
||||
data->tablename = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
@@ -78,11 +94,19 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
xasprintf(cause, "unknown key: %s", argv[0]);
|
||||
goto error;
|
||||
}
|
||||
if (!no_prefix)
|
||||
data->key |= KEYC_PREFIX;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||
goto error;
|
||||
if (data->tablename != NULL) {
|
||||
if (argc != 1)
|
||||
goto usage;
|
||||
data->modecmd = xstrdup(argv[0]);
|
||||
} else {
|
||||
if ((data->cmdlist = cmd_list_parse(argc, argv, cause)) == NULL)
|
||||
goto error;
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -101,6 +125,8 @@ cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
if (data->tablename != NULL)
|
||||
return (cmd_bind_key_table(self, ctx));
|
||||
|
||||
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
|
||||
data->cmdlist = NULL; /* avoid free */
|
||||
@@ -108,23 +134,37 @@ cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_bind_key_send(struct cmd *self, struct buffer *b)
|
||||
int
|
||||
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_bind_key_data *data = self->data;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
enum mode_key_cmd cmd;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_list_send(data->cmdlist, b);
|
||||
}
|
||||
if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", data->tablename);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_bind_key_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_bind_key_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->cmdlist = cmd_list_recv(b);
|
||||
cmd = mode_key_fromstring(mtab->cmdstr, data->modecmd);
|
||||
if (cmd == MODEKEY_NONE) {
|
||||
ctx->error(ctx, "unknown command: %s", data->modecmd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
mtmp.key = data->key & ~KEYC_PREFIX;
|
||||
mtmp.mode = data->command_key ? 1 : 0;
|
||||
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||
mbind->cmd = cmd;
|
||||
return (0);
|
||||
}
|
||||
mbind = xmalloc(sizeof *mbind);
|
||||
mbind->key = mtmp.key;
|
||||
mbind->mode = mtmp.mode;
|
||||
mbind->cmd = cmd;
|
||||
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -134,6 +174,10 @@ cmd_bind_key_free(struct cmd *self)
|
||||
|
||||
if (data->cmdlist != NULL)
|
||||
cmd_list_free(data->cmdlist);
|
||||
if (data->tablename != NULL)
|
||||
xfree(data->tablename);
|
||||
if (data->modecmd != NULL)
|
||||
xfree(data->modecmd);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-break-pane.c,v 1.3 2009-05-18 21:01:38 nicm Exp $ */
|
||||
/* $Id: cmd-break-pane.c,v 1.9 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -30,41 +30,31 @@ int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_break_pane_entry = {
|
||||
"break-pane", "breakp",
|
||||
CMD_PANE_WINDOW_USAGE " [-d]",
|
||||
CMD_DFLAG,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
CMD_TARGET_PANE_USAGE " [-d]",
|
||||
0, CMD_CHFLAG('d'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_break_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
struct window *w;
|
||||
char *cause;
|
||||
int base_idx;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
ctx->error(ctx, "can't break pane: %d", data->pane);
|
||||
ctx->error(ctx, "can't break with only one pane");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -74,19 +64,21 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (wl->window->active == NULL)
|
||||
wl->window->active = TAILQ_NEXT(wp, entry);
|
||||
}
|
||||
layout_refresh(wl->window, 0);
|
||||
layout_close_pane(wp);
|
||||
|
||||
w = wp->window = window_create1(s->sx, s->sy);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
w->name = default_window_name(w);
|
||||
layout_init(w);
|
||||
|
||||
wl = session_attach(s, w, -1, &cause); /* can't fail */
|
||||
if (!(data->flags & CMD_DFLAG))
|
||||
base_idx = options_get_number(&s->options, "base-index");
|
||||
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||
if (!(data->chflags & CMD_CHFLAG('d')))
|
||||
session_select(s, wl->idx);
|
||||
layout_refresh(w, 0);
|
||||
|
||||
server_redraw_session(s);
|
||||
server_status_session_group(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
152
cmd-choose-client.c
Normal file
152
cmd-choose-client.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/* $Id: cmd-choose-client.c,v 1.3 2009-09-07 23:59:19 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter choice mode to choose a client.
|
||||
*/
|
||||
|
||||
int cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_client_callback(void *, int);
|
||||
void cmd_choose_client_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_choose_client_entry = {
|
||||
"choose-client", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_choose_client_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_choose_client_data {
|
||||
struct client *client;
|
||||
char *template;
|
||||
};
|
||||
|
||||
int
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_choose_client_data *cdata;
|
||||
struct winlink *wl;
|
||||
struct client *c;
|
||||
u_int i, idx, cur;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
return (0);
|
||||
|
||||
cur = idx = 0;
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
continue;
|
||||
if (c == ctx->curclient)
|
||||
cur = idx;
|
||||
idx++;
|
||||
|
||||
window_choose_add(wl->window->active, i,
|
||||
"%s: %s [%ux%u %s]%s", c->tty.path,
|
||||
c->session->name, c->tty.sx, c->tty.sy,
|
||||
c->tty.termname, c->tty.flags & TTY_UTF8 ? " (utf8)" : "");
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
if (data->arg != NULL)
|
||||
cdata->template = xstrdup(data->arg);
|
||||
else
|
||||
cdata->template = xstrdup("detach-client -t '%%'");
|
||||
cdata->client = ctx->curclient;
|
||||
cdata->client->references++;
|
||||
|
||||
window_choose_ready(wl->window->active,
|
||||
cur, cmd_choose_client_callback, cmd_choose_client_free, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_client_callback(void *data, int idx)
|
||||
{
|
||||
struct cmd_choose_client_data *cdata = data;
|
||||
struct client *c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *template, *cause;
|
||||
|
||||
if (idx == -1)
|
||||
return;
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
if ((u_int) idx > ARRAY_LENGTH(&clients) - 1)
|
||||
return;
|
||||
c = ARRAY_ITEM(&clients, idx);
|
||||
if (c == NULL || c->session == NULL)
|
||||
return;
|
||||
template = cmd_template_replace(cdata->template, c->tty.path, 1);
|
||||
|
||||
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
xfree(template);
|
||||
return;
|
||||
}
|
||||
xfree(template);
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = cdata->client;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
ctx.print = key_bindings_print;
|
||||
ctx.info = key_bindings_info;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_client_free(void *data)
|
||||
{
|
||||
struct cmd_choose_client_data *cdata = data;
|
||||
|
||||
cdata->client->references--;
|
||||
xfree(cdata->template);
|
||||
xfree(cdata);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-choose-session.c,v 1.7 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-choose-session.c,v 1.14 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -27,22 +29,22 @@
|
||||
int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_session_callback(void *, int);
|
||||
void cmd_choose_session_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_choose_session_entry = {
|
||||
"choose-session", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_choose_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_choose_session_data {
|
||||
u_int client;
|
||||
struct client *client;
|
||||
char *template;
|
||||
};
|
||||
|
||||
int
|
||||
@@ -52,7 +54,9 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_choose_session_data *cdata;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct session_group *sg;
|
||||
u_int i, idx, cur;
|
||||
char tmp[64];
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
@@ -74,17 +78,30 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cur = idx;
|
||||
idx++;
|
||||
|
||||
sg = session_group_find(s);
|
||||
if (sg == NULL)
|
||||
*tmp = '\0';
|
||||
else {
|
||||
idx = session_group_index(sg);
|
||||
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||
}
|
||||
|
||||
window_choose_add(wl->window->active, i,
|
||||
"%s: %u windows [%ux%u]%s", s->name,
|
||||
"%s: %u windows [%ux%u]%s%s", s->name,
|
||||
winlink_count(&s->windows), s->sx, s->sy,
|
||||
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->client = server_client_index(ctx->curclient);
|
||||
if (data->arg != NULL)
|
||||
cdata->template = xstrdup(data->arg);
|
||||
else
|
||||
cdata->template = xstrdup("switch-client -t '%%'");
|
||||
cdata->client = ctx->curclient;
|
||||
cdata->client->references++;
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_session_callback, cdata);
|
||||
window_choose_ready(wl->window->active,
|
||||
cur, cmd_choose_session_callback, cmd_choose_session_free, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -93,15 +110,53 @@ void
|
||||
cmd_choose_session_callback(void *data, int idx)
|
||||
{
|
||||
struct cmd_choose_session_data *cdata = data;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *template, *cause;
|
||||
|
||||
if (idx != -1 && cdata->client <= ARRAY_LENGTH(&clients) - 1) {
|
||||
c = ARRAY_ITEM(&clients, cdata->client);
|
||||
if (c != NULL && (u_int) idx <= ARRAY_LENGTH(&sessions) - 1) {
|
||||
c->session = ARRAY_ITEM(&sessions, idx);
|
||||
recalculate_sizes();
|
||||
server_redraw_client(c);
|
||||
if (idx == -1)
|
||||
return;
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
if ((u_int) idx > ARRAY_LENGTH(&sessions) - 1)
|
||||
return;
|
||||
s = ARRAY_ITEM(&sessions, idx);
|
||||
if (s == NULL)
|
||||
return;
|
||||
template = cmd_template_replace(cdata->template, s->name, 1);
|
||||
|
||||
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(cdata->client, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
xfree(template);
|
||||
return;
|
||||
}
|
||||
xfree(template);
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = cdata->client;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
ctx.print = key_bindings_print;
|
||||
ctx.info = key_bindings_info;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_session_free(void *data)
|
||||
{
|
||||
struct cmd_choose_session_data *cdata = data;
|
||||
|
||||
cdata->client->references--;
|
||||
xfree(cdata->template);
|
||||
xfree(cdata);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-choose-window.c,v 1.9 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-choose-window.c,v 1.18 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -27,22 +29,23 @@
|
||||
int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_window_callback(void *, int);
|
||||
void cmd_choose_window_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_choose_window_entry = {
|
||||
"choose-window", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
CMD_TARGET_WINDOW_USAGE " [template]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_choose_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_choose_window_data {
|
||||
u_int session;
|
||||
struct client *client;
|
||||
struct session *session;
|
||||
char *template;
|
||||
};
|
||||
|
||||
int
|
||||
@@ -54,6 +57,8 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct winlink *wl, *wm;
|
||||
struct window *w;
|
||||
u_int idx, cur;
|
||||
char flag, *title;
|
||||
const char *left, *right;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
@@ -75,17 +80,44 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cur = idx;
|
||||
idx++;
|
||||
|
||||
flag = ' ';
|
||||
if (session_alert_has(s, wm, WINDOW_ACTIVITY))
|
||||
flag = '#';
|
||||
else if (session_alert_has(s, wm, WINDOW_BELL))
|
||||
flag = '!';
|
||||
else if (session_alert_has(s, wm, WINDOW_CONTENT))
|
||||
flag = '+';
|
||||
else if (wm == s->curw)
|
||||
flag = '*';
|
||||
else if (wm == TAILQ_FIRST(&s->lastw))
|
||||
flag = '-';
|
||||
|
||||
title = w->active->screen->title;
|
||||
if (wm == wl)
|
||||
title = w->active->base.title;
|
||||
left = " \"";
|
||||
right = "\"";
|
||||
if (*title == '\0')
|
||||
left = right = "";
|
||||
|
||||
window_choose_add(wl->window->active,
|
||||
wm->idx, "%3d: %s [%ux%u %s] (%u panes)", wm->idx, w->name,
|
||||
w->sx, w->sy, layout_name(w), window_count_panes(w));
|
||||
wm->idx, "%3d: %s%c [%ux%u] (%u panes)%s%s%s",
|
||||
wm->idx, w->name, flag, w->sx, w->sy, window_count_panes(w),
|
||||
left, title, right);
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
if (session_index(s, &cdata->session) != 0)
|
||||
fatalx("session not found");
|
||||
if (data->arg != NULL)
|
||||
cdata->template = xstrdup(data->arg);
|
||||
else
|
||||
cdata->template = xstrdup("select-window -t '%%'");
|
||||
cdata->session = s;
|
||||
cdata->session->references++;
|
||||
cdata->client = ctx->curclient;
|
||||
cdata->client->references++;
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_window_callback, cdata);
|
||||
window_choose_ready(wl->window->active,
|
||||
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -94,13 +126,54 @@ void
|
||||
cmd_choose_window_callback(void *data, int idx)
|
||||
{
|
||||
struct cmd_choose_window_data *cdata = data;
|
||||
struct session *s;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *target, *template, *cause;
|
||||
|
||||
if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
|
||||
s = ARRAY_ITEM(&sessions, cdata->session);
|
||||
if (s != NULL && session_select(s, idx) == 0)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
if (idx == -1)
|
||||
return;
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
if (cdata->session->flags & SESSION_DEAD)
|
||||
return;
|
||||
if (cdata->client->session != cdata->session)
|
||||
return;
|
||||
|
||||
xasprintf(&target, "%s:%d", cdata->session->name, idx);
|
||||
template = cmd_template_replace(cdata->template, target, 1);
|
||||
xfree(target);
|
||||
|
||||
if (cmd_string_parse(template, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(cdata->client, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
xfree(template);
|
||||
return;
|
||||
}
|
||||
xfree(template);
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = cdata->client;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
ctx.print = key_bindings_print;
|
||||
ctx.info = key_bindings_info;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_window_free(void *data)
|
||||
{
|
||||
struct cmd_choose_window_data *cdata = data;
|
||||
|
||||
cdata->session->references--;
|
||||
cdata->client->references--;
|
||||
xfree(cdata->template);
|
||||
xfree(cdata);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-clear-history.c,v 1.3 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-clear-history.c,v 1.7 2009-07-30 21:04:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,36 +28,24 @@ int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_clear_history_entry = {
|
||||
"clear-history", "clearhist",
|
||||
CMD_PANE_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_clear_history_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
gd = wp->base.grid;
|
||||
|
||||
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-clock-mode.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-clock-mode.c,v 1.6 2009-08-20 11:37:46 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,13 +28,11 @@ int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_clock_mode_entry = {
|
||||
"clock-mode", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_clock_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -43,12 +41,12 @@ int
|
||||
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||
return (-1);
|
||||
|
||||
window_pane_set_mode(wl->window->active, &window_clock_mode);
|
||||
window_pane_set_mode(wp, &window_clock_mode);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-command-prompt.c,v 1.16 2009-02-16 18:58:14 nicm Exp $ */
|
||||
/* $Id: cmd-command-prompt.c,v 1.26 2009-09-22 14:06:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -27,57 +27,111 @@
|
||||
* Prompt for command in client.
|
||||
*/
|
||||
|
||||
void cmd_command_prompt_init(struct cmd *, int);
|
||||
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_command_prompt_init(struct cmd *, int);
|
||||
int cmd_command_prompt_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_command_prompt_free(struct cmd *);
|
||||
size_t cmd_command_prompt_print(struct cmd *, char *, size_t);
|
||||
|
||||
int cmd_command_prompt_callback(void *, const char *);
|
||||
int cmd_command_prompt_callback(void *, const char *);
|
||||
void cmd_command_prompt_cfree(void *);
|
||||
|
||||
const struct cmd_entry cmd_command_prompt_entry = {
|
||||
"command-prompt", NULL,
|
||||
CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
CMD_ARG01,
|
||||
CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
|
||||
0, 0,
|
||||
cmd_command_prompt_init,
|
||||
cmd_target_parse,
|
||||
cmd_command_prompt_parse,
|
||||
cmd_command_prompt_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
cmd_command_prompt_free,
|
||||
cmd_command_prompt_print
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_data {
|
||||
char *prompts;
|
||||
char *target;
|
||||
char *template;
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
struct client *c;
|
||||
char *next_prompt;
|
||||
char *prompts;
|
||||
char *template;
|
||||
int idx;
|
||||
};
|
||||
|
||||
void
|
||||
cmd_command_prompt_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
struct cmd_command_prompt_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->prompts = NULL;
|
||||
data->target = NULL;
|
||||
data->template = NULL;
|
||||
|
||||
switch (key) {
|
||||
case ',':
|
||||
data->arg = xstrdup("rename-window '%%'");
|
||||
data->template = xstrdup("rename-window '%%'");
|
||||
break;
|
||||
case '.':
|
||||
data->arg = xstrdup("move-window -t '%%'");
|
||||
data->template = xstrdup("move-window -t '%%'");
|
||||
break;
|
||||
case 'f':
|
||||
data->arg = xstrdup("find-window '%%'");
|
||||
data->template = xstrdup("find-window '%%'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_command_prompt_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_command_prompt_data *data;
|
||||
int opt;
|
||||
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "p:t:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
if (data->prompts == NULL)
|
||||
data->prompts = xstrdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0 && argc != 1)
|
||||
goto usage;
|
||||
|
||||
if (argc == 1)
|
||||
data->template = xstrdup(argv[0]);
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_command_prompt_data *cdata;
|
||||
struct cmd_command_prompt_data *data = self->data;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
struct client *c;
|
||||
char *hdr, *ptr;
|
||||
char *prompt, *ptr;
|
||||
size_t n;
|
||||
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
@@ -87,80 +141,102 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->c = c;
|
||||
if (data->arg != NULL) {
|
||||
cdata->template = xstrdup(data->arg);
|
||||
if ((ptr = strchr(data->arg, ' ')) == NULL)
|
||||
ptr = strchr(data->arg, '\0');
|
||||
xasprintf(&hdr, "(%.*s) ", (int) (ptr - data->arg), data->arg);
|
||||
} else {
|
||||
cdata->template = NULL;
|
||||
hdr = xstrdup(":");
|
||||
}
|
||||
status_prompt_set(c, hdr, cmd_command_prompt_callback, cdata, 0);
|
||||
xfree(hdr);
|
||||
cdata->idx = 1;
|
||||
cdata->next_prompt = NULL;
|
||||
cdata->prompts = NULL;
|
||||
cdata->template = NULL;
|
||||
|
||||
if (data->template != NULL)
|
||||
cdata->template = xstrdup(data->template);
|
||||
else
|
||||
cdata->template = xstrdup("%1");
|
||||
if (data->prompts != NULL)
|
||||
cdata->prompts = xstrdup(data->prompts);
|
||||
else if (data->template != NULL) {
|
||||
n = strcspn(data->template, " ,");
|
||||
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, data->template);
|
||||
} else
|
||||
cdata->prompts = xstrdup(":");
|
||||
|
||||
cdata->next_prompt = cdata->prompts;
|
||||
ptr = strsep(&cdata->next_prompt, ",");
|
||||
if (data->prompts == NULL)
|
||||
prompt = xstrdup(ptr);
|
||||
else
|
||||
xasprintf(&prompt, "%s ", ptr);
|
||||
status_prompt_set(c, prompt, cmd_command_prompt_callback,
|
||||
cmd_command_prompt_cfree, cdata, 0);
|
||||
xfree(prompt);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_command_prompt_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_command_prompt_data *data = self->data;
|
||||
|
||||
if (data->prompts != NULL)
|
||||
xfree(data->prompts);
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->template != NULL)
|
||||
xfree(data->template);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_command_prompt_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_command_prompt_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
if (off < len && data->prompts != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -p ", data->prompts);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->template != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->template);
|
||||
return (off);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_command_prompt_callback(void *data, const char *s)
|
||||
{
|
||||
struct cmd_command_prompt_data *cdata = data;
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause, *ptr, *buf, ch;
|
||||
size_t len, slen;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause, *newtempl, *prompt, *ptr;
|
||||
|
||||
if (s == NULL) {
|
||||
xfree(cdata);
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
|
||||
newtempl = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||
xfree(cdata->template);
|
||||
cdata->template = newtempl;
|
||||
|
||||
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||
xasprintf(&prompt, "%s ", ptr);
|
||||
status_prompt_update(c, prompt);
|
||||
xfree(prompt);
|
||||
cdata->idx++;
|
||||
return (1);
|
||||
}
|
||||
slen = strlen(s);
|
||||
|
||||
len = 0;
|
||||
buf = NULL;
|
||||
if (cdata->template != NULL) {
|
||||
ptr = cdata->template;
|
||||
while (*ptr != '\0') {
|
||||
switch (ch = *ptr++) {
|
||||
case '%':
|
||||
if (*ptr != '%')
|
||||
break;
|
||||
ptr++;
|
||||
|
||||
buf = xrealloc(buf, 1, len + slen + 1);
|
||||
memcpy(buf + len, s, slen);
|
||||
len += slen;
|
||||
break;
|
||||
default:
|
||||
buf = xrealloc(buf, 1, len + 2);
|
||||
buf[len++] = ch;
|
||||
break;
|
||||
}
|
||||
if (cmd_string_parse(newtempl, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
xfree(cdata->template);
|
||||
|
||||
buf[len] = '\0';
|
||||
s = buf;
|
||||
}
|
||||
xfree(cdata);
|
||||
|
||||
if (cmd_string_parse(s, &cmdlist, &cause) != 0) {
|
||||
if (cause == NULL)
|
||||
return (0);
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, cause);
|
||||
xfree(cause);
|
||||
cmdlist = NULL;
|
||||
}
|
||||
if (buf != NULL)
|
||||
xfree(buf);
|
||||
if (cmdlist == NULL)
|
||||
return (0);
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = c->session;
|
||||
ctx.curclient = c;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
@@ -172,7 +248,19 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
if (c->prompt_callback != (void *) &cmd_command_prompt_callback)
|
||||
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_command_prompt_cfree(void *data)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
|
||||
if (cdata->prompts != NULL)
|
||||
xfree(cdata->prompts);
|
||||
if (cdata->template != NULL)
|
||||
xfree(cdata->template);
|
||||
xfree(cdata);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-confirm-before.c,v 1.4 2009-04-28 18:29:44 tcunha Exp $ */
|
||||
/* $Id: cmd-confirm-before.c,v 1.11 2009-08-24 16:24:18 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -29,25 +29,24 @@ int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_confirm_before_init(struct cmd *, int);
|
||||
|
||||
int cmd_confirm_before_callback(void *, const char *);
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
struct client *c;
|
||||
char *cmd;
|
||||
};
|
||||
void cmd_confirm_before_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_confirm_before_entry = {
|
||||
"confirm-before", "confirm",
|
||||
CMD_TARGET_CLIENT_USAGE " command",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_confirm_before_init,
|
||||
cmd_target_parse,
|
||||
cmd_confirm_before_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
struct client *c;
|
||||
char *cmd;
|
||||
};
|
||||
|
||||
void
|
||||
cmd_confirm_before_init(struct cmd *self, int key)
|
||||
{
|
||||
@@ -67,7 +66,7 @@ cmd_confirm_before_init(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
int
|
||||
cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
@@ -91,8 +90,9 @@ cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(data->arg);
|
||||
cdata->c = c;
|
||||
status_prompt_set(
|
||||
cdata->c, buf, cmd_confirm_before_callback, cdata, PROMPT_SINGLE);
|
||||
status_prompt_set(cdata->c, buf,
|
||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||
PROMPT_SINGLE);
|
||||
|
||||
xfree(buf);
|
||||
return (1);
|
||||
@@ -107,20 +107,21 @@ cmd_confirm_before_callback(void *data, const char *s)
|
||||
struct cmd_ctx ctx;
|
||||
char *cause;
|
||||
|
||||
if (s == NULL || tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
goto out;
|
||||
if (s == NULL || *s == '\0')
|
||||
return (0);
|
||||
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
return (0);
|
||||
|
||||
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
goto out;
|
||||
return (0);
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cursession = c->session;
|
||||
ctx.curclient = c;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
@@ -132,10 +133,15 @@ cmd_confirm_before_callback(void *data, const char *s)
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
out:
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
|
||||
if (cdata->cmd != NULL)
|
||||
xfree(cdata->cmd);
|
||||
xfree(cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-copy-buffer.c,v 1.1 2009-02-03 17:21:19 tcunha Exp $ */
|
||||
/* $Id: cmd-copy-buffer.c,v 1.5 2009-09-22 14:06:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -16,7 +16,10 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,8 +29,6 @@
|
||||
|
||||
int cmd_copy_buffer_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_copy_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_copy_buffer_send(struct cmd *, struct buffer *);
|
||||
void cmd_copy_buffer_recv(struct cmd *, struct buffer *);
|
||||
void cmd_copy_buffer_free(struct cmd *);
|
||||
void cmd_copy_buffer_init(struct cmd *, int);
|
||||
size_t cmd_copy_buffer_print(struct cmd *, char *, size_t);
|
||||
@@ -42,12 +43,10 @@ struct cmd_copy_buffer_data {
|
||||
const struct cmd_entry cmd_copy_buffer_entry = {
|
||||
"copy-buffer", "copyb",
|
||||
"[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]",
|
||||
0,
|
||||
0, 0,
|
||||
cmd_copy_buffer_init,
|
||||
cmd_copy_buffer_parse,
|
||||
cmd_copy_buffer_exec,
|
||||
cmd_copy_buffer_send,
|
||||
cmd_copy_buffer_recv,
|
||||
cmd_copy_buffer_free,
|
||||
cmd_copy_buffer_print
|
||||
};
|
||||
@@ -71,7 +70,7 @@ cmd_copy_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
const char *errstr;
|
||||
int n, opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "a:b:s:t:")) != -1) {
|
||||
@@ -126,61 +125,44 @@ cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data = self->data;
|
||||
struct paste_buffer *pb;
|
||||
struct paste_stack *dst_ps, *src_ps;
|
||||
u_char *pdata;
|
||||
struct session *dst_session, *src_session;
|
||||
u_int limit;
|
||||
|
||||
if ((dst_session = cmd_find_session(ctx, data->dst_session)) == NULL ||
|
||||
(src_session = cmd_find_session(ctx, data->src_session)) == NULL)
|
||||
return (-1);
|
||||
dst_ps = &dst_session->buffers;
|
||||
src_ps = &src_session->buffers;
|
||||
|
||||
if (data->src_idx == -1) {
|
||||
if ((pb = paste_get_top(&src_session->buffers)) == NULL) {
|
||||
if ((pb = paste_get_top(src_ps)) == NULL) {
|
||||
ctx->error(ctx, "no buffers");
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if ((pb = paste_get_index(&src_session->buffers,
|
||||
data->src_idx)) == NULL) {
|
||||
if ((pb = paste_get_index(src_ps, data->src_idx)) == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", data->src_idx);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
limit = options_get_number(&dst_session->options, "buffer-limit");
|
||||
if (data->dst_idx == -1) {
|
||||
paste_add(&dst_session->buffers, xstrdup(pb->data), limit);
|
||||
return (0);
|
||||
}
|
||||
if (paste_replace(&dst_session->buffers, data->dst_idx,
|
||||
xstrdup(pb->data)) != 0) {
|
||||
|
||||
pdata = xmalloc(pb->size);
|
||||
memcpy(pdata, pb->data, pb->size);
|
||||
|
||||
if (data->dst_idx == -1)
|
||||
paste_add(dst_ps, pdata, pb->size, limit);
|
||||
else if (paste_replace(dst_ps, data->dst_idx, pdata, pb->size) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", data->dst_idx);
|
||||
xfree(pdata);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_copy_buffer_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->dst_session);
|
||||
cmd_send_string(b, data->src_session);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_copy_buffer_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_copy_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->dst_session = cmd_recv_string(b);
|
||||
data->src_session = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_copy_buffer_free(struct cmd *self)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-copy-mode.c,v 1.19 2009-07-01 23:06:32 nicm Exp $ */
|
||||
/* $Id: cmd-copy-mode.c,v 1.24 2009-10-06 14:14:06 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -24,34 +24,46 @@
|
||||
* Enter copy mode.
|
||||
*/
|
||||
|
||||
void cmd_copy_mode_init(struct cmd *, int);
|
||||
int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_copy_mode_entry = {
|
||||
"copy-mode", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_UFLAG,
|
||||
cmd_target_init,
|
||||
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||
0, CMD_CHFLAG('u'),
|
||||
cmd_copy_mode_init,
|
||||
cmd_target_parse,
|
||||
cmd_copy_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
NULL
|
||||
};
|
||||
|
||||
void
|
||||
cmd_copy_mode_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
switch (key) {
|
||||
case KEYC_PPAGE:
|
||||
data->chflags |= CMD_CHFLAG('u');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||
return (-1);
|
||||
wp = wl->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
if (wp->mode == &window_copy_mode && data->flags & CMD_UFLAG)
|
||||
if (wp->mode == &window_copy_mode && data->chflags & CMD_CHFLAG('u'))
|
||||
window_copy_pageup(wp);
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-delete-buffer.c,v 1.5 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-delete-buffer.c,v 1.7 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
"delete-buffer", "deleteb",
|
||||
CMD_BUFFER_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_delete_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-detach-client.c,v 1.7 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-detach-client.c,v 1.9 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_detach_client_entry = {
|
||||
"detach-client", "detach",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_detach_client_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
63
cmd-display-message.c
Normal file
63
cmd-display-message.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $Id: cmd-display-message.c,v 1.3 2009-10-11 23:55:26 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Displays a message in the status line.
|
||||
*/
|
||||
|
||||
int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_display_message_entry = {
|
||||
"display-message", "display",
|
||||
CMD_TARGET_CLIENT_USAGE " [message]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_display_message_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
const char *template;
|
||||
char *msg;
|
||||
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (data->arg == NULL)
|
||||
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
|
||||
else
|
||||
template = data->arg;
|
||||
|
||||
msg = status_replace(c, template, time(NULL));
|
||||
status_message_set(c, "%s", msg);
|
||||
xfree(msg);
|
||||
|
||||
return (0);
|
||||
}
|
||||
52
cmd-display-panes.c
Normal file
52
cmd-display-panes.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $Id: cmd-display-panes.c,v 1.1 2009-08-31 22:30:15 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Display panes on a client.
|
||||
*/
|
||||
|
||||
int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
"display-panes", "displayp",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_display_panes_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
server_set_identify(c);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-down-pane.c,v 1.7 2009-04-01 21:10:08 nicm Exp $ */
|
||||
/* $Id: cmd-down-pane.c,v 1.12 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_down_pane_entry = {
|
||||
"down-pane", "downp",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_down_pane_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -54,8 +52,8 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
w->active = TAILQ_NEXT(w->active, entry);
|
||||
if (w->active == NULL)
|
||||
w->active = TAILQ_FIRST(&w->panes);
|
||||
layout_refresh(w, 1);
|
||||
} while (w->active->flags & PANE_HIDDEN);
|
||||
} while (!window_pane_visible(w->active));
|
||||
server_status_window(wl->window);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-find-window.c,v 1.10 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-find-window.c,v 1.13 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -34,12 +34,10 @@ void cmd_find_window_callback(void *, int);
|
||||
const struct cmd_entry cmd_find_window_entry = {
|
||||
"find-window", "findw",
|
||||
CMD_TARGET_WINDOW_USAGE " match-string",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_find_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -140,7 +138,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
fatalx("session not found");
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, 0, cmd_find_window_callback, cdata);
|
||||
wl->window->active, 0, cmd_find_window_callback, xfree, cdata);
|
||||
|
||||
out:
|
||||
ARRAY_FREE(&list_idx);
|
||||
@@ -161,5 +159,4 @@ cmd_find_window_callback(void *data, int idx)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
|
||||
504
cmd-generic.c
504
cmd-generic.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-generic.c,v 1.28 2009-05-21 19:47:57 nicm Exp $ */
|
||||
/* $Id: cmd-generic.c,v 1.34 2009-08-26 22:13:52 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -23,13 +23,10 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#define CMD_FLAGS "adDgkuU"
|
||||
#define CMD_FLAGMASK (CMD_AFLAG|CMD_DFLAG|CMD_BIGDFLAG|CMD_GFLAG|CMD_KFLAG| \
|
||||
CMD_UFLAG|CMD_BIGUFLAG)
|
||||
|
||||
int cmd_do_flags(int, int, int *);
|
||||
size_t cmd_print_flags(char *, size_t, size_t, int);
|
||||
int cmd_fill_argument(int, char **, int, char **);
|
||||
int cmd_getopt(int, char **, const char *, uint64_t);
|
||||
int cmd_flags(int, uint64_t, uint64_t *);
|
||||
size_t cmd_print_flags(char *, size_t, size_t, uint64_t);
|
||||
int cmd_fill_argument(int, char **, char **, int, char **);
|
||||
|
||||
size_t
|
||||
cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
|
||||
@@ -39,85 +36,78 @@ cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
|
||||
return (xsnprintf(buf, len, "%s%s", prefix, arg));
|
||||
}
|
||||
|
||||
/* Prepend flags from chflags onto flagstr and call getopt. */
|
||||
int
|
||||
cmd_do_flags(int opt, int iflags, int *oflags)
|
||||
cmd_getopt(int argc, char **argv, const char *flagstr, uint64_t chflags)
|
||||
{
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
if (iflags & CMD_AFLAG) {
|
||||
(*oflags) |= CMD_AFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'd':
|
||||
if (iflags & CMD_DFLAG) {
|
||||
(*oflags) |= CMD_DFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'D':
|
||||
if (iflags & CMD_BIGDFLAG) {
|
||||
(*oflags) |= CMD_BIGDFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'g':
|
||||
if (iflags & CMD_GFLAG) {
|
||||
(*oflags) |= CMD_GFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'k':
|
||||
if (iflags & CMD_KFLAG) {
|
||||
(*oflags) |= CMD_KFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'u':
|
||||
if (iflags & CMD_UFLAG) {
|
||||
(*oflags) |= CMD_UFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
case 'U':
|
||||
if (iflags & CMD_BIGUFLAG) {
|
||||
(*oflags) |= CMD_BIGUFLAG;
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
u_char ch;
|
||||
char buf[128];
|
||||
size_t len, off;
|
||||
|
||||
*buf = '\0';
|
||||
|
||||
len = sizeof buf;
|
||||
off = 0;
|
||||
|
||||
for (ch = 0; ch < 26; ch++) {
|
||||
if (chflags & CMD_CHFLAG('a' + ch))
|
||||
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||
if (chflags & CMD_CHFLAG('A' + ch))
|
||||
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
|
||||
}
|
||||
return (1);
|
||||
|
||||
strlcat(buf, flagstr, sizeof buf);
|
||||
|
||||
return (getopt(argc, argv, buf));
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_print_flags(char *buf, size_t len, size_t off, int flags)
|
||||
/*
|
||||
* If this option is expected (in ichflags), set it in ochflags, otherwise
|
||||
* return -1.
|
||||
*/
|
||||
int
|
||||
cmd_flags(int opt, uint64_t ichflags, uint64_t *ochflags)
|
||||
{
|
||||
u_char ch;
|
||||
|
||||
for (ch = 0; ch < 26; ch++) {
|
||||
if (opt == 'a' + ch && ichflags & CMD_CHFLAG(opt)) {
|
||||
(*ochflags) |= CMD_CHFLAG(opt);
|
||||
return (0);
|
||||
}
|
||||
if (opt == 'A' + ch && ichflags & CMD_CHFLAG(opt)) {
|
||||
(*ochflags) |= CMD_CHFLAG(opt);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Print the flags supported in chflags. */
|
||||
size_t
|
||||
cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
|
||||
{
|
||||
u_char ch;
|
||||
size_t boff = off;
|
||||
|
||||
if ((flags & CMD_FLAGMASK) == 0)
|
||||
if (chflags == 0)
|
||||
return (0);
|
||||
off += xsnprintf(buf + off, len - off, " -");
|
||||
if (off < len && flags & CMD_AFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "a");
|
||||
if (off < len && flags & CMD_BIGDFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "D");
|
||||
if (off < len && flags & CMD_DFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "d");
|
||||
if (off < len && flags & CMD_GFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "g");
|
||||
if (off < len && flags & CMD_KFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "k");
|
||||
if (off < len && flags & CMD_UFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "u");
|
||||
if (off < len && flags & CMD_BIGUFLAG)
|
||||
off += xsnprintf(buf + off, len - off, "U");
|
||||
|
||||
for (ch = 0; ch < 26; ch++) {
|
||||
if (chflags & CMD_CHFLAG('a' + ch))
|
||||
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
|
||||
if (chflags & CMD_CHFLAG('A' + ch))
|
||||
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
|
||||
}
|
||||
return (off - boff);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_fill_argument(int flags, char **arg, int argc, char **argv)
|
||||
cmd_fill_argument(int flags, char **arg, char **arg2, int argc, char **argv)
|
||||
{
|
||||
*arg = NULL;
|
||||
*arg2 = NULL;
|
||||
|
||||
if (flags & CMD_ARG1) {
|
||||
if (argc != 1)
|
||||
@@ -134,6 +124,23 @@ cmd_fill_argument(int flags, char **arg, int argc, char **argv)
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (flags & CMD_ARG2) {
|
||||
if (argc != 2)
|
||||
return (-1);
|
||||
*arg = xstrdup(argv[0]);
|
||||
*arg2 = xstrdup(argv[1]);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (flags & CMD_ARG12) {
|
||||
if (argc != 1 && argc != 2)
|
||||
return (-1);
|
||||
*arg = xstrdup(argv[0]);
|
||||
if (argc == 2)
|
||||
*arg2 = xstrdup(argv[1]);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (argc != 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
@@ -145,28 +152,26 @@ cmd_target_init(struct cmd *self, unused int key)
|
||||
struct cmd_target_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->chflags = 0;
|
||||
data->target = NULL;
|
||||
data->arg = NULL;
|
||||
data->arg2 = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
const struct cmd_entry *entry = self->entry;
|
||||
int opt;
|
||||
|
||||
/* Don't use the entry version since it may be dependent on key. */
|
||||
cmd_target_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) {
|
||||
if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
@@ -179,7 +184,8 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (cmd_fill_argument(self->entry->flags, &data->arg, argc, argv) != 0)
|
||||
if (cmd_fill_argument(
|
||||
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
@@ -190,27 +196,6 @@ usage:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_target_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_target_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_target_free(struct cmd *self)
|
||||
{
|
||||
@@ -220,6 +205,8 @@ cmd_target_free(struct cmd *self)
|
||||
xfree(data->target);
|
||||
if (data->arg != NULL)
|
||||
xfree(data->arg);
|
||||
if (data->arg2 != NULL)
|
||||
xfree(data->arg2);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
@@ -232,11 +219,13 @@ cmd_target_print(struct cmd *self, char *buf, size_t len)
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
if (off < len && data->arg2 != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||
return (off);
|
||||
}
|
||||
|
||||
@@ -246,28 +235,26 @@ cmd_srcdst_init(struct cmd *self, unused int key)
|
||||
struct cmd_srcdst_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->chflags = 0;
|
||||
data->src = NULL;
|
||||
data->dst = NULL;
|
||||
data->arg = NULL;
|
||||
data->arg2 = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_srcdst_data *data;
|
||||
const struct cmd_entry *entry = self->entry;
|
||||
int opt;
|
||||
|
||||
cmd_srcdst_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "s:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
|
||||
if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 's':
|
||||
if (data->src == NULL)
|
||||
@@ -284,7 +271,8 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (cmd_fill_argument(self->entry->flags, &data->arg, argc, argv) != 0)
|
||||
if (cmd_fill_argument(
|
||||
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
@@ -295,29 +283,6 @@ usage:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_srcdst_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->src);
|
||||
cmd_send_string(b, data->dst);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_srcdst_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_srcdst_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->src = cmd_recv_string(b);
|
||||
data->dst = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_srcdst_free(struct cmd *self)
|
||||
{
|
||||
@@ -329,6 +294,8 @@ cmd_srcdst_free(struct cmd *self)
|
||||
xfree(data->dst);
|
||||
if (data->arg != NULL)
|
||||
xfree(data->arg);
|
||||
if (data->arg2 != NULL)
|
||||
xfree(data->arg2);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
@@ -341,13 +308,15 @@ cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||
if (off < len && data->src != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -s %s", data->src);
|
||||
if (off < len && data->dst != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " -t %s", data->dst);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
if (off < len && data->arg2 != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||
return (off);
|
||||
}
|
||||
|
||||
@@ -357,29 +326,27 @@ cmd_buffer_init(struct cmd *self, unused int key)
|
||||
struct cmd_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->chflags = 0;
|
||||
data->target = NULL;
|
||||
data->buffer = -1;
|
||||
data->arg = NULL;
|
||||
data->arg2 = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_buffer_data *data;
|
||||
const struct cmd_entry *entry = self->entry;
|
||||
int opt, n;
|
||||
const char *errstr;
|
||||
|
||||
cmd_buffer_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "b:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
|
||||
if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
if (data->buffer == -1) {
|
||||
@@ -402,7 +369,8 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (cmd_fill_argument(self->entry->flags, &data->arg, argc, argv) != 0)
|
||||
if (cmd_fill_argument(
|
||||
self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
@@ -414,27 +382,6 @@ error:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_buffer_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_buffer_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_buffer_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_buffer_free(struct cmd *self)
|
||||
{
|
||||
@@ -444,6 +391,8 @@ cmd_buffer_free(struct cmd *self)
|
||||
xfree(data->target);
|
||||
if (data->arg != NULL)
|
||||
xfree(data->arg);
|
||||
if (data->arg2 != NULL)
|
||||
xfree(data->arg2);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
@@ -456,239 +405,14 @@ cmd_buffer_print(struct cmd *self, char *buf, size_t len)
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
off += cmd_print_flags(buf, len, off, data->chflags);
|
||||
if (off < len && data->buffer != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->option = NULL;
|
||||
data->value = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_option_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
int opt;
|
||||
|
||||
/* Don't use the entry version since it may be dependent on key. */
|
||||
cmd_option_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc == 2) {
|
||||
data->option = xstrdup(argv[0]);
|
||||
data->value = xstrdup(argv[1]);
|
||||
} else if (argc == 1)
|
||||
data->option = xstrdup(argv[0]);
|
||||
else
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->option);
|
||||
cmd_send_string(b, data->value);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_option_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->option = cmd_recv_string(b);
|
||||
data->value = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_option_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->option != NULL)
|
||||
xfree(data->option);
|
||||
if (data->value != NULL)
|
||||
xfree(data->value);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_option_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->option != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->option);
|
||||
if (off < len && data->value != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " %s", data->value);
|
||||
return (off);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_init(struct cmd *self, unused int key)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flags = 0;
|
||||
data->target = NULL;
|
||||
data->arg = NULL;
|
||||
data->pane = -1;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
int opt, n;
|
||||
const char *errstr;
|
||||
|
||||
/* Don't use the entry version since it may be dependent on key. */
|
||||
cmd_pane_init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, CMD_FLAGS "p:t:")) != -1) {
|
||||
switch (cmd_do_flags(opt, self->entry->flags, &data->flags)) {
|
||||
case -1:
|
||||
goto usage;
|
||||
case 0:
|
||||
continue;
|
||||
}
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
if (data->pane == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "pane %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->pane = n;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (cmd_fill_argument(self->entry->flags, &data->arg, argc, argv) != 0)
|
||||
goto usage;
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
error:
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->arg);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->arg = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_pane_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
if (data->arg != NULL)
|
||||
xfree(data->arg);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_pane_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
off += cmd_print_flags(buf, len, off, data->flags);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->arg != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg);
|
||||
if (off < len && data->arg2 != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
|
||||
return (off);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-has-session.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-has-session.c,v 1.14 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_has_session_entry = {
|
||||
"has-session", "has",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_has_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
117
cmd-if-shell.c
Normal file
117
cmd-if-shell.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* $Id: cmd-if-shell.c,v 1.7 2009-11-02 21:38:26 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Executes a tmux command if a shell command returns true.
|
||||
*/
|
||||
|
||||
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_if_shell_callback(struct job *);
|
||||
void cmd_if_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_if_shell_entry = {
|
||||
"if-shell", "if",
|
||||
"shell-command command",
|
||||
CMD_ARG2, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_if_shell_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
char *cmd;
|
||||
struct cmd_ctx ctx;
|
||||
};
|
||||
|
||||
int
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_if_shell_data *cdata;
|
||||
struct job *job;
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(data->arg2);
|
||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
ctx->cmdclient->references++;
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references++;
|
||||
|
||||
job = job_add(NULL, 0, NULL,
|
||||
data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||
job_run(job);
|
||||
|
||||
return (1); /* don't let client exit */
|
||||
}
|
||||
|
||||
void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job->data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
struct cmd_list *cmdlist;
|
||||
char *cause;
|
||||
|
||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||
return;
|
||||
|
||||
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "%s", cause);
|
||||
xfree(cause);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd_list_exec(cmdlist, ctx) < 0) {
|
||||
cmd_list_free(cmdlist);
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_if_shell_free(void *data)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
|
||||
if (ctx->cmdclient != NULL) {
|
||||
ctx->cmdclient->references--;
|
||||
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
|
||||
}
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references--;
|
||||
|
||||
xfree(cdata->cmd);
|
||||
xfree(cdata);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-kill-pane.c,v 1.7 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-kill-pane.c,v 1.14 2009-10-25 10:41:03 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -30,43 +30,47 @@ int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_kill_pane_entry = {
|
||||
"kill-pane", "killp",
|
||||
CMD_PANE_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||
0, CMD_CHFLAG('a'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_kill_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
struct window_pane *loopwp, *nextwp, *wp;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
ctx->error(ctx, "can't kill pane: %d", data->pane);
|
||||
return (-1);
|
||||
/* Only one pane, kill the window. */
|
||||
server_kill_window(wl->window);
|
||||
recalculate_sizes();
|
||||
return (0);
|
||||
}
|
||||
|
||||
window_remove_pane(wl->window, wp);
|
||||
if (data->chflags & CMD_CHFLAG('a')) {
|
||||
loopwp = TAILQ_FIRST(&wl->window->panes);
|
||||
while (loopwp != NULL) {
|
||||
nextwp = TAILQ_NEXT(loopwp, entry);
|
||||
if (loopwp != wp) {
|
||||
layout_close_pane(loopwp);
|
||||
window_remove_pane(wl->window, loopwp);
|
||||
}
|
||||
loopwp = nextwp;
|
||||
}
|
||||
} else {
|
||||
layout_close_pane(wp);
|
||||
window_remove_pane(wl->window, wp);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
layout_refresh(wl->window, 0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-kill-server.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-kill-server.c,v 1.8 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,13 +32,11 @@ int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_kill_server_entry = {
|
||||
"kill-server", NULL,
|
||||
"",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_kill_server_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-kill-session.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-kill-session.c,v 1.15 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,12 +32,10 @@ int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_kill_session_entry = {
|
||||
"kill-session", NULL,
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_kill_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -55,7 +53,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c->session == s) {
|
||||
if (c != NULL && c->session == s) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-kill-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-kill-window.c,v 1.20 2009-09-20 22:15:32 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_kill_window_entry = {
|
||||
"kill-window", "killw",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_kill_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,25 +42,11 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int destroyed;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
destroyed = session_detach(s, wl);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
server_kill_window(wl->window);
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-last-window.c,v 1.16 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-last-window.c,v 1.18 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_last_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_last_window_entry = {
|
||||
"last-window", "last",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_last_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-link-window.c,v 1.28 2009-01-23 16:59:14 nicm Exp $ */
|
||||
/* $Id: cmd-link-window.c,v 1.35 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_link_window_entry = {
|
||||
"link-window", "linkw",
|
||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
CMD_DFLAG|CMD_KFLAG,
|
||||
0, CMD_CHFLAG('d')|CMD_CHFLAG('k'),
|
||||
cmd_srcdst_init,
|
||||
cmd_srcdst_parse,
|
||||
cmd_link_window_exec,
|
||||
cmd_srcdst_send,
|
||||
cmd_srcdst_recv,
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
@@ -45,64 +43,23 @@ int
|
||||
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct session *dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct session *src, *dst;
|
||||
struct winlink *wl;
|
||||
char *cause;
|
||||
int idx;
|
||||
int idx, kflag, dflag;
|
||||
|
||||
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||
return (-1);
|
||||
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||
return (-1);
|
||||
|
||||
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
if (dst == NULL)
|
||||
dst = ctx->cursession;
|
||||
if (dst == NULL)
|
||||
dst = cmd_current_session(ctx);
|
||||
if (dst == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wl_dst = NULL;
|
||||
if (idx != -1)
|
||||
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||
if (wl_dst != NULL) {
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (0);
|
||||
|
||||
if (data->flags & CMD_KFLAG) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session
|
||||
* if this makes it empty.
|
||||
*/
|
||||
session_alert_cancel(dst, wl_dst);
|
||||
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||
winlink_remove(&dst->windows, wl_dst);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl_dst == dst->curw) {
|
||||
data->flags &= ~CMD_DFLAG;
|
||||
dst->curw = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||
if (wl_dst == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
kflag = data->chflags & CMD_CHFLAG('k');
|
||||
dflag = data->chflags & CMD_CHFLAG('d');
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||
ctx->error(ctx, "can't link window: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_status_session(dst);
|
||||
else {
|
||||
session_select(dst, wl_dst->idx);
|
||||
server_redraw_session(dst);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-buffers.c,v 1.7 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-list-buffers.c,v 1.12 2009-09-07 23:48:54 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_list_buffers_entry = {
|
||||
"list-buffers", "lsb",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_list_buffers_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,44 +46,33 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
u_int idx;
|
||||
char *tmp;
|
||||
size_t size, in, out;
|
||||
char tmp[51 * 4 + 1];
|
||||
size_t size, len;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (s->sx > 35) { /* leave three for ... */
|
||||
size = s->sx - 32;
|
||||
tmp = xmalloc(size + 1);
|
||||
} else {
|
||||
size = 0;
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||
if (tmp != NULL) {
|
||||
in = out = 0;
|
||||
while (out < size && pb->data[in] != '\0') {
|
||||
if (pb->data[in] > 31 && pb->data[in] != 127)
|
||||
tmp[out++] = pb->data[in];
|
||||
in++;
|
||||
}
|
||||
tmp[out] = '\0';
|
||||
if (out == size) {
|
||||
tmp[out - 1] = '.';
|
||||
tmp[out - 2] = '.';
|
||||
tmp[out - 3] = '.';
|
||||
}
|
||||
size = pb->size;
|
||||
|
||||
ctx->print(ctx, "%d: %zu bytes: \"%s\"",
|
||||
idx - 1, strlen(pb->data), tmp);
|
||||
} else
|
||||
ctx->print(ctx, "%d: %zu bytes", idx, strlen(pb->data));
|
||||
/* Translate the first 50 characters. */
|
||||
len = size;
|
||||
if (len > 50)
|
||||
len = 50;
|
||||
strvisx(tmp, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||
|
||||
/*
|
||||
* If the first 50 characterswere encoded as a longer string,
|
||||
* or there is definitely more data, add "...".
|
||||
*/
|
||||
if (size > 50 || strlen(tmp) > 50) {
|
||||
tmp[50 - 3] = '\0';
|
||||
strlcat(tmp, "...", sizeof tmp);
|
||||
}
|
||||
|
||||
ctx->print(ctx, "%u: %zu bytes: \"%s\"", idx - 1, size, tmp);
|
||||
}
|
||||
|
||||
if (tmp != NULL)
|
||||
xfree(tmp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-clients.c,v 1.16 2009-06-25 16:34:50 nicm Exp $ */
|
||||
/* $Id: cmd-list-clients.c,v 1.18 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,13 +32,11 @@ int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_list_clients_entry = {
|
||||
"list-clients", "lsc",
|
||||
"",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_clients_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-commands.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-list-commands.c,v 1.5 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,13 +29,11 @@ int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_list_commands_entry = {
|
||||
"list-commands", "lscm",
|
||||
"",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_commands_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-keys.c,v 1.14 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-list-keys.c,v 1.20 2009-07-28 23:19:06 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -26,33 +28,97 @@
|
||||
|
||||
int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
int cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_keys_entry = {
|
||||
"list-keys", "lsk",
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
"[-t key-table]",
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_list_keys_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct key_binding *bd;
|
||||
const char *key;
|
||||
char tmp[BUFSIZ];
|
||||
char tmp[BUFSIZ], keytmp[64];
|
||||
int width, keywidth;
|
||||
|
||||
if (data->target != NULL)
|
||||
return (cmd_list_keys_table(self, ctx));
|
||||
|
||||
width = 0;
|
||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||
if (key == NULL)
|
||||
continue;
|
||||
|
||||
keywidth = strlen(key) + 1;
|
||||
if (!(bd->key & KEYC_PREFIX))
|
||||
keywidth += 2;
|
||||
if (keywidth > width)
|
||||
width = keywidth;
|
||||
}
|
||||
|
||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
||||
if ((key = key_string_lookup_key(bd->key)) == NULL)
|
||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||
if (key == NULL)
|
||||
continue;
|
||||
|
||||
*tmp = '\0';
|
||||
cmd_list_print(bd->cmdlist, tmp, sizeof tmp);
|
||||
ctx->print(ctx, "%11s: %s", key, tmp);
|
||||
if (!(bd->key & KEYC_PREFIX)) {
|
||||
xsnprintf(keytmp, sizeof keytmp, "[%s]", key);
|
||||
key = keytmp;
|
||||
}
|
||||
ctx->print(ctx, "%*s: %s", width, key, tmp);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind;
|
||||
const char *key, *cmdstr, *mode;
|
||||
int width, keywidth;
|
||||
|
||||
if ((mtab = mode_key_findtable(data->target)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", data->target);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
width = 0;
|
||||
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
key = key_string_lookup_key(mbind->key);
|
||||
if (key == NULL)
|
||||
continue;
|
||||
|
||||
keywidth = strlen(key) + 1;
|
||||
if (keywidth > width)
|
||||
width = keywidth;
|
||||
}
|
||||
|
||||
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
key = key_string_lookup_key(mbind->key);
|
||||
if (key == NULL)
|
||||
continue;
|
||||
|
||||
mode = "";
|
||||
if (mbind->mode != 0)
|
||||
mode = "(command mode) ";
|
||||
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||
if (cmdstr != NULL)
|
||||
ctx->print(ctx, "%*s: %s%s", width, key, mode, cmdstr);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $Id: cmd-scroll-mode.c,v 1.19 2009-07-01 23:06:32 nicm Exp $ */
|
||||
/* $Id: cmd-list-panes.c,v 1.2 2009-10-15 20:10:28 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,57 +18,57 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter scroll mode.
|
||||
* List panes on given window..
|
||||
*/
|
||||
|
||||
void cmd_scroll_mode_init(struct cmd *, int);
|
||||
int cmd_scroll_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
int cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_scroll_mode_entry = {
|
||||
"scroll-mode", NULL,
|
||||
const struct cmd_entry cmd_list_panes_entry = {
|
||||
"list-panes", "lsp",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_UFLAG,
|
||||
cmd_scroll_mode_init,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_scroll_mode_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_list_panes_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_scroll_mode_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
switch (key) {
|
||||
case KEYC_PPAGE:
|
||||
data->flags |= CMD_UFLAG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
struct grid_line *gl;
|
||||
u_int i, n;
|
||||
unsigned long long size;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
wp = wl->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_scroll_mode);
|
||||
if (wp->mode == &window_scroll_mode && data->flags & CMD_UFLAG)
|
||||
window_scroll_pageup(wp);
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
gd = wp->base.grid;
|
||||
|
||||
size = 0;
|
||||
for (i = 0; i < gd->hsize; i++) {
|
||||
gl = &gd->linedata[i];
|
||||
size += gl->cellsize * sizeof *gl->celldata;
|
||||
size += gl->utf8size * sizeof *gl->utf8data;
|
||||
}
|
||||
size += gd->hsize * sizeof *gd->linedata;
|
||||
|
||||
ctx->print(ctx, "%u: [%ux%u] [history %u/%u, %llu bytes]",
|
||||
n, wp->sx, wp->sy, gd->hsize, gd->hlimit, size);
|
||||
n++;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-sessions.c,v 1.19 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-list-sessions.c,v 1.23 2009-11-04 22:42:31 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,36 +31,43 @@ int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_list_sessions_entry = {
|
||||
"list-sessions", "ls", "",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_sessions_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
int
|
||||
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct session *s;
|
||||
char *tim;
|
||||
u_int i;
|
||||
time_t t;
|
||||
struct session *s;
|
||||
struct session_group *sg;
|
||||
char *tim, tmp[64];
|
||||
u_int i, idx;
|
||||
time_t t;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL)
|
||||
continue;
|
||||
|
||||
t = s->tv.tv_sec;
|
||||
sg = session_group_find(s);
|
||||
if (sg == NULL)
|
||||
*tmp = '\0';
|
||||
else {
|
||||
idx = session_group_index(sg);
|
||||
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
|
||||
}
|
||||
|
||||
t = s->creation_time.tv_sec;
|
||||
tim = ctime(&t);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s",
|
||||
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
|
||||
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
|
||||
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list-windows.c,v 1.35 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-list-windows.c,v 1.41 2009-10-12 00:08:12 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_list_windows_entry = {
|
||||
"list-windows", "lsw",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_list_windows_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -47,41 +45,13 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
u_int i;
|
||||
unsigned long long size;
|
||||
const char *name;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
ctx->print(ctx,
|
||||
"%3d: %s [%ux%u]", wl->idx, w->name, w->sx, w->sy);
|
||||
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
gd = wp->base.grid;
|
||||
|
||||
size = 0;
|
||||
for (i = 0; i < gd->hsize; i++) {
|
||||
size += gd->size[i] * sizeof **gd->data;
|
||||
size += gd->usize[i] * sizeof **gd->udata;
|
||||
}
|
||||
size += gd->hsize * (sizeof *gd->data);
|
||||
size += gd->hsize * (sizeof *gd->size);
|
||||
|
||||
if (wp->fd != -1)
|
||||
name = ttyname(wp->fd);
|
||||
else
|
||||
name = "unknown";
|
||||
ctx->print(ctx,
|
||||
" %s [%ux%u %s] [history %u/%u, %llu bytes]",
|
||||
name, wp->sx, wp->sy, layout_name(w), gd->hsize,
|
||||
gd->hlimit, size);
|
||||
}
|
||||
ctx->print(ctx, "%d: %s [%ux%u]",
|
||||
wl->idx, wl->window->name, wl->window->sx, wl->window->sy);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
37
cmd-list.c
37
cmd-list.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-list.c,v 1.5 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-list.c,v 1.6 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -86,41 +86,6 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_send(struct cmd_list *cmdlist, struct buffer *b)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
n++;
|
||||
|
||||
buffer_write(b, &n, sizeof n);
|
||||
TAILQ_FOREACH(cmd, cmdlist, qentry)
|
||||
cmd_send(cmd, b);
|
||||
}
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_recv(struct buffer *b)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
u_int n;
|
||||
|
||||
buffer_read(b, &n, sizeof n);
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
TAILQ_INIT(cmdlist);
|
||||
|
||||
while (n-- > 0) {
|
||||
cmd = cmd_recv(b);
|
||||
TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
|
||||
}
|
||||
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-load-buffer.c,v 1.4 2009-05-21 19:38:51 nicm Exp $ */
|
||||
/* $Id: cmd-load-buffer.c,v 1.11 2009-10-28 23:10:05 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -35,12 +35,10 @@ int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_load_buffer_entry = {
|
||||
"load-buffer", "loadb",
|
||||
CMD_BUFFER_SESSION_USAGE " path",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_load_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
@@ -50,25 +48,22 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct session *s;
|
||||
struct stat statbuf;
|
||||
struct stat sb;
|
||||
FILE *f;
|
||||
char *buf;
|
||||
u_int limit;
|
||||
u_char *buf;
|
||||
u_int limit;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (stat(data->arg, &statbuf) < 0) {
|
||||
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (!S_ISREG(statbuf.st_mode)) {
|
||||
ctx->error(ctx, "%s: not a regular file", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((f = fopen(data->arg, "rb")) == NULL) {
|
||||
if (fstat(fileno(f), &sb) < 0) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -76,27 +71,27 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
* We don't want to die due to memory exhaustion, hence xmalloc can't
|
||||
* be used here.
|
||||
*/
|
||||
if ((buf = malloc(statbuf.st_size + 1)) == NULL) {
|
||||
if ((buf = malloc(sb.st_size + 1)) == NULL) {
|
||||
ctx->error(ctx, "malloc error: %s", strerror(errno));
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (fread(buf, 1, statbuf.st_size, f) != (size_t) statbuf.st_size) {
|
||||
if (fread(buf, 1, sb.st_size, f) != (size_t) sb.st_size) {
|
||||
ctx->error(ctx, "%s: fread error", data->arg);
|
||||
xfree(buf);
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
buf[statbuf.st_size] = '\0';
|
||||
fclose(f);
|
||||
|
||||
limit = options_get_number(&s->options, "buffer-limit");
|
||||
if (data->buffer == -1) {
|
||||
paste_add(&s->buffers, buf, limit);
|
||||
paste_add(&s->buffers, buf, sb.st_size, limit);
|
||||
return (0);
|
||||
}
|
||||
if (paste_replace(&s->buffers, data->buffer, buf) != 0) {
|
||||
if (paste_replace(&s->buffers, data->buffer, buf, sb.st_size) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
xfree(buf);
|
||||
return (-1);
|
||||
|
||||
53
cmd-lock-client.c
Normal file
53
cmd-lock-client.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $Id: cmd-lock-client.c,v 1.1 2009-09-25 17:51:39 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Lock a single client.
|
||||
*/
|
||||
|
||||
int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_lock_client_entry = {
|
||||
"lock-client", "lockc",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_lock_client_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct client *c;
|
||||
|
||||
if ((c = cmd_find_client(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
server_lock_client(c);
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-lock-server.c,v 1.4 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-lock-server.c,v 1.7 2009-09-25 17:47:42 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -33,20 +33,19 @@ int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_lock_server_entry = {
|
||||
"lock-server", "lock",
|
||||
"",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_lock_server_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
int
|
||||
cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
{
|
||||
server_lock();
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
53
cmd-lock-session.c
Normal file
53
cmd-lock-session.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $Id: cmd-lock-session.c,v 1.1 2009-09-25 17:51:39 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Lock all clients attached to a session.
|
||||
*/
|
||||
|
||||
int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_lock_session_entry = {
|
||||
"lock-session", "locks",
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_lock_session_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
server_lock_session(s);
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-move-window.c,v 1.5 2009-01-23 16:59:14 nicm Exp $ */
|
||||
/* $Id: cmd-move-window.c,v 1.12 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_move_window_entry = {
|
||||
"move-window", "movew",
|
||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
CMD_DFLAG|CMD_KFLAG,
|
||||
0, CMD_CHFLAG('d')|CMD_CHFLAG('k'),
|
||||
cmd_srcdst_init,
|
||||
cmd_srcdst_parse,
|
||||
cmd_move_window_exec,
|
||||
cmd_srcdst_send,
|
||||
cmd_srcdst_recv,
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
@@ -46,77 +44,23 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct session *src, *dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int destroyed, idx;
|
||||
struct winlink *wl;
|
||||
char *cause;
|
||||
int idx, kflag, dflag;
|
||||
|
||||
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||
if ((wl = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||
return (-1);
|
||||
if ((idx = cmd_find_index(ctx, data->dst, &dst)) == -2)
|
||||
return (-1);
|
||||
|
||||
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
if (dst == NULL)
|
||||
dst = ctx->cursession;
|
||||
if (dst == NULL)
|
||||
dst = cmd_current_session(ctx);
|
||||
if (dst == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wl_dst = NULL;
|
||||
if (idx != -1)
|
||||
wl_dst = winlink_find_by_index(&dst->windows, idx);
|
||||
if (wl_dst != NULL) {
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (0);
|
||||
|
||||
if (data->flags & CMD_KFLAG) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session
|
||||
* if this makes it empty.
|
||||
*/
|
||||
session_alert_cancel(dst, wl_dst);
|
||||
winlink_stack_remove(&dst->lastw, wl_dst);
|
||||
winlink_remove(&dst->windows, wl_dst);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl_dst == dst->curw) {
|
||||
data->flags &= ~CMD_DFLAG;
|
||||
dst->curw = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||
if (wl_dst == NULL) {
|
||||
ctx->error(ctx, "attach window failed: %s", cause);
|
||||
kflag = data->chflags & CMD_CHFLAG('k');
|
||||
dflag = data->chflags & CMD_CHFLAG('d');
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||
ctx->error(ctx, "can't move window: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
destroyed = session_detach(src, wl_src);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != src)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_DFLAG)
|
||||
server_status_session(dst);
|
||||
else {
|
||||
session_select(dst, wl_dst->idx);
|
||||
server_redraw_session(dst);
|
||||
}
|
||||
server_unlink_window(src, wl);
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-new-session.c,v 1.41 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-new-session.c,v 1.69 2009-10-12 00:49:06 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -26,13 +29,12 @@
|
||||
|
||||
int cmd_new_session_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_new_session_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_recv(struct cmd *, struct buffer *);
|
||||
void cmd_new_session_free(struct cmd *);
|
||||
void cmd_new_session_init(struct cmd *, int);
|
||||
size_t cmd_new_session_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_new_session_data {
|
||||
char *target;
|
||||
char *newname;
|
||||
char *winname;
|
||||
char *cmd;
|
||||
@@ -41,13 +43,11 @@ struct cmd_new_session_data {
|
||||
|
||||
const struct cmd_entry cmd_new_session_entry = {
|
||||
"new-session", "new",
|
||||
"[-d] [-n window-name] [-s session-name] [command]",
|
||||
CMD_STARTSERVER|CMD_CANTNEST,
|
||||
"[-d] [-n window-name] [-s session-name] [-t target-session] [command]",
|
||||
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, 0,
|
||||
cmd_new_session_init,
|
||||
cmd_new_session_parse,
|
||||
cmd_new_session_exec,
|
||||
cmd_new_session_send,
|
||||
cmd_new_session_recv,
|
||||
cmd_new_session_free,
|
||||
cmd_new_session_print
|
||||
};
|
||||
@@ -59,6 +59,7 @@ cmd_new_session_init(struct cmd *self, unused int arg)
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->flag_detached = 0;
|
||||
data->target = NULL;
|
||||
data->newname = NULL;
|
||||
data->winname = NULL;
|
||||
data->cmd = NULL;
|
||||
@@ -70,10 +71,10 @@ cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
struct cmd_new_session_data *data;
|
||||
int opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ds:n:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "ds:t:n:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
data->flag_detached = 1;
|
||||
@@ -82,6 +83,10 @@ cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
if (data->newname == NULL)
|
||||
data->newname = xstrdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
if (data->winname == NULL)
|
||||
data->winname = xstrdup(optarg);
|
||||
@@ -95,6 +100,9 @@ cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
if (argc != 0 && argc != 1)
|
||||
goto usage;
|
||||
|
||||
if (data->target != NULL && (argc == 1 || data->winname != NULL))
|
||||
goto usage;
|
||||
|
||||
if (argc == 1)
|
||||
data->cmd = xstrdup(argv[0]);
|
||||
|
||||
@@ -111,106 +119,166 @@ int
|
||||
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
struct client *c = ctx->cmdclient;
|
||||
struct session *s;
|
||||
char *cmd, *cwd, *cause;
|
||||
struct session *s, *groupwith;
|
||||
struct window *w;
|
||||
struct environ env;
|
||||
struct termios tio, *tiop;
|
||||
const char *update;
|
||||
char *overrides, *cmd, *cwd, *cause;
|
||||
int detached, idx;
|
||||
u_int sx, sy;
|
||||
|
||||
if (ctx->curclient != NULL)
|
||||
return (0);
|
||||
|
||||
if (!data->flag_detached) {
|
||||
if (c == NULL) {
|
||||
ctx->error(ctx, "no client to attach to");
|
||||
return (-1);
|
||||
}
|
||||
if (!(c->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->newname != NULL && session_find(data->newname) != NULL) {
|
||||
ctx->error(ctx, "duplicate session: %s", data->newname);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cmd = data->cmd;
|
||||
if (cmd == NULL)
|
||||
cmd = options_get_string(&global_options, "default-command");
|
||||
if (c == NULL || c->cwd == NULL)
|
||||
cwd = options_get_string(&global_options, "default-path");
|
||||
else
|
||||
cwd = c->cwd;
|
||||
|
||||
sx = 80;
|
||||
sy = 25;
|
||||
if (!data->flag_detached) {
|
||||
sx = c->tty.sx;
|
||||
sy = c->tty.sy;
|
||||
}
|
||||
|
||||
if (options_get_number(&global_options, "status")) {
|
||||
if (sy == 0)
|
||||
sy = 1;
|
||||
else
|
||||
sy--;
|
||||
}
|
||||
|
||||
if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
xfree(cause);
|
||||
groupwith = NULL;
|
||||
if (data->target != NULL &&
|
||||
(groupwith = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* There are three cases:
|
||||
*
|
||||
* 1. If cmdclient is non-NULL, new-session has been called from the
|
||||
* command-line - cmdclient is to become a new attached, interactive
|
||||
* client. Unless -d is given, the terminal must be opened and then
|
||||
* the client sent MSG_READY.
|
||||
*
|
||||
* 2. If cmdclient is NULL, new-session has been called from an
|
||||
* existing client (such as a key binding).
|
||||
*
|
||||
* 3. Both are NULL, the command was in the configuration file. Treat
|
||||
* this as if -d was given even if it was not.
|
||||
*
|
||||
* In all cases, a new additional session needs to be created and
|
||||
* (unless -d) set as the current session for the client.
|
||||
*/
|
||||
|
||||
/* Set -d if no client. */
|
||||
detached = data->flag_detached;
|
||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||
detached = 1;
|
||||
|
||||
/*
|
||||
* Save the termios settings, part of which is used for new windows in
|
||||
* this session.
|
||||
*
|
||||
* This is read again with tcgetattr() rather than using tty.tio as if
|
||||
* detached, tty_open won't be called. Because of this, it must be done
|
||||
* before opening the terminal as that calls tcsetattr() to prepare for
|
||||
* tmux taking over.
|
||||
*/
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
tiop = &tio;
|
||||
} else
|
||||
tiop = NULL;
|
||||
|
||||
/* Open the terminal if necessary. */
|
||||
if (!detached && ctx->cmdclient != NULL) {
|
||||
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
|
||||
ctx->error(ctx, "not a terminal");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
overrides =
|
||||
options_get_string(&global_s_options, "terminal-overrides");
|
||||
if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||
cwd = ctx->cmdclient->cwd;
|
||||
else
|
||||
cwd = options_get_string(&global_s_options, "default-path");
|
||||
|
||||
s = session_create(data->newname, cmd, cwd, sx, sy, &cause);
|
||||
/* Find new session size. */
|
||||
if (detached) {
|
||||
sx = 80;
|
||||
sy = 24;
|
||||
} else if (ctx->cmdclient != NULL) {
|
||||
sx = ctx->cmdclient->tty.sx;
|
||||
sy = ctx->cmdclient->tty.sy;
|
||||
} else {
|
||||
sx = ctx->curclient->tty.sx;
|
||||
sy = ctx->curclient->tty.sy;
|
||||
}
|
||||
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||
sy--;
|
||||
if (sx == 0)
|
||||
sx = 1;
|
||||
if (sy == 0)
|
||||
sy = 1;
|
||||
|
||||
/* Figure out the command for the new window. */
|
||||
if (data->target != NULL)
|
||||
cmd = NULL;
|
||||
else if (data->cmd != NULL)
|
||||
cmd = data->cmd;
|
||||
else
|
||||
cmd = options_get_string(&global_s_options, "default-command");
|
||||
|
||||
/* Construct the environment. */
|
||||
environ_init(&env);
|
||||
update = options_get_string(&global_s_options, "update-environment");
|
||||
if (ctx->cmdclient != NULL)
|
||||
environ_update(update, &ctx->cmdclient->environ, &env);
|
||||
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||
s = session_create(
|
||||
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
if (data->winname != NULL) {
|
||||
xfree(s->curw->window->name);
|
||||
s->curw->window->name = xstrdup(data->winname);
|
||||
options_set_number(
|
||||
&s->curw->window->options, "automatic-rename", 0);
|
||||
environ_free(&env);
|
||||
|
||||
/* Set the initial window name if one given. */
|
||||
if (cmd != NULL && data->winname != NULL) {
|
||||
w = s->curw->window;
|
||||
|
||||
xfree(w->name);
|
||||
w->name = xstrdup(data->winname);
|
||||
|
||||
options_set_number(&w->options, "automatic-rename", 0);
|
||||
}
|
||||
|
||||
if (data->flag_detached) {
|
||||
if (c != NULL)
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else {
|
||||
c->session = s;
|
||||
server_write_client(c, MSG_READY, NULL, 0);
|
||||
server_redraw_client(c);
|
||||
/*
|
||||
* If a target session is given, this is to be part of a session group,
|
||||
* so add it to the group and synchronize.
|
||||
*/
|
||||
if (groupwith != NULL) {
|
||||
session_group_add(groupwith, s);
|
||||
session_group_synchronize_to(s);
|
||||
session_select(s, RB_ROOT(&s->windows)->idx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the client to the new session. If a command client exists, it is
|
||||
* taking this session and needs to get MSG_READY and stay around.
|
||||
*/
|
||||
if (!detached) {
|
||||
if (ctx->cmdclient != NULL) {
|
||||
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
|
||||
ctx->cmdclient->session = s;
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
} else {
|
||||
ctx->curclient->session = s;
|
||||
server_redraw_client(ctx->curclient);
|
||||
}
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_session_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_session_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->newname);
|
||||
cmd_send_string(b, data->winname);
|
||||
cmd_send_string(b, data->cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_session_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_session_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->newname = cmd_recv_string(b);
|
||||
data->winname = cmd_recv_string(b);
|
||||
data->cmd = cmd_recv_string(b);
|
||||
return (!detached); /* 1 means don't tell command client to exit */
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-new-window.c,v 1.31 2009-01-23 16:59:14 nicm Exp $ */
|
||||
/* $Id: cmd-new-window.c,v 1.39 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,8 +28,6 @@
|
||||
|
||||
int cmd_new_window_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_new_window_send(struct cmd *, struct buffer *);
|
||||
void cmd_new_window_recv(struct cmd *, struct buffer *);
|
||||
void cmd_new_window_free(struct cmd *);
|
||||
void cmd_new_window_init(struct cmd *, int);
|
||||
size_t cmd_new_window_print(struct cmd *, char *, size_t);
|
||||
@@ -45,12 +43,10 @@ struct cmd_new_window_data {
|
||||
const struct cmd_entry cmd_new_window_entry = {
|
||||
"new-window", "neww",
|
||||
"[-dk] [-n window-name] [-t target-window] [command]",
|
||||
0,
|
||||
0, 0,
|
||||
cmd_new_window_init,
|
||||
cmd_new_window_parse,
|
||||
cmd_new_window_exec,
|
||||
cmd_new_window_send,
|
||||
cmd_new_window_recv,
|
||||
cmd_new_window_free,
|
||||
cmd_new_window_print
|
||||
};
|
||||
@@ -74,7 +70,7 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
struct cmd_new_window_data *data;
|
||||
int opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dkt:n:")) != -1) {
|
||||
@@ -126,18 +122,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
|
||||
if (arg_parse_window(data->target, &s, &idx) != 0) {
|
||||
ctx->error(ctx, "bad window: %s", data->target);
|
||||
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2)
|
||||
return (-1);
|
||||
}
|
||||
if (s == NULL)
|
||||
s = ctx->cursession;
|
||||
if (s == NULL)
|
||||
s = cmd_current_session(ctx);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "session not found: %s", data->target);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wl = NULL;
|
||||
if (idx != -1)
|
||||
@@ -164,10 +150,12 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (cmd == NULL)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
|
||||
cwd = options_get_string(&global_options, "default-path");
|
||||
cwd = options_get_string(&s->options, "default-path");
|
||||
else
|
||||
cwd = ctx->cmdclient->cwd;
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(&s->options, "base-index");
|
||||
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
|
||||
if (wl == NULL) {
|
||||
ctx->error(ctx, "create window failed: %s", cause);
|
||||
@@ -176,36 +164,13 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
if (!data->flag_detached) {
|
||||
session_select(s, wl->idx);
|
||||
server_redraw_session(s);
|
||||
} else
|
||||
server_status_session(s);
|
||||
server_redraw_session_group(s);
|
||||
} else
|
||||
server_status_session_group(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_window_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->name);
|
||||
cmd_send_string(b, data->cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_new_window_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->name = cmd_recv_string(b);
|
||||
data->cmd = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_new_window_free(struct cmd *self)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-next-layout.c,v 1.2 2009-04-30 21:17:06 nicm Exp $ */
|
||||
/* $Id: cmd-next-layout.c,v 1.5 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_next_layout_entry = {
|
||||
"next-layout", "nextl",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_next_layout_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,12 +42,13 @@ cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
u_int layout;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
layout_next(wl->window);
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
layout = layout_set_next(wl->window);
|
||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-next-window.c,v 1.17 2009-06-25 15:29:34 nicm Exp $ */
|
||||
/* $Id: cmd-next-window.c,v 1.20 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -30,12 +30,10 @@ int cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_next_window_entry = {
|
||||
"next-window", "next",
|
||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_AFLAG,
|
||||
0, CMD_CHFLAG('a'),
|
||||
cmd_next_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_next_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,8 +46,8 @@ cmd_next_window_init(struct cmd *self, int key)
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDESC('n'))
|
||||
data->flags |= CMD_AFLAG;
|
||||
if (key == ('n' | KEYC_ESCAPE))
|
||||
data->chflags |= CMD_CHFLAG('a');
|
||||
}
|
||||
|
||||
int
|
||||
@@ -63,7 +61,7 @@ cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (-1);
|
||||
|
||||
activity = 0;
|
||||
if (data->flags & CMD_AFLAG)
|
||||
if (data->chflags & CMD_CHFLAG('a'))
|
||||
activity = 1;
|
||||
|
||||
if (session_next(s, activity) == 0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-paste-buffer.c,v 1.16 2009-07-02 16:23:54 nicm Exp $ */
|
||||
/* $Id: cmd-paste-buffer.c,v 1.20 2009-09-07 23:48:54 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -27,16 +27,15 @@
|
||||
*/
|
||||
|
||||
int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_paste_buffer_lf2cr(struct buffer *, const char *, size_t);
|
||||
|
||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
"paste-buffer", "pasteb",
|
||||
"[-d] " CMD_BUFFER_WINDOW_USAGE,
|
||||
CMD_DFLAG,
|
||||
"[-dr] " CMD_BUFFER_WINDOW_USAGE,
|
||||
0, CMD_CHFLAG('d')|CMD_CHFLAG('r'),
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_paste_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
@@ -46,13 +45,13 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
wp = wl->window->active;
|
||||
|
||||
if (data->buffer == -1)
|
||||
pb = paste_get_top(&s->buffers);
|
||||
@@ -63,11 +62,16 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
if (pb != NULL && *pb->data != '\0')
|
||||
buffer_write(w->active->out, pb->data, strlen(pb->data));
|
||||
if (pb != NULL && *pb->data != '\0') {
|
||||
/* -r means raw data without LF->CR conversion. */
|
||||
if (data->chflags & CMD_CHFLAG('r'))
|
||||
buffer_write(wp->out, pb->data, pb->size);
|
||||
else
|
||||
cmd_paste_buffer_lf2cr(wp->out, pb->data, pb->size);
|
||||
}
|
||||
|
||||
/* Delete the buffer if -d. */
|
||||
if (data->flags & CMD_DFLAG) {
|
||||
if (data->chflags & CMD_CHFLAG('d')) {
|
||||
if (data->buffer == -1)
|
||||
paste_free_top(&s->buffers);
|
||||
else
|
||||
@@ -76,3 +80,21 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Add bytes to a buffer but change every '\n' to '\r'. */
|
||||
void
|
||||
cmd_paste_buffer_lf2cr(struct buffer *b, const char *data, size_t size)
|
||||
{
|
||||
const char *end = data + size;
|
||||
const char *lf;
|
||||
|
||||
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||
if (lf != data)
|
||||
buffer_write(b, data, lf - data);
|
||||
buffer_write8(b, '\r');
|
||||
data = lf + 1;
|
||||
}
|
||||
|
||||
if (end != data)
|
||||
buffer_write(b, data, end - data);
|
||||
}
|
||||
|
||||
125
cmd-pipe-pane.c
Normal file
125
cmd-pipe-pane.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/* $Id: cmd-pipe-pane.c,v 1.3 2009-10-23 17:26:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Open pipe to redirect pane output. If already open, close first.
|
||||
*/
|
||||
|
||||
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
"pipe-pane", "pipep",
|
||||
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||
CMD_ARG01, CMD_CHFLAG('o'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_pipe_pane_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct window_pane *wp;
|
||||
int old_fd, pipe_fd[2], null_fd, mode;
|
||||
|
||||
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||
return (-1);
|
||||
|
||||
/* Destroy the old pipe. */
|
||||
old_fd = wp->pipe_fd;
|
||||
if (wp->pipe_fd != -1) {
|
||||
buffer_destroy(wp->pipe_buf);
|
||||
close(wp->pipe_fd);
|
||||
wp->pipe_fd = -1;
|
||||
}
|
||||
|
||||
/* If no pipe command, that is enough. */
|
||||
if (data->arg == NULL || *data->arg == '\0')
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* With -o, only open the new pipe if there was no previous one. This
|
||||
* allows a pipe to be toggled with a single key, for example:
|
||||
*
|
||||
* bind ^p pipep -o 'cat >>~/output'
|
||||
*/
|
||||
if (data->chflags & CMD_CHFLAG('o') && old_fd != -1)
|
||||
return (0);
|
||||
|
||||
/* Open the new pipe. */
|
||||
if (pipe(pipe_fd) != 0) {
|
||||
ctx->error(ctx, "pipe error: %s", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Fork the child. */
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||
return (-1);
|
||||
case 0:
|
||||
/* Child process. */
|
||||
close(pipe_fd[0]);
|
||||
sigreset();
|
||||
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (pipe_fd[1] != STDIN_FILENO)
|
||||
close(pipe_fd[1]);
|
||||
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
||||
close(null_fd);
|
||||
|
||||
execl(_PATH_BSHELL, "sh", "-c", data->arg, (char *) NULL);
|
||||
_exit(1);
|
||||
default:
|
||||
/* Parent process. */
|
||||
close(pipe_fd[1]);
|
||||
|
||||
wp->pipe_fd = pipe_fd[0];
|
||||
wp->pipe_buf = buffer_create(BUFSIZ);
|
||||
wp->pipe_off = BUFFER_USED(wp->in);
|
||||
|
||||
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
|
||||
fatal("fcntl failed");
|
||||
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||
fatal("fcntl failed");
|
||||
if (fcntl(wp->pipe_fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
fatal("fcntl failed");
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-previous-layout.c,v 1.1 2009-04-30 21:17:06 nicm Exp $ */
|
||||
/* $Id: cmd-previous-layout.c,v 1.4 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_previous_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_previous_layout_entry = {
|
||||
"previous-layout", "prevl",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_previous_layout_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,12 +42,13 @@ cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
|
||||
u_int layout;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
layout_previous(wl->window);
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
layout = layout_set_previous(wl->window);
|
||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-previous-window.c,v 1.17 2009-06-25 15:29:34 nicm Exp $ */
|
||||
/* $Id: cmd-previous-window.c,v 1.20 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -30,12 +30,10 @@ int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_previous_window_entry = {
|
||||
"previous-window", "prev",
|
||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_AFLAG,
|
||||
0, CMD_CHFLAG('a'),
|
||||
cmd_previous_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_previous_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,8 +46,8 @@ cmd_previous_window_init(struct cmd *self, int key)
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDESC('p'))
|
||||
data->flags |= CMD_AFLAG;
|
||||
if (key == ('p' | KEYC_ESCAPE))
|
||||
data->chflags |= CMD_CHFLAG('a');
|
||||
}
|
||||
|
||||
int
|
||||
@@ -63,7 +61,7 @@ cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (-1);
|
||||
|
||||
activity = 0;
|
||||
if (data->flags & CMD_AFLAG)
|
||||
if (data->chflags & CMD_CHFLAG('a'))
|
||||
activity = 1;
|
||||
|
||||
if (session_previous(s, activity) == 0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-refresh-client.c,v 1.8 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-refresh-client.c,v 1.10 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_refresh_client_entry = {
|
||||
"refresh-client", "refresh",
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_refresh_client_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-rename-session.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-rename-session.c,v 1.18 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_rename_session_entry = {
|
||||
"rename-session", "rename",
|
||||
CMD_TARGET_SESSION_USAGE " new-name",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_rename_session_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -53,5 +51,7 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
xfree(s->name);
|
||||
s->name = xstrdup(data->arg);
|
||||
|
||||
server_status_session(s);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-rename-window.c,v 1.27 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: cmd-rename-window.c,v 1.30 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_rename_window_entry = {
|
||||
"rename-window", "renamew",
|
||||
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_rename_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -55,7 +53,7 @@ cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
wl->window->name = xstrdup(data->arg);
|
||||
options_set_number(&wl->window->options, "automatic-rename", 0);
|
||||
|
||||
server_status_session(s);
|
||||
server_status_window(wl->window);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-resize-pane.c,v 1.7 2009-05-21 19:46:00 nicm Exp $ */
|
||||
/* $Id: cmd-resize-pane.c,v 1.12 2009-07-30 20:45:20 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,32 +31,47 @@ int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_resize_pane_entry = {
|
||||
"resize-pane", "resizep",
|
||||
CMD_PANE_WINDOW_USAGE "[-DU] [adjustment]",
|
||||
CMD_ARG01|CMD_BIGUFLAG|CMD_BIGDFLAG,
|
||||
"[-DU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||
CMD_ARG01,
|
||||
CMD_CHFLAG('D')|CMD_CHFLAG('L')|CMD_CHFLAG('R')|CMD_CHFLAG('U'),
|
||||
cmd_resize_pane_init,
|
||||
cmd_pane_parse,
|
||||
cmd_target_parse,
|
||||
cmd_resize_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_resize_pane_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_pane_data *data;
|
||||
struct cmd_target_data *data;
|
||||
|
||||
cmd_pane_init(self, key);
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDCTL(KEYC_DOWN))
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
|
||||
if (key == KEYC_ADDESC(KEYC_UP))
|
||||
if (key == (KEYC_UP | KEYC_CTRL))
|
||||
data->chflags |= CMD_CHFLAG('U');
|
||||
if (key == (KEYC_DOWN | KEYC_CTRL))
|
||||
data->chflags |= CMD_CHFLAG('D');
|
||||
if (key == (KEYC_LEFT | KEYC_CTRL))
|
||||
data->chflags |= CMD_CHFLAG('L');
|
||||
if (key == (KEYC_RIGHT | KEYC_CTRL))
|
||||
data->chflags |= CMD_CHFLAG('R');
|
||||
|
||||
if (key == (KEYC_UP | KEYC_ESCAPE)) {
|
||||
data->chflags |= CMD_CHFLAG('U');
|
||||
data->arg = xstrdup("5");
|
||||
if (key == KEYC_ADDESC(KEYC_DOWN)) {
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
}
|
||||
if (key == (KEYC_DOWN | KEYC_ESCAPE)) {
|
||||
data->chflags |= CMD_CHFLAG('D');
|
||||
data->arg = xstrdup("5");
|
||||
}
|
||||
if (key == (KEYC_LEFT | KEYC_ESCAPE)) {
|
||||
data->chflags |= CMD_CHFLAG('L');
|
||||
data->arg = xstrdup("5");
|
||||
}
|
||||
if (key == (KEYC_RIGHT | KEYC_ESCAPE)) {
|
||||
data->chflags |= CMD_CHFLAG('R');
|
||||
data->arg = xstrdup("5");
|
||||
}
|
||||
}
|
||||
@@ -64,23 +79,14 @@ cmd_resize_pane_init(struct cmd *self, int key)
|
||||
int
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
const char *errstr;
|
||||
struct window_pane *wp;
|
||||
u_int adjust;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->arg == NULL)
|
||||
adjust = 1;
|
||||
@@ -92,12 +98,14 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(data->flags & CMD_BIGDFLAG))
|
||||
adjust = -adjust;
|
||||
if (layout_resize(wp, adjust) != 0) {
|
||||
ctx->error(ctx, "layout %s "
|
||||
"does not support resizing", layout_name(wp->window));
|
||||
return (-1);
|
||||
if (data->chflags & (CMD_CHFLAG('L')|CMD_CHFLAG('R'))) {
|
||||
if (data->chflags & CMD_CHFLAG('L'))
|
||||
adjust = -adjust;
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||
} else {
|
||||
if (data->chflags & CMD_CHFLAG('U'))
|
||||
adjust = -adjust;
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-respawn-window.c,v 1.14 2009-03-04 17:24:07 nicm Exp $ */
|
||||
/* $Id: cmd-respawn-window.c,v 1.22 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_respawn_window_entry = {
|
||||
"respawn-window", "respawnw",
|
||||
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
CMD_ARG01|CMD_KFLAG,
|
||||
CMD_ARG01, CMD_CHFLAG('k'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_respawn_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -49,14 +47,14 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
const char **env;
|
||||
struct environ env;
|
||||
char *cause;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
if (!(data->flags & CMD_KFLAG)) {
|
||||
if (!(data->chflags & CMD_CHFLAG('k'))) {
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
@@ -66,22 +64,31 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
env = server_fill_environ(s);
|
||||
environ_init(&env);
|
||||
environ_copy(&global_environ, &env);
|
||||
environ_copy(&s->environ, &env);
|
||||
server_fill_environ(s, &env);
|
||||
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
layout_free(w);
|
||||
window_destroy_panes(w);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
if (window_pane_spawn(wp, data->arg, NULL, env, &cause) != 0) {
|
||||
if (window_pane_spawn(
|
||||
wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||
xfree(cause);
|
||||
environ_free(&env);
|
||||
return (-1);
|
||||
}
|
||||
layout_init(w);
|
||||
screen_reinit(&wp->base);
|
||||
window_set_active_pane(w, wp);
|
||||
|
||||
recalculate_sizes();
|
||||
server_redraw_window(w);
|
||||
|
||||
environ_free(&env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-rotate-window.c,v 1.4 2009-06-25 15:28:08 nicm Exp $ */
|
||||
/* $Id: cmd-rotate-window.c,v 1.9 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -30,12 +30,10 @@ int cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_rotate_window_entry = {
|
||||
"rotate-window", "rotatew",
|
||||
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_BIGUFLAG|CMD_BIGDFLAG,
|
||||
0, CMD_CHFLAG('D')|CMD_CHFLAG('U'),
|
||||
cmd_rotate_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_rotate_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,8 +46,8 @@ cmd_rotate_window_init(struct cmd *self, int key)
|
||||
cmd_target_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
if (key == KEYC_ADDESC('o'))
|
||||
data->flags |= CMD_BIGDFLAG;
|
||||
if (key == ('o' | KEYC_ESCAPE))
|
||||
data->chflags |= CMD_CHFLAG('D');
|
||||
}
|
||||
|
||||
int
|
||||
@@ -59,64 +57,68 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp, *wp2;
|
||||
struct layout_cell *lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
int flags;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
if (data->flags & CMD_BIGDFLAG) {
|
||||
if (data->chflags & CMD_CHFLAG('D')) {
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
|
||||
lc = wp->layout_cell;
|
||||
xoff = wp->xoff; yoff = wp->yoff;
|
||||
sx = wp->sx; sy = wp->sy;
|
||||
flags = wp->flags;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
|
||||
break;
|
||||
wp->layout_cell = wp2->layout_cell;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= wp2->flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||
}
|
||||
wp->layout_cell = lc;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = xoff; wp->yoff = yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, sx, sy);
|
||||
|
||||
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
window_set_active_pane(w, wp);
|
||||
server_redraw_window(w);
|
||||
} else {
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
|
||||
|
||||
lc = wp->layout_cell;
|
||||
xoff = wp->xoff; yoff = wp->yoff;
|
||||
sx = wp->sx; sy = wp->sy;
|
||||
flags = wp->flags;
|
||||
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
|
||||
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
|
||||
break;
|
||||
wp->layout_cell = wp2->layout_cell;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= wp2->flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, wp2->sx, wp2->sy);
|
||||
}
|
||||
wp->layout_cell = lc;
|
||||
if (wp->layout_cell != NULL)
|
||||
wp->layout_cell->wp = wp;
|
||||
wp->xoff = xoff; wp->yoff = yoff;
|
||||
wp->flags &= ~PANE_HIDDEN;
|
||||
wp->flags |= flags & PANE_HIDDEN;
|
||||
window_pane_resize(wp, sx, sy);
|
||||
|
||||
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
window_set_active_pane(w, wp);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
layout_refresh(w, 0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
137
cmd-run-shell.c
Normal file
137
cmd-run-shell.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/* $Id: cmd-run-shell.c,v 1.4 2009-11-02 21:38:26 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Runs a command without a window.
|
||||
*/
|
||||
|
||||
int cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_run_shell_callback(struct job *);
|
||||
void cmd_run_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_run_shell_entry = {
|
||||
"run-shell", "run",
|
||||
"command",
|
||||
CMD_ARG1, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_run_shell_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
struct cmd_run_shell_data {
|
||||
char *cmd;
|
||||
struct cmd_ctx ctx;
|
||||
};
|
||||
|
||||
int
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct cmd_run_shell_data *cdata;
|
||||
struct job *job;
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(data->arg);
|
||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
ctx->cmdclient->references++;
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references++;
|
||||
|
||||
job = job_add(NULL, 0, NULL,
|
||||
data->arg, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||
job_run(job);
|
||||
|
||||
return (1); /* don't let client exit */
|
||||
}
|
||||
|
||||
void
|
||||
cmd_run_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
char *cmd, *msg, *line, *buf;
|
||||
size_t off, len, llen;
|
||||
int retcode;
|
||||
|
||||
buf = BUFFER_OUT(job->out);
|
||||
len = BUFFER_USED(job->out);
|
||||
|
||||
cmd = cdata->cmd;
|
||||
|
||||
if (len != 0) {
|
||||
line = buf;
|
||||
for (off = 0; off < len; off++) {
|
||||
if (buf[off] == '\n') {
|
||||
llen = buf + off - line;
|
||||
if (llen > INT_MAX)
|
||||
break;
|
||||
ctx->print(ctx, "%.*s", (int) llen, line);
|
||||
line = buf + off + 1;
|
||||
}
|
||||
}
|
||||
llen = buf + len - line;
|
||||
if (llen > 0 && llen < INT_MAX)
|
||||
ctx->print(ctx, "%.*s", (int) llen, line);
|
||||
}
|
||||
|
||||
msg = NULL;
|
||||
if (WIFEXITED(job->status)) {
|
||||
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||
} else if (WIFSIGNALED(job->status)) {
|
||||
retcode = WTERMSIG(job->status);
|
||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||
}
|
||||
if (msg != NULL) {
|
||||
if (len != 0)
|
||||
ctx->print(ctx, "%s", msg);
|
||||
else
|
||||
ctx->info(ctx, "%s", msg);
|
||||
xfree(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cmd_run_shell_free(void *data)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
|
||||
if (ctx->cmdclient != NULL) {
|
||||
ctx->cmdclient->references--;
|
||||
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
|
||||
}
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references--;
|
||||
|
||||
xfree(cdata->cmd);
|
||||
xfree(cdata);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-save-buffer.c,v 1.5 2009-05-18 16:22:30 nicm Exp $ */
|
||||
/* $Id: cmd-save-buffer.c,v 1.9 2009-10-28 23:08:52 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -33,12 +33,10 @@ int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_save_buffer_entry = {
|
||||
"save-buffer", "saveb",
|
||||
"[-a] " CMD_BUFFER_SESSION_USAGE " path",
|
||||
CMD_AFLAG|CMD_ARG1,
|
||||
CMD_ARG1, CMD_CHFLAG('a'),
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_save_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
@@ -68,23 +66,23 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
|
||||
mask = umask(S_IRWXG | S_IRWXO);
|
||||
if (data->flags & CMD_AFLAG)
|
||||
if (data->chflags & CMD_CHFLAG('a'))
|
||||
f = fopen(data->arg, "ab");
|
||||
else
|
||||
f = fopen(data->arg, "wb");
|
||||
umask(mask);
|
||||
if (f == NULL) {
|
||||
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (fwrite(pb->data, 1, strlen(pb->data), f) != strlen(pb->data)) {
|
||||
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||
ctx->error(ctx, "%s: fwrite error", data->arg);
|
||||
fclose(f);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
umask(mask);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-layout.c,v 1.3 2009-06-25 16:34:50 nicm Exp $ */
|
||||
/* $Id: cmd-select-layout.c,v 1.8 2009-07-28 23:04:29 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,13 +29,11 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_select_layout_entry = {
|
||||
"select-layout", "selectl",
|
||||
CMD_TARGET_WINDOW_USAGE " layout-name",
|
||||
CMD_ARG1,
|
||||
CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||
CMD_ARG01, 0,
|
||||
cmd_select_layout_init,
|
||||
cmd_target_parse,
|
||||
cmd_select_layout_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -49,17 +47,17 @@ cmd_select_layout_init(struct cmd *self, int key)
|
||||
data = self->data;
|
||||
|
||||
switch (key) {
|
||||
case KEYC_ADDESC('0'):
|
||||
data->arg = xstrdup("manual-vertical");
|
||||
break;
|
||||
case KEYC_ADDESC('1'):
|
||||
case ('1' | KEYC_ESCAPE):
|
||||
data->arg = xstrdup("even-horizontal");
|
||||
break;
|
||||
case KEYC_ADDESC('2'):
|
||||
case ('2' | KEYC_ESCAPE):
|
||||
data->arg = xstrdup("even-vertical");
|
||||
break;
|
||||
case ('3' | KEYC_ESCAPE):
|
||||
data->arg = xstrdup("main-horizontal");
|
||||
break;
|
||||
case KEYC_ADDESC('9'):
|
||||
data->arg = xstrdup("active-only");
|
||||
case ('4' | KEYC_ESCAPE):
|
||||
data->arg = xstrdup("main-vertical");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -74,13 +72,17 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if ((layout = layout_lookup(data->arg)) == -1) {
|
||||
ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
|
||||
if (data->arg == NULL) {
|
||||
layout = wl->window->lastlayout;
|
||||
if (layout == -1)
|
||||
return (0);
|
||||
} else if ((layout = layout_set_lookup(data->arg)) == -1) {
|
||||
ctx->error(ctx, "unknown layout or ambiguous: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (layout_select(wl->window, layout) == 0)
|
||||
ctx->info(ctx, "layout now: %s", layout_name(wl->window));
|
||||
|
||||
layout = layout_set_select(wl->window, layout);
|
||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-pane.c,v 1.4 2009-04-01 21:10:08 nicm Exp $ */
|
||||
/* $Id: cmd-select-pane.c,v 1.10 2009-07-30 20:45:20 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,42 +28,31 @@ int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_select_pane_entry = {
|
||||
"select-pane", "selectp",
|
||||
CMD_PANE_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_pane_init,
|
||||
cmd_pane_parse,
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_select_pane_exec,
|
||||
cmd_pane_send,
|
||||
cmd_pane_recv,
|
||||
cmd_pane_free,
|
||||
cmd_pane_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_pane_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if ((wl = cmd_find_pane(ctx, data->target, NULL, &wp)) == NULL)
|
||||
return (-1);
|
||||
if (data->pane == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
wp = window_pane_at_index(wl->window, data->pane);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->pane);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (wp->flags & PANE_HIDDEN) {
|
||||
ctx->error(ctx, "pane %d is hidden", data->pane);
|
||||
if (!window_pane_visible(wp)) {
|
||||
ctx->error(ctx, "pane not visible: %s", data->target);
|
||||
return (-1);
|
||||
}
|
||||
window_set_active_pane(wl->window, wp);
|
||||
layout_refresh(wl->window, 1);
|
||||
server_status_window(wl->window);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-prompt.c,v 1.7 2009-02-13 18:57:55 nicm Exp $ */
|
||||
/* $Id: cmd-select-prompt.c,v 1.12 2009-08-16 19:29:24 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -33,12 +33,10 @@ int cmd_select_prompt_callback(void *, const char *);
|
||||
const struct cmd_entry cmd_select_prompt_entry = {
|
||||
"select-prompt", NULL,
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_select_prompt_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -55,7 +53,7 @@ cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (c->prompt_string != NULL)
|
||||
return (0);
|
||||
|
||||
status_prompt_set(c, "index ", cmd_select_prompt_callback, c, 0);
|
||||
status_prompt_set(c, "index ", cmd_select_prompt_callback, NULL, c, 0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -68,20 +66,20 @@ cmd_select_prompt_callback(void *data, const char *s)
|
||||
char msg[128];
|
||||
u_int idx;
|
||||
|
||||
if (s == NULL)
|
||||
if (s == NULL || *s == '\0')
|
||||
return (0);
|
||||
|
||||
idx = strtonum(s, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "Index %s: %s", errstr, s);
|
||||
status_message_set(c, msg);
|
||||
status_message_set(c, "%s", msg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (winlink_find_by_index(&c->session->windows, idx) == NULL) {
|
||||
xsnprintf(msg, sizeof msg,
|
||||
"Window not found: %s:%d", c->session->name, idx);
|
||||
status_message_set(c, msg);
|
||||
status_message_set(c, "%s", msg);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-window.c,v 1.21 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-select-window.c,v 1.23 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,12 +32,10 @@ int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_select_window_entry = {
|
||||
"select-window", "selectw",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_select_window_init,
|
||||
cmd_target_parse,
|
||||
cmd_select_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-send-keys.c,v 1.18 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-send-keys.c,v 1.22 2009-09-22 14:03:11 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,27 +28,22 @@
|
||||
|
||||
int cmd_send_keys_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_send_keys_send(struct cmd *, struct buffer *);
|
||||
void cmd_send_keys_recv(struct cmd *, struct buffer *);
|
||||
void cmd_send_keys_free(struct cmd *);
|
||||
size_t cmd_send_keys_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_send_keys_data {
|
||||
char *target;
|
||||
int idx;
|
||||
u_int nkeys;
|
||||
int *keys;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_send_keys_entry = {
|
||||
"send-keys", "send",
|
||||
"[-t target-window] key ...",
|
||||
0,
|
||||
"[-t target-pane] key ...",
|
||||
0, 0,
|
||||
NULL,
|
||||
cmd_send_keys_parse,
|
||||
cmd_send_keys_exec,
|
||||
cmd_send_keys_send,
|
||||
cmd_send_keys_recv,
|
||||
cmd_send_keys_free,
|
||||
cmd_send_keys_print
|
||||
};
|
||||
@@ -62,7 +57,6 @@ cmd_send_keys_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->target = NULL;
|
||||
data->idx = -1;
|
||||
data->nkeys = 0;
|
||||
data->keys = NULL;
|
||||
|
||||
@@ -110,45 +104,21 @@ int
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_send_keys_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
u_int i;
|
||||
|
||||
if (data == NULL)
|
||||
return (-1);
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL)
|
||||
return (-1);
|
||||
|
||||
for (i = 0; i < data->nkeys; i++) {
|
||||
window_pane_key(
|
||||
wl->window->active, ctx->curclient, data->keys[i]);
|
||||
}
|
||||
for (i = 0; i < data->nkeys; i++)
|
||||
window_pane_key(wp, ctx->curclient, data->keys[i]);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_send_keys_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_send_keys_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
buffer_write(b, data->keys, data->nkeys * sizeof *data->keys);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_send_keys_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_send_keys_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->keys = xcalloc(data->nkeys, sizeof *data->keys);
|
||||
buffer_read(b, data->keys, data->nkeys * sizeof *data->keys);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_send_keys_free(struct cmd *self)
|
||||
{
|
||||
@@ -171,8 +141,6 @@ cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
|
||||
return (off);
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->idx != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -i %d", data->idx);
|
||||
|
||||
for (i = 0; i < data->nkeys; i++) {
|
||||
if (off >= len)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-send-prefix.c,v 1.23 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-send-prefix.c,v 1.27 2009-09-22 14:22:20 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,13 +28,11 @@ int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_send_prefix_entry = {
|
||||
"send-prefix", NULL,
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_send_prefix_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,14 +42,14 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
int key;
|
||||
struct window_pane *wp;
|
||||
struct keylist *keylist;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
if (cmd_find_pane(ctx, data->target, &s, &wp) == NULL)
|
||||
return (-1);
|
||||
|
||||
key = options_get_number(&s->options, "prefix");
|
||||
window_pane_key(wl->window->active, ctx->curclient, key);
|
||||
keylist = options_get_data(&s->options, "prefix");
|
||||
window_pane_key(wp, ctx->curclient, ARRAY_FIRST(keylist));
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-server-info.c,v 1.20 2009-06-25 20:27:31 nicm Exp $ */
|
||||
/* $Id: cmd-server-info.c,v 1.33 2009-11-04 22:42:31 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -35,13 +35,11 @@ int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_server_info_entry = {
|
||||
"server-info", "info",
|
||||
"",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_server_info_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -57,7 +55,9 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct tty_code *code;
|
||||
struct tty_term_code_entry *ent;
|
||||
struct utsname un;
|
||||
struct job *job;
|
||||
struct grid *gd;
|
||||
struct grid_line *gl;
|
||||
u_int i, j, k;
|
||||
char out[80];
|
||||
char *tim;
|
||||
@@ -71,8 +71,8 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
"tmux " BUILD ", pid %ld, started %s", (long) getpid(), tim);
|
||||
ctx->print(ctx, "socket path %s, debug level %d%s",
|
||||
socket_path, debug_level, be_quiet ? ", quiet" : "");
|
||||
if (uname(&un) == 0) {
|
||||
ctx->print(ctx, "system is %s %s %s %s",
|
||||
if (uname(&un) == 0) {
|
||||
ctx->print(ctx, "system is %s %s %s %s",
|
||||
un.sysname, un.release, un.version, un.machine);
|
||||
}
|
||||
if (cfg_file != NULL)
|
||||
@@ -82,7 +82,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||
ctx->print(ctx, "%u clients, %u sessions",
|
||||
ARRAY_LENGTH(&clients), ARRAY_LENGTH(&sessions));
|
||||
ctx->print(ctx, "");
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Clients:");
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
@@ -91,11 +91,12 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
continue;
|
||||
|
||||
ctx->print(ctx, "%2d: %s (%d, %d): %s [%ux%u %s] "
|
||||
"[flags=0x%x/0x%x]", i, c->tty.path, c->fd, c->tty.fd,
|
||||
c->session->name, c->tty.sx, c->tty.sy, c->tty.termname,
|
||||
c->flags, c->tty.flags);
|
||||
"[flags=0x%x/0x%x, references=%u]", i, c->tty.path,
|
||||
c->ibuf.fd, c->tty.fd, c->session->name,
|
||||
c->tty.sx, c->tty.sy, c->tty.termname, c->flags,
|
||||
c->tty.flags, c->references);
|
||||
}
|
||||
ctx->print(ctx, "");
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||
@@ -104,33 +105,35 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (s == NULL)
|
||||
continue;
|
||||
|
||||
t = s->tv.tv_sec;
|
||||
t = s->creation_time.tv_sec;
|
||||
tim = ctime(&t);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||
"[flags=0x%x]", i, s->name, winlink_count(&s->windows),
|
||||
tim, s->sx, s->sy, s->flags);
|
||||
"[flags=0x%x, references=%u]", i, s->name,
|
||||
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags,
|
||||
s->references);
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||
"references=%u, layout=%u]", wl->idx, w->name,
|
||||
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||
w->sx, w->sy, w->flags, w->references,
|
||||
w->layout);
|
||||
w->lastlayout);
|
||||
j = 0;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
lines = ulines = size = usize = 0;
|
||||
gd = wp->base.grid;
|
||||
for (k = 0; k < gd->hsize + gd->sy; k++) {
|
||||
if (gd->data[k] != NULL) {
|
||||
gl = &gd->linedata[k];
|
||||
if (gl->celldata != NULL) {
|
||||
lines++;
|
||||
size += gd->size[k] *
|
||||
sizeof (**gd->data);
|
||||
size += gl->cellsize *
|
||||
sizeof *gl->celldata;
|
||||
}
|
||||
if (gd->udata[k] != NULL) {
|
||||
if (gl->utf8data != NULL) {
|
||||
ulines++;
|
||||
usize += gd->usize[k] *
|
||||
sizeof (**gd->udata);
|
||||
usize += gl->utf8size *
|
||||
sizeof *gl->utf8data;
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||
@@ -142,7 +145,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "");
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Terminals:");
|
||||
SLIST_FOREACH(term, &tty_terms, entry) {
|
||||
@@ -174,7 +177,13 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "");
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Jobs:");
|
||||
SLIST_FOREACH(job, &all_jobs, lentry) {
|
||||
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d, flags=0x%x]",
|
||||
job->cmd, job->fd, job->pid, job->status, job->flags);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-buffer.c,v 1.7 2009-01-25 18:51:28 tcunha Exp $ */
|
||||
/* $Id: cmd-set-buffer.c,v 1.10 2009-09-07 23:48:54 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -31,12 +31,10 @@ int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_set_buffer_entry = {
|
||||
"set-buffer", "setb",
|
||||
CMD_BUFFER_SESSION_USAGE " data",
|
||||
CMD_ARG1,
|
||||
CMD_ARG1, 0,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_set_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
@@ -47,17 +45,23 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct session *s;
|
||||
u_int limit;
|
||||
u_char *pdata;
|
||||
size_t psize;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
limit = options_get_number(&s->options, "buffer-limit");
|
||||
|
||||
pdata = xstrdup(data->arg);
|
||||
psize = strlen(pdata);
|
||||
|
||||
if (data->buffer == -1) {
|
||||
paste_add(&s->buffers, xstrdup(data->arg), limit);
|
||||
paste_add(&s->buffers, pdata, psize, limit);
|
||||
return (0);
|
||||
}
|
||||
if (paste_replace(&s->buffers, data->buffer, xstrdup(data->arg)) != 0) {
|
||||
if (paste_replace(&s->buffers, data->buffer, pdata, psize) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
xfree(pdata);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
|
||||
88
cmd-set-environment.c
Normal file
88
cmd-set-environment.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/* $Id: cmd-set-environment.c,v 1.2 2009-08-11 14:42:59 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Set an environment variable.
|
||||
*/
|
||||
|
||||
int cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_set_environment_entry = {
|
||||
"set-environment", "setenv",
|
||||
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||
CMD_ARG12, CMD_CHFLAG('g')|CMD_CHFLAG('r')|CMD_CHFLAG('u'),
|
||||
NULL,
|
||||
cmd_target_parse,
|
||||
cmd_set_environment_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct environ *env;
|
||||
|
||||
if (*data->arg == '\0') {
|
||||
ctx->error(ctx, "empty variable name");
|
||||
return (-1);
|
||||
}
|
||||
if (strchr(data->arg, '=') != NULL) {
|
||||
ctx->error(ctx, "variable name contains =");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
env = &global_environ;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
env = &s->environ;
|
||||
}
|
||||
|
||||
if (data->chflags & CMD_CHFLAG('u')) {
|
||||
if (data->arg2 != NULL) {
|
||||
ctx->error(ctx, "can't specify a value with -u");
|
||||
return (-1);
|
||||
}
|
||||
environ_unset(env, data->arg);
|
||||
} else if (data->chflags & CMD_CHFLAG('r')) {
|
||||
if (data->arg2 != NULL) {
|
||||
ctx->error(ctx, "can't specify a value with -r");
|
||||
return (-1);
|
||||
}
|
||||
environ_set(env, data->arg, NULL);
|
||||
} else {
|
||||
if (data->arg2 == NULL) {
|
||||
ctx->error(ctx, "no value specified");
|
||||
return (-1);
|
||||
}
|
||||
environ_set(env, data->arg, data->arg2);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
127
cmd-set-option.c
127
cmd-set-option.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-option.c,v 1.62 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-set-option.c,v 1.85 2009-11-02 21:38:26 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,101 +31,127 @@ int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_set_option_entry = {
|
||||
"set-option", "set",
|
||||
CMD_OPTION_SESSION_USAGE,
|
||||
CMD_GFLAG|CMD_UFLAG,
|
||||
"[-agu] " CMD_TARGET_SESSION_USAGE " option [value]",
|
||||
CMD_ARG12, CMD_CHFLAG('a')|CMD_CHFLAG('g')|CMD_CHFLAG('u'),
|
||||
NULL,
|
||||
cmd_option_parse,
|
||||
cmd_target_parse,
|
||||
cmd_set_option_exec,
|
||||
cmd_option_send,
|
||||
cmd_option_recv,
|
||||
cmd_option_free,
|
||||
cmd_option_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
const char *set_option_status_keys_list[] = {
|
||||
"emacs", "vi", NULL
|
||||
};
|
||||
const char *set_option_status_justify_list[] = {
|
||||
"left", "centre", "right", NULL
|
||||
};
|
||||
const char *set_option_bell_action_list[] = {
|
||||
"none", "any", "current", NULL
|
||||
};
|
||||
const struct set_option_entry set_option_table[NSETOPTION] = {
|
||||
const struct set_option_entry set_option_table[] = {
|
||||
{ "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
|
||||
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "default-path", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "default-shell", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "default-terminal", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "display-panes-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "display-panes-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "history-limit", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "lock-after-time", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "lock-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "lock-server", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "message-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "message-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "message-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "prefix", SET_OPTION_KEY, 0, 0, NULL },
|
||||
{ "mouse-select-pane", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "prefix", SET_OPTION_KEYS, 0, 0, NULL },
|
||||
{ "repeat-time", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||
{ "set-remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "set-titles", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "set-titles-string", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "status", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "status-justify",
|
||||
SET_OPTION_CHOICE, 0, 0, set_option_status_justify_list },
|
||||
{ "status-keys", SET_OPTION_CHOICE, 0, 0, set_option_status_keys_list },
|
||||
{ "status-left", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "status-left-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "status-left-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-left-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-left-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "status-right-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "status-right-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-right-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||
{ "status-utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "status-utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "terminal-overrides", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "update-environment", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "visual-activity", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "visual-bell", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "visual-content", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ NULL, 0, 0, 0, NULL }
|
||||
};
|
||||
|
||||
int
|
||||
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
struct options *oo;
|
||||
const struct set_option_entry *entry;
|
||||
const struct set_option_entry *entry, *opt;
|
||||
struct jobs *jobs;
|
||||
struct job *job, *nextjob;
|
||||
u_int i;
|
||||
int try_again;
|
||||
|
||||
if (data->flags & CMD_GFLAG)
|
||||
oo = &global_options;
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
oo = &global_s_options;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
oo = &s->options;
|
||||
}
|
||||
|
||||
if (*data->option == '\0') {
|
||||
if (*data->arg == '\0') {
|
||||
ctx->error(ctx, "invalid option");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
entry = NULL;
|
||||
for (i = 0; i < NSETOPTION; i++) {
|
||||
if (strncmp(set_option_table[i].name,
|
||||
data->option, strlen(data->option)) != 0)
|
||||
for (opt = set_option_table; opt->name != NULL; opt++) {
|
||||
if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
|
||||
continue;
|
||||
if (entry != NULL) {
|
||||
ctx->error(ctx, "ambiguous option: %s", data->option);
|
||||
ctx->error(ctx, "ambiguous option: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
entry = &set_option_table[i];
|
||||
entry = opt;
|
||||
|
||||
/* Bail now if an exact match. */
|
||||
if (strcmp(entry->name, data->option) == 0)
|
||||
if (strcmp(entry->name, data->arg) == 0)
|
||||
break;
|
||||
}
|
||||
if (entry == NULL) {
|
||||
ctx->error(ctx, "unknown option: %s", data->option);
|
||||
ctx->error(ctx, "unknown option: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_UFLAG) {
|
||||
if (data->flags & CMD_GFLAG) {
|
||||
if (data->chflags & CMD_CHFLAG('u')) {
|
||||
if (data->chflags & CMD_CHFLAG('g')) {
|
||||
ctx->error(ctx,
|
||||
"can't unset global option: %s", entry->name);
|
||||
return (-1);
|
||||
}
|
||||
if (data->value != NULL) {
|
||||
if (data->arg2 != NULL) {
|
||||
ctx->error(ctx,
|
||||
"value passed to unset option: %s", entry->name);
|
||||
return (-1);
|
||||
@@ -136,34 +162,61 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
} else {
|
||||
switch (entry->type) {
|
||||
case SET_OPTION_STRING:
|
||||
set_option_string(ctx, oo, entry, data->value);
|
||||
set_option_string(ctx, oo, entry,
|
||||
data->arg2, data->chflags & CMD_CHFLAG('a'));
|
||||
break;
|
||||
case SET_OPTION_NUMBER:
|
||||
set_option_number(ctx, oo, entry, data->value);
|
||||
set_option_number(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
set_option_key(ctx, oo, entry, data->value);
|
||||
case SET_OPTION_KEYS:
|
||||
set_option_keys(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_COLOUR:
|
||||
set_option_colour(ctx, oo, entry, data->value);
|
||||
set_option_colour(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_ATTRIBUTES:
|
||||
set_option_attributes(ctx, oo, entry, data->value);
|
||||
set_option_attributes(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
set_option_flag(ctx, oo, entry, data->value);
|
||||
set_option_flag(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
set_option_choice(ctx, oo, entry, data->value);
|
||||
set_option_choice(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
recalculate_sizes();
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && c->session != NULL)
|
||||
|
||||
/*
|
||||
* Special-case: kill all persistent jobs if status-left, status-right
|
||||
* or set-titles-string have changed. Persistent jobs are only used by
|
||||
* the status line at the moment so this works XXX.
|
||||
*/
|
||||
if (strcmp(entry->name, "status-left") == 0 ||
|
||||
strcmp(entry->name, "status-right") == 0 ||
|
||||
strcmp(entry->name, "set-titles-string") == 0) {
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
continue;
|
||||
|
||||
jobs = &c->status_jobs;
|
||||
do {
|
||||
try_again = 0;
|
||||
job = RB_ROOT(jobs);
|
||||
while (job != NULL) {
|
||||
nextjob = RB_NEXT(jobs, jobs, job);
|
||||
if (job->flags & JOB_PERSIST) {
|
||||
job_remove(jobs, job);
|
||||
try_again = 1;
|
||||
break;
|
||||
}
|
||||
job = nextjob;
|
||||
}
|
||||
} while (try_again);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
/* $Id: cmd-set-password.c,v 1.5 2009-06-25 16:47:00 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Set server password.
|
||||
*/
|
||||
|
||||
int cmd_set_password_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_set_password_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_set_password_send(struct cmd *, struct buffer *);
|
||||
void cmd_set_password_recv(struct cmd *, struct buffer *);
|
||||
void cmd_set_password_free(struct cmd *);
|
||||
void cmd_set_password_init(struct cmd *, int);
|
||||
size_t cmd_set_password_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_set_password_data {
|
||||
char *password;
|
||||
int flag_encrypted;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_set_password_entry = {
|
||||
"set-password", "pass",
|
||||
"[-c] password",
|
||||
0,
|
||||
cmd_set_password_init,
|
||||
cmd_set_password_parse,
|
||||
cmd_set_password_exec,
|
||||
cmd_set_password_send,
|
||||
cmd_set_password_recv,
|
||||
cmd_set_password_free,
|
||||
cmd_set_password_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_set_password_init(struct cmd *self, unused int arg)
|
||||
{
|
||||
struct cmd_set_password_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->password = NULL;
|
||||
data->flag_encrypted = 0;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_set_password_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_set_password_data *data;
|
||||
int opt;
|
||||
char *out;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "c")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
data->flag_encrypted = 1;
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 1)
|
||||
goto usage;
|
||||
|
||||
if (!data->flag_encrypted) {
|
||||
if ((out = crypt(argv[0], "$1")) != NULL)
|
||||
data->password = xstrdup(out);
|
||||
} else
|
||||
data->password = xstrdup(argv[0]);
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_set_password_data *data = self->data;
|
||||
|
||||
if (data->password == NULL) {
|
||||
ctx->error(ctx, "failed to encrypt password");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (server_password != NULL)
|
||||
xfree(server_password);
|
||||
if (*data->password == '\0')
|
||||
server_password = NULL;
|
||||
else
|
||||
server_password = xstrdup(data->password);
|
||||
log_debug("pw now %s", server_password);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_set_password_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_set_password_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->password);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_set_password_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_set_password_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->password = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_set_password_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_set_password_data *data = self->data;
|
||||
|
||||
if (data->password != NULL)
|
||||
xfree(data->password);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_set_password_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_set_password_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
if (off < len && data->flag_encrypted)
|
||||
off += xsnprintf(buf + off, len - off, " -c");
|
||||
if (off < len && data->password != NULL)
|
||||
off += xsnprintf(buf + off, len - off, " password");
|
||||
return (off);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-window-option.c,v 1.28 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-set-window-option.c,v 1.40 2009-10-09 13:07:04 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,15 +31,13 @@ int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_set_window_option_entry = {
|
||||
"set-window-option", "setw",
|
||||
CMD_OPTION_WINDOW_USAGE,
|
||||
CMD_GFLAG|CMD_UFLAG,
|
||||
"[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
CMD_ARG12, CMD_CHFLAG('a')|CMD_CHFLAG('g')|CMD_CHFLAG('u'),
|
||||
NULL,
|
||||
cmd_option_parse,
|
||||
cmd_target_parse,
|
||||
cmd_set_window_option_exec,
|
||||
cmd_option_send,
|
||||
cmd_option_recv,
|
||||
cmd_option_free,
|
||||
cmd_option_print
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
const char *set_option_mode_keys_list[] = {
|
||||
@@ -48,7 +46,7 @@ const char *set_option_mode_keys_list[] = {
|
||||
const char *set_option_clock_mode_style_list[] = {
|
||||
"12", "24", NULL
|
||||
};
|
||||
const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
|
||||
const struct set_option_entry set_window_option_table[] = {
|
||||
{ "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
@@ -56,71 +54,77 @@ const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
|
||||
SET_OPTION_CHOICE, 0, 0, set_option_clock_mode_style_list },
|
||||
{ "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "main-pane-height", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "main-pane-width", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||
{ "mode-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "mode-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "mode-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list },
|
||||
{ "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "monitor-content", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "window-status-current-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
|
||||
{ "window-status-current-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "window-status-current-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
|
||||
{ NULL, 0, 0, 0, NULL }
|
||||
};
|
||||
|
||||
int
|
||||
cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_option_data *data = self->data;
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct client *c;
|
||||
struct options *oo;
|
||||
const struct set_option_entry *entry;
|
||||
const struct set_option_entry *entry, *opt;
|
||||
u_int i;
|
||||
|
||||
if (data->flags & CMD_GFLAG)
|
||||
oo = &global_window_options;
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
oo = &global_w_options;
|
||||
else {
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
oo = &wl->window->options;
|
||||
}
|
||||
|
||||
if (*data->option == '\0') {
|
||||
if (*data->arg == '\0') {
|
||||
ctx->error(ctx, "invalid option");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
entry = NULL;
|
||||
for (i = 0; i < NSETWINDOWOPTION; i++) {
|
||||
if (strncmp(set_window_option_table[i].name,
|
||||
data->option, strlen(data->option)) != 0)
|
||||
for (opt = set_window_option_table; opt->name != NULL; opt++) {
|
||||
if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
|
||||
continue;
|
||||
if (entry != NULL) {
|
||||
ctx->error(ctx, "ambiguous option: %s", data->option);
|
||||
ctx->error(ctx, "ambiguous option: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
entry = &set_window_option_table[i];
|
||||
entry = opt;
|
||||
|
||||
/* Bail now if an exact match. */
|
||||
if (strcmp(entry->name, data->option) == 0)
|
||||
if (strcmp(entry->name, data->arg) == 0)
|
||||
break;
|
||||
}
|
||||
if (entry == NULL) {
|
||||
ctx->error(ctx, "unknown option: %s", data->option);
|
||||
ctx->error(ctx, "unknown option: %s", data->arg);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (data->flags & CMD_UFLAG) {
|
||||
if (data->flags & CMD_GFLAG) {
|
||||
if (data->chflags & CMD_CHFLAG('u')) {
|
||||
if (data->chflags & CMD_CHFLAG('g')) {
|
||||
ctx->error(ctx,
|
||||
"can't unset global option: %s", entry->name);
|
||||
return (-1);
|
||||
}
|
||||
if (data->value != NULL) {
|
||||
if (data->arg2 != NULL) {
|
||||
ctx->error(ctx,
|
||||
"value passed to unset option: %s", entry->name);
|
||||
return (-1);
|
||||
@@ -131,25 +135,26 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
} else {
|
||||
switch (entry->type) {
|
||||
case SET_OPTION_STRING:
|
||||
set_option_string(ctx, oo, entry, data->value);
|
||||
set_option_string(ctx, oo, entry,
|
||||
data->arg2, data->chflags & CMD_CHFLAG('a'));
|
||||
break;
|
||||
case SET_OPTION_NUMBER:
|
||||
set_option_number(ctx, oo, entry, data->value);
|
||||
set_option_number(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
set_option_key(ctx, oo, entry, data->value);
|
||||
case SET_OPTION_KEYS:
|
||||
set_option_keys(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_COLOUR:
|
||||
set_option_colour(ctx, oo, entry, data->value);
|
||||
set_option_colour(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_ATTRIBUTES:
|
||||
set_option_attributes(ctx, oo, entry, data->value);
|
||||
set_option_attributes(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
set_option_flag(ctx, oo, entry, data->value);
|
||||
set_option_flag(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
set_option_choice(ctx, oo, entry, data->value);
|
||||
set_option_choice(ctx, oo, entry, data->arg2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-show-buffer.c,v 1.4 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-show-buffer.c,v 1.10 2009-09-07 23:48:54 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -31,12 +29,10 @@ int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_show_buffer_entry = {
|
||||
"show-buffer", "showb",
|
||||
CMD_BUFFER_SESSION_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_buffer_init,
|
||||
cmd_buffer_parse,
|
||||
cmd_show_buffer_exec,
|
||||
cmd_buffer_send,
|
||||
cmd_buffer_recv,
|
||||
cmd_buffer_free,
|
||||
cmd_buffer_print
|
||||
};
|
||||
@@ -47,9 +43,9 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_buffer_data *data = self->data;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
u_int size;
|
||||
char *buf, *ptr;
|
||||
size_t len;
|
||||
char *in, *buf, *ptr;
|
||||
size_t size, len;
|
||||
u_int width;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
@@ -63,27 +59,43 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||
return (-1);
|
||||
}
|
||||
if (pb == NULL)
|
||||
return (0);
|
||||
|
||||
if (pb != NULL) {
|
||||
size = s->sx;
|
||||
size = pb->size;
|
||||
if (size > SIZE_MAX / 4 - 1)
|
||||
size = SIZE_MAX / 4 - 1;
|
||||
in = xmalloc(size * 4 + 1);
|
||||
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
|
||||
|
||||
buf = xmalloc(size + 1);
|
||||
len = 0;
|
||||
width = s->sx;
|
||||
if (ctx->cmdclient != NULL)
|
||||
width = ctx->cmdclient->tty.sx;
|
||||
|
||||
buf = xmalloc(width + 1);
|
||||
len = 0;
|
||||
|
||||
ptr = in;
|
||||
do {
|
||||
buf[len++] = *ptr++;
|
||||
|
||||
if (len == width || buf[len - 1] == '\n') {
|
||||
if (buf[len - 1] == '\n')
|
||||
len--;
|
||||
buf[len] = '\0';
|
||||
|
||||
ptr = pb->data;
|
||||
do {
|
||||
buf[len++] = *ptr++;
|
||||
|
||||
if (len == size) {
|
||||
buf[len] = '\0';
|
||||
ctx->print(ctx, buf);
|
||||
|
||||
len = 0;
|
||||
}
|
||||
} while (*ptr != '\0');
|
||||
ctx->print(ctx, "%s", buf);
|
||||
len = 0;
|
||||
}
|
||||
} while (*ptr != '\0');
|
||||
|
||||
if (len != 0) {
|
||||
buf[len] = '\0';
|
||||
ctx->print(ctx, buf);
|
||||
ctx->print(ctx, "%s", buf);
|
||||
}
|
||||
xfree(buf);
|
||||
|
||||
xfree(in);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
67
cmd-show-environment.c
Normal file
67
cmd-show-environment.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* $Id: cmd-show-environment.c,v 1.1 2009-08-09 17:48:55 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Show environment.
|
||||
*/
|
||||
|
||||
int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_show_environment_entry = {
|
||||
"show-environment", "showenv",
|
||||
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||
0, CMD_CHFLAG('g'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_show_environment_exec,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
int
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct environ *env;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
env = &global_environ;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
env = &s->environ;
|
||||
}
|
||||
|
||||
RB_FOREACH(envent, environ, env) {
|
||||
if (envent->value != NULL)
|
||||
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||
else
|
||||
ctx->print(ctx, "-%s", envent->name);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-show-options.c,v 1.11 2009-01-27 20:22:33 nicm Exp $ */
|
||||
/* $Id: cmd-show-options.c,v 1.17 2009-09-22 13:56:02 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,12 +32,10 @@ int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_show_options_entry = {
|
||||
"show-options", "show",
|
||||
"[-g] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_GFLAG,
|
||||
0, CMD_CHFLAG('g'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_show_options_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,62 +46,23 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct session *s;
|
||||
struct options *oo;
|
||||
struct options_entry *o;
|
||||
const struct set_option_entry *entry;
|
||||
u_int i;
|
||||
char *vs;
|
||||
long long vn;
|
||||
const char *optval;
|
||||
|
||||
if (data->flags & CMD_GFLAG)
|
||||
oo = &global_options;
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
oo = &global_s_options;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
oo = &s->options;
|
||||
}
|
||||
|
||||
for (i = 0; i < NSETOPTION; i++) {
|
||||
entry = &set_option_table[i];
|
||||
|
||||
if (options_find1(oo, entry->name) == NULL)
|
||||
for (entry = set_option_table; entry->name != NULL; entry++) {
|
||||
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||
continue;
|
||||
|
||||
switch (entry->type) {
|
||||
case SET_OPTION_STRING:
|
||||
vs = options_get_string(oo, entry->name);
|
||||
ctx->print(ctx, "%s \"%s\"", entry->name, vs);
|
||||
break;
|
||||
case SET_OPTION_NUMBER:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %lld", entry->name, vn);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, key_string_lookup_key(vn));
|
||||
break;
|
||||
case SET_OPTION_COLOUR:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, colour_tostring(vn));
|
||||
break;
|
||||
case SET_OPTION_ATTRIBUTES:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, attributes_tostring(vn));
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
if (vn)
|
||||
ctx->print(ctx, "%s on", entry->name);
|
||||
else
|
||||
ctx->print(ctx, "%s off", entry->name);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, entry->choices[vn]);
|
||||
break;
|
||||
}
|
||||
optval = set_option_print(entry, o);
|
||||
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-show-window-options.c,v 1.7 2009-01-27 20:22:33 nicm Exp $ */
|
||||
/* $Id: cmd-show-window-options.c,v 1.13 2009-09-22 13:56:02 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -32,12 +32,10 @@ int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_show_window_options_entry = {
|
||||
"show-window-options", "showw",
|
||||
"[-g] " CMD_TARGET_WINDOW_USAGE,
|
||||
CMD_GFLAG,
|
||||
0, CMD_CHFLAG('g'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_show_window_options_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -48,62 +46,23 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct options *oo;
|
||||
struct options_entry *o;
|
||||
const struct set_option_entry *entry;
|
||||
u_int i;
|
||||
char *vs;
|
||||
long long vn;
|
||||
const char *optval;
|
||||
|
||||
if (data->flags & CMD_GFLAG)
|
||||
oo = &global_window_options;
|
||||
if (data->chflags & CMD_CHFLAG('g'))
|
||||
oo = &global_w_options;
|
||||
else {
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
return (-1);
|
||||
oo = &wl->window->options;
|
||||
}
|
||||
|
||||
for (i = 0; i < NSETWINDOWOPTION; i++) {
|
||||
entry = &set_window_option_table[i];
|
||||
|
||||
if (options_find1(oo, entry->name) == NULL)
|
||||
for (entry = set_window_option_table; entry->name != NULL; entry++) {
|
||||
if ((o = options_find1(oo, entry->name)) == NULL)
|
||||
continue;
|
||||
|
||||
switch (entry->type) {
|
||||
case SET_OPTION_STRING:
|
||||
vs = options_get_string(oo, entry->name);
|
||||
ctx->print(ctx, "%s \"%s\"", entry->name, vs);
|
||||
break;
|
||||
case SET_OPTION_NUMBER:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %lld", entry->name, vn);
|
||||
break;
|
||||
case SET_OPTION_KEY:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, key_string_lookup_key(vn));
|
||||
break;
|
||||
case SET_OPTION_COLOUR:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, colour_tostring(vn));
|
||||
break;
|
||||
case SET_OPTION_ATTRIBUTES:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, attributes_tostring(vn));
|
||||
break;
|
||||
case SET_OPTION_FLAG:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
if (vn)
|
||||
ctx->print(ctx, "%s on", entry->name);
|
||||
else
|
||||
ctx->print(ctx, "%s off", entry->name);
|
||||
break;
|
||||
case SET_OPTION_CHOICE:
|
||||
vn = options_get_number(oo, entry->name);
|
||||
ctx->print(ctx, "%s %s",
|
||||
entry->name, entry->choices[vn]);
|
||||
break;
|
||||
}
|
||||
optval = set_option_print(entry, o);
|
||||
ctx->print(ctx, "%s %s", entry->name, optval);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-source-file.c,v 1.5 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-source-file.c,v 1.9 2009-09-22 14:06:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
|
||||
@@ -26,8 +26,6 @@
|
||||
|
||||
int cmd_source_file_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_source_file_send(struct cmd *, struct buffer *);
|
||||
void cmd_source_file_recv(struct cmd *, struct buffer *);
|
||||
void cmd_source_file_free(struct cmd *);
|
||||
void cmd_source_file_init(struct cmd *, int);
|
||||
size_t cmd_source_file_print(struct cmd *, char *, size_t);
|
||||
@@ -39,12 +37,10 @@ struct cmd_source_file_data {
|
||||
const struct cmd_entry cmd_source_file_entry = {
|
||||
"source-file", "source",
|
||||
"path",
|
||||
0,
|
||||
0, 0,
|
||||
cmd_source_file_init,
|
||||
cmd_source_file_parse,
|
||||
cmd_source_file_exec,
|
||||
cmd_source_file_send,
|
||||
cmd_source_file_recv,
|
||||
cmd_source_file_free,
|
||||
cmd_source_file_print
|
||||
};
|
||||
@@ -64,7 +60,7 @@ cmd_source_file_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
struct cmd_source_file_data *data;
|
||||
int opt;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||
@@ -94,7 +90,7 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct cmd_source_file_data *data = self->data;
|
||||
char *cause;
|
||||
|
||||
if (load_cfg(data->path, &cause) != 0) {
|
||||
if (load_cfg(data->path, ctx, &cause) != 0) {
|
||||
ctx->error(ctx, "%s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
@@ -103,25 +99,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_source_file_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->path);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_source_file_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->path = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_free(struct cmd *self)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-split-window.c,v 1.15 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-split-window.c,v 1.28 2009-09-22 14:06:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
int cmd_split_window_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_split_window_send(struct cmd *, struct buffer *);
|
||||
void cmd_split_window_recv(struct cmd *, struct buffer *);
|
||||
void cmd_split_window_free(struct cmd *);
|
||||
void cmd_split_window_init(struct cmd *, int);
|
||||
size_t cmd_split_window_print(struct cmd *, char *, size_t);
|
||||
@@ -39,25 +37,24 @@ struct cmd_split_window_data {
|
||||
char *target;
|
||||
char *cmd;
|
||||
int flag_detached;
|
||||
int flag_horizontal;
|
||||
int percentage;
|
||||
int lines;
|
||||
int size;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_split_window_entry = {
|
||||
"split-window", "splitw",
|
||||
"[-d] [-p percentage|-l lines] [-t target-window] [command]",
|
||||
0,
|
||||
"[-dhv] [-p percentage|-l size] [-t target-window] [command]",
|
||||
0, 0,
|
||||
cmd_split_window_init,
|
||||
cmd_split_window_parse,
|
||||
cmd_split_window_exec,
|
||||
cmd_split_window_send,
|
||||
cmd_split_window_recv,
|
||||
cmd_split_window_free,
|
||||
cmd_split_window_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_split_window_init(struct cmd *self, unused int arg)
|
||||
cmd_split_window_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_split_window_data *data;
|
||||
|
||||
@@ -65,50 +62,63 @@ cmd_split_window_init(struct cmd *self, unused int arg)
|
||||
data->target = NULL;
|
||||
data->cmd = NULL;
|
||||
data->flag_detached = 0;
|
||||
data->flag_horizontal = 0;
|
||||
data->percentage = -1;
|
||||
data->lines = -1;
|
||||
data->size = -1;
|
||||
|
||||
switch (key) {
|
||||
case '%':
|
||||
data->flag_horizontal = 1;
|
||||
break;
|
||||
case '"':
|
||||
data->flag_horizontal = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_split_window_data *data;
|
||||
int opt, n;
|
||||
int opt;
|
||||
const char *errstr;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
self->entry->init(self, KEYC_NONE);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dl:p:t:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "dhl:p:t:v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
data->flag_detached = 1;
|
||||
break;
|
||||
case 'h':
|
||||
data->flag_horizontal = 1;
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
if (data->percentage == -1 && data->lines == -1) {
|
||||
n = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "lines %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->lines = n;
|
||||
if (data->percentage != -1 || data->size != -1)
|
||||
break;
|
||||
data->size = strtonum(optarg, 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "size %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (data->lines == -1 && data->percentage == -1) {
|
||||
n = strtonum(optarg, 1, 100, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(
|
||||
cause, "percentage %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->percentage = n;
|
||||
if (data->size != -1 || data->percentage != -1)
|
||||
break;
|
||||
data->percentage = strtonum(optarg, 1, 100, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "percentage %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
data->flag_horizontal = 0;
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
@@ -139,38 +149,53 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
const char **env;
|
||||
struct environ env;
|
||||
char *cmd, *cwd, *cause;
|
||||
const char *shell;
|
||||
u_int hlimit;
|
||||
int lines;
|
||||
int size;
|
||||
enum layout_type type;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
env = server_fill_environ(s);
|
||||
environ_init(&env);
|
||||
environ_copy(&global_environ, &env);
|
||||
environ_copy(&s->environ, &env);
|
||||
server_fill_environ(s, &env);
|
||||
|
||||
cmd = data->cmd;
|
||||
if (cmd == NULL)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
if (ctx->cmdclient == NULL || ctx->cmdclient->cwd == NULL)
|
||||
cwd = options_get_string(&global_options, "default-path");
|
||||
cwd = options_get_string(&s->options, "default-path");
|
||||
else
|
||||
cwd = ctx->cmdclient->cwd;
|
||||
|
||||
lines = -1;
|
||||
if (data->lines != -1)
|
||||
lines = data->lines;
|
||||
size = -1;
|
||||
if (data->size != -1)
|
||||
size = data->size;
|
||||
else if (data->percentage != -1)
|
||||
lines = (w->active->sy * data->percentage) / 100;
|
||||
|
||||
size = (w->active->sy * data->percentage) / 100;
|
||||
hlimit = options_get_number(&s->options, "history-limit");
|
||||
wp = window_add_pane(w, lines, cmd, cwd, env, hlimit, &cause);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "create pane failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (data->flag_horizontal)
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
|
||||
shell = options_get_string(&s->options, "default-shell");
|
||||
if (*shell == '\0' || areshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
wp = window_add_pane(w, hlimit);
|
||||
if (window_pane_spawn(wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
|
||||
goto error;
|
||||
if (layout_split_pane(w->active, type, size, wp) != 0) {
|
||||
cause = xstrdup("pane too small");
|
||||
goto error;
|
||||
}
|
||||
|
||||
server_redraw_window(w);
|
||||
|
||||
if (!data->flag_detached) {
|
||||
@@ -179,30 +204,17 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
server_redraw_session(s);
|
||||
} else
|
||||
server_status_session(s);
|
||||
layout_refresh(w, 0);
|
||||
|
||||
environ_free(&env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_split_window_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_split_window_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
cmd_send_string(b, data->cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_split_window_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_split_window_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
data->cmd = cmd_recv_string(b);
|
||||
error:
|
||||
environ_free(&env);
|
||||
if (wp != NULL)
|
||||
window_remove_pane(w, wp);
|
||||
ctx->error(ctx, "create pane failed: %s", cause);
|
||||
xfree(cause);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -228,6 +240,14 @@ cmd_split_window_print(struct cmd *self, char *buf, size_t len)
|
||||
return (off);
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, " -d");
|
||||
if (off < len && data->flag_horizontal)
|
||||
off += xsnprintf(buf + off, len - off, " -h");
|
||||
if (off < len && data->size > 0)
|
||||
off += xsnprintf(buf + off, len - off, " -l %d", data->size);
|
||||
if (off < len && data->percentage > 0) {
|
||||
off += xsnprintf(
|
||||
buf + off, len - off, " -p %d", data->percentage);
|
||||
}
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->cmd != NULL)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-start-server.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-start-server.c,v 1.8 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,13 +29,11 @@ int cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_start_server_entry = {
|
||||
"start-server", "start",
|
||||
"",
|
||||
CMD_STARTSERVER,
|
||||
CMD_STARTSERVER, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_start_server_exec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
117
cmd-string.c
117
cmd-string.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-string.c,v 1.17 2009-06-25 16:21:32 nicm Exp $ */
|
||||
/* $Id: cmd-string.c,v 1.24 2009-10-28 23:12:38 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -19,9 +19,11 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -33,6 +35,7 @@ int cmd_string_getc(const char *, size_t *);
|
||||
void cmd_string_ungetc(const char *, size_t *);
|
||||
char *cmd_string_string(const char *, size_t *, char, int);
|
||||
char *cmd_string_variable(const char *, size_t *);
|
||||
char *cmd_string_expand_tilde(const char *, size_t *);
|
||||
|
||||
int
|
||||
cmd_string_getc(const char *s, size_t *p)
|
||||
@@ -56,21 +59,11 @@ int
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
{
|
||||
size_t p;
|
||||
int ch, argc, rval, have_arg;
|
||||
char **argv, *buf, *t, *u;
|
||||
int ch, i, argc, rval, have_arg;
|
||||
char **argv, *buf, *t;
|
||||
const char *whitespace, *equals;
|
||||
size_t len;
|
||||
|
||||
if ((t = strchr(s, ' ')) == NULL && (t = strchr(s, '\t')) == NULL)
|
||||
t = strchr(s, '\0');
|
||||
if ((u = strchr(s, '=')) != NULL && u < t) {
|
||||
if (putenv(xstrdup(s)) != 0) {
|
||||
xasprintf(cause, "assignment failed: %s", s);
|
||||
return (-1);
|
||||
}
|
||||
*cmdlist = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
argv = NULL;
|
||||
argc = 0;
|
||||
|
||||
@@ -114,6 +107,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
xfree(t);
|
||||
|
||||
have_arg = 1;
|
||||
break;
|
||||
@@ -143,6 +137,18 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
equals = strchr(argv[i], '=');
|
||||
whitespace = argv[i] + strcspn(argv[i], " \t");
|
||||
if (equals == NULL || equals > whitespace)
|
||||
break;
|
||||
environ_put(&global_environ, argv[i]);
|
||||
memmove(&argv[i], &argv[i + 1], argc - i - 1);
|
||||
argc--;
|
||||
}
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
*cmdlist = cmd_list_parse(argc, argv, cause);
|
||||
if (*cmdlist == NULL)
|
||||
goto out;
|
||||
@@ -153,6 +159,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
|
||||
rval = 0;
|
||||
goto out;
|
||||
case '~':
|
||||
if (have_arg == 0) {
|
||||
if ((t = cmd_string_expand_tilde(s, &p)) == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
xfree(t);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
if (len >= SIZE_MAX - 2)
|
||||
goto error;
|
||||
@@ -187,30 +204,33 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
char *buf, *t;
|
||||
size_t len;
|
||||
|
||||
buf = NULL;
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
|
||||
while ((ch = cmd_string_getc(s, p)) != endch) {
|
||||
switch (ch) {
|
||||
while ((ch = cmd_string_getc(s, p)) != endch) {
|
||||
switch (ch) {
|
||||
case EOF:
|
||||
goto error;
|
||||
case '\\':
|
||||
case '\\':
|
||||
if (!esc)
|
||||
break;
|
||||
switch (ch = cmd_string_getc(s, p)) {
|
||||
switch (ch = cmd_string_getc(s, p)) {
|
||||
case EOF:
|
||||
goto error;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
ch = '\033';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
if (!esc)
|
||||
break;
|
||||
@@ -219,14 +239,15 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
xfree(t);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (len >= SIZE_MAX - 2)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + 1);
|
||||
buf[len++] = ch;
|
||||
}
|
||||
buf[len++] = ch;
|
||||
}
|
||||
|
||||
buf = xrealloc(buf, 1, len + 1);
|
||||
buf[len] = '\0';
|
||||
@@ -251,7 +272,7 @@ cmd_string_variable(const char *s, size_t *p)
|
||||
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z') || \
|
||||
((ch) >= '0' && (ch) <= '9'))
|
||||
|
||||
buf = NULL;
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
|
||||
fch = EOF;
|
||||
@@ -307,3 +328,31 @@ error:
|
||||
xfree(buf);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
{
|
||||
struct passwd *pw;
|
||||
char *home, *path, *username;
|
||||
|
||||
home = NULL;
|
||||
if (cmd_string_getc(s, p) == '/') {
|
||||
if ((home = getenv("HOME")) == NULL) {
|
||||
if ((pw = getpwuid(getuid())) != NULL)
|
||||
home = pw->pw_dir;
|
||||
}
|
||||
} else {
|
||||
cmd_string_ungetc(s, p);
|
||||
if ((username = cmd_string_string(s, p, '/', 0)) == NULL)
|
||||
return (NULL);
|
||||
if ((pw = getpwnam(username)) != NULL)
|
||||
home = pw->pw_dir;
|
||||
if (username != NULL)
|
||||
xfree(username);
|
||||
}
|
||||
if (home == NULL)
|
||||
return (NULL);
|
||||
|
||||
xasprintf(&path, "%s/", home);
|
||||
return (path);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-suspend-client.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-suspend-client.c,v 1.4 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -37,12 +37,10 @@ struct cmd_suspend_client_data {
|
||||
const struct cmd_entry cmd_suspend_client_entry = {
|
||||
"suspend-client", "suspendc",
|
||||
"[-c target-client]",
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_suspend_client_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
|
||||
295
cmd-swap-pane.c
295
cmd-swap-pane.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-swap-pane.c,v 1.6 2009-06-25 15:28:08 nicm Exp $ */
|
||||
/* $Id: cmd-swap-pane.c,v 1.13 2009-07-30 21:04:40 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -26,269 +26,118 @@
|
||||
* Swap two panes.
|
||||
*/
|
||||
|
||||
int cmd_swap_pane_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_swap_pane_send(struct cmd *, struct buffer *);
|
||||
void cmd_swap_pane_recv(struct cmd *, struct buffer *);
|
||||
void cmd_swap_pane_free(struct cmd *);
|
||||
void cmd_swap_pane_init(struct cmd *, int);
|
||||
size_t cmd_swap_pane_print(struct cmd *, char *, size_t);
|
||||
|
||||
struct cmd_swap_pane_data {
|
||||
char *target;
|
||||
int src;
|
||||
int dst;
|
||||
int flag_detached;
|
||||
int flag_up;
|
||||
int flag_down;
|
||||
};
|
||||
int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_swap_pane_entry = {
|
||||
"swap-pane", "swapp",
|
||||
"[-dDU] [-t target-window] [-p src-index] [-q dst-index]",
|
||||
0,
|
||||
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
||||
0, CMD_CHFLAG('d')|CMD_CHFLAG('D')|CMD_CHFLAG('U'),
|
||||
cmd_swap_pane_init,
|
||||
cmd_swap_pane_parse,
|
||||
cmd_srcdst_parse,
|
||||
cmd_swap_pane_exec,
|
||||
cmd_swap_pane_send,
|
||||
cmd_swap_pane_recv,
|
||||
cmd_swap_pane_free,
|
||||
cmd_swap_pane_print
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
|
||||
void
|
||||
cmd_swap_pane_init(struct cmd *self, int key)
|
||||
{
|
||||
struct cmd_swap_pane_data *data;
|
||||
struct cmd_target_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->target = NULL;
|
||||
data->src = -1;
|
||||
data->dst = -1;
|
||||
data->flag_detached = 0;
|
||||
data->flag_up = 0;
|
||||
data->flag_down = 0;
|
||||
|
||||
switch (key) {
|
||||
case '{':
|
||||
data->flag_up = 1;
|
||||
break;
|
||||
case '}':
|
||||
data->flag_down = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
cmd_swap_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_swap_pane_data *data;
|
||||
int opt, n;
|
||||
const char *errstr;
|
||||
|
||||
self->entry->init(self, 0);
|
||||
cmd_srcdst_init(self, key);
|
||||
data = self->data;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dDt:p:q:U")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
data->flag_detached = 1;
|
||||
break;
|
||||
case 'D':
|
||||
data->flag_up = 0;
|
||||
data->flag_down = 1;
|
||||
data->dst = -1;
|
||||
break;
|
||||
case 't':
|
||||
if (data->target == NULL)
|
||||
data->target = xstrdup(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
if (data->src == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "src %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->src = n;
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
if (data->dst == -1) {
|
||||
n = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
xasprintf(cause, "dst %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
data->dst = n;
|
||||
}
|
||||
data->flag_up = 0;
|
||||
data->flag_down = 0;
|
||||
break;
|
||||
case 'U':
|
||||
data->flag_up = 1;
|
||||
data->flag_down = 0;
|
||||
data->dst = -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0)
|
||||
goto usage;
|
||||
|
||||
return (0);
|
||||
|
||||
usage:
|
||||
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
|
||||
|
||||
error:
|
||||
self->entry->free(self);
|
||||
return (-1);
|
||||
if (key == '{')
|
||||
data->chflags |= CMD_CHFLAG('U');
|
||||
else if (key == '}')
|
||||
data->chflags |= CMD_CHFLAG('D');
|
||||
}
|
||||
|
||||
int
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_swap_pane_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||
u_int xx, yy;
|
||||
int flags;
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct winlink *src_wl, *dst_wl;
|
||||
struct window *src_w, *dst_w;
|
||||
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||
struct layout_cell *src_lc, *dst_lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
|
||||
if ((dst_wl = cmd_find_pane(ctx, data->dst, NULL, &dst_wp)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
dst_w = dst_wl->window;
|
||||
|
||||
if (data->src == -1)
|
||||
src_wp = w->active;
|
||||
else {
|
||||
src_wp = window_pane_at_index(w, data->src);
|
||||
if (src_wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->src);
|
||||
if (data->src == NULL) {
|
||||
src_w = dst_w;
|
||||
if (data->chflags & CMD_CHFLAG('D')) {
|
||||
src_wp = TAILQ_NEXT(dst_wp, entry);
|
||||
if (src_wp == NULL)
|
||||
src_wp = TAILQ_FIRST(&dst_w->panes);
|
||||
} else if (data->chflags & CMD_CHFLAG('U')) {
|
||||
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||
if (src_wp == NULL)
|
||||
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
||||
} else
|
||||
return (0);
|
||||
} else {
|
||||
src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp);
|
||||
if (src_wl == NULL)
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if (data->dst == -1)
|
||||
dst_wp = w->active;
|
||||
else {
|
||||
dst_wp = window_pane_at_index(w, data->dst);
|
||||
if (dst_wp == NULL) {
|
||||
ctx->error(ctx, "no pane: %d", data->dst);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->dst == -1 && data->flag_up) {
|
||||
if ((dst_wp = TAILQ_PREV(src_wp, window_panes, entry)) == NULL)
|
||||
dst_wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
}
|
||||
if (data->dst == -1 && data->flag_down) {
|
||||
if ((dst_wp = TAILQ_NEXT(src_wp, entry)) == NULL)
|
||||
dst_wp = TAILQ_FIRST(&w->panes);
|
||||
src_w = src_wl->window;
|
||||
}
|
||||
|
||||
if (src_wp == dst_wp)
|
||||
return (0);
|
||||
|
||||
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||
TAILQ_REMOVE(&w->panes, dst_wp, entry);
|
||||
TAILQ_REPLACE(&w->panes, src_wp, dst_wp, entry);
|
||||
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
|
||||
TAILQ_REPLACE(&src_w->panes, src_wp, dst_wp, entry);
|
||||
if (tmp_wp == src_wp)
|
||||
tmp_wp = dst_wp;
|
||||
if (tmp_wp == NULL)
|
||||
TAILQ_INSERT_HEAD(&w->panes, src_wp, entry);
|
||||
TAILQ_INSERT_HEAD(&dst_w->panes, src_wp, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(&w->panes, tmp_wp, src_wp, entry);
|
||||
TAILQ_INSERT_AFTER(&dst_w->panes, tmp_wp, src_wp, entry);
|
||||
|
||||
xx = src_wp->xoff;
|
||||
yy = src_wp->yoff;
|
||||
flags = src_wp->flags;
|
||||
src_wp->xoff = dst_wp->xoff;
|
||||
src_wp->yoff = dst_wp->yoff;
|
||||
src_wp->flags &= ~PANE_HIDDEN;
|
||||
src_wp->flags |= dst_wp->flags & PANE_HIDDEN;
|
||||
dst_wp->xoff = xx;
|
||||
dst_wp->yoff = yy;
|
||||
dst_wp->flags &= ~PANE_HIDDEN;
|
||||
dst_wp->flags |= flags & PANE_HIDDEN;
|
||||
src_lc = src_wp->layout_cell;
|
||||
dst_lc = dst_wp->layout_cell;
|
||||
src_lc->wp = dst_wp;
|
||||
dst_wp->layout_cell = src_lc;
|
||||
dst_lc->wp = src_wp;
|
||||
src_wp->layout_cell = dst_lc;
|
||||
|
||||
src_wp->window = dst_w;
|
||||
dst_wp->window = src_w;
|
||||
|
||||
xx = src_wp->sx;
|
||||
yy = src_wp->sy;
|
||||
sx = src_wp->sx; sy = src_wp->sy;
|
||||
xoff = src_wp->xoff; yoff = src_wp->yoff;
|
||||
src_wp->xoff = dst_wp->xoff; src_wp->yoff = dst_wp->yoff;
|
||||
window_pane_resize(src_wp, dst_wp->sx, dst_wp->sy);
|
||||
window_pane_resize(dst_wp, xx, yy);
|
||||
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
|
||||
window_pane_resize(dst_wp, sx, sy);
|
||||
|
||||
if (!data->flag_detached) {
|
||||
tmp_wp = dst_wp;
|
||||
if (tmp_wp->flags & PANE_HIDDEN)
|
||||
tmp_wp = src_wp;
|
||||
window_set_active_pane(w, tmp_wp);
|
||||
layout_refresh(w, 0);
|
||||
if (!(data->chflags & CMD_CHFLAG('d'))) {
|
||||
if (src_w != dst_w) {
|
||||
window_set_active_pane(src_w, dst_wp);
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
} else {
|
||||
tmp_wp = dst_wp;
|
||||
if (!window_pane_visible(tmp_wp))
|
||||
tmp_wp = src_wp;
|
||||
window_set_active_pane(src_w, tmp_wp);
|
||||
}
|
||||
} else {
|
||||
if (src_w->active == src_wp)
|
||||
window_set_active_pane(src_w, dst_wp);
|
||||
if (dst_w->active == dst_wp)
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
}
|
||||
server_redraw_window(src_w);
|
||||
server_redraw_window(dst_w);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_swap_pane_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_swap_pane_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->target);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_swap_pane_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_swap_pane_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->target = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_swap_pane_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_swap_pane_data *data = self->data;
|
||||
|
||||
if (data->target != NULL)
|
||||
xfree(data->target);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_swap_pane_print(struct cmd *self, char *buf, size_t len)
|
||||
{
|
||||
struct cmd_swap_pane_data *data = self->data;
|
||||
size_t off = 0;
|
||||
|
||||
off += xsnprintf(buf, len, "%s", self->entry->name);
|
||||
if (data == NULL)
|
||||
return (off);
|
||||
if (off < len &&
|
||||
(data->flag_down || data->flag_up || data->flag_detached)) {
|
||||
off += xsnprintf(buf + off, len - off, " -");
|
||||
if (off < len && data->flag_detached)
|
||||
off += xsnprintf(buf + off, len - off, "d");
|
||||
if (off < len && data->flag_up)
|
||||
off += xsnprintf(buf + off, len - off, "D");
|
||||
if (off < len && data->flag_down)
|
||||
off += xsnprintf(buf + off, len - off, "U");
|
||||
}
|
||||
if (off < len && data->target != NULL)
|
||||
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
|
||||
if (off < len && data->src != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -p %d", data->src);
|
||||
if (off < len && data->dst != -1)
|
||||
off += xsnprintf(buf + off, len - off, " -q %d", data->dst);
|
||||
return (off);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-swap-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-swap-window.c,v 1.18 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -31,12 +31,10 @@ int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_swap_window_entry = {
|
||||
"swap-window", "swapw",
|
||||
"[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||
CMD_DFLAG,
|
||||
0, CMD_CHFLAG('d'),
|
||||
cmd_srcdst_init,
|
||||
cmd_srcdst_parse,
|
||||
cmd_swap_window_exec,
|
||||
cmd_srcdst_send,
|
||||
cmd_srcdst_recv,
|
||||
cmd_srcdst_free,
|
||||
cmd_srcdst_print
|
||||
};
|
||||
@@ -46,6 +44,7 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_srcdst_data *data = self->data;
|
||||
struct session *src, *dst;
|
||||
struct session_group *sg_src, *sg_dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct window *w;
|
||||
|
||||
@@ -54,6 +53,14 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL)
|
||||
return (-1);
|
||||
|
||||
sg_src = session_group_find(src);
|
||||
sg_dst = session_group_find(dst);
|
||||
if (src != dst &&
|
||||
sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) {
|
||||
ctx->error(ctx, "can't move window, sessions are grouped");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (0);
|
||||
|
||||
@@ -61,14 +68,17 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
wl_dst->window = wl_src->window;
|
||||
wl_src->window = w;
|
||||
|
||||
if (!(data->flags & CMD_DFLAG)) {
|
||||
if (!(data->chflags & CMD_CHFLAG('d'))) {
|
||||
session_select(dst, wl_dst->idx);
|
||||
if (src != dst)
|
||||
session_select(src, wl_src->idx);
|
||||
}
|
||||
server_redraw_session(src);
|
||||
if (src != dst)
|
||||
server_redraw_session(dst);
|
||||
session_group_synchronize_from(src);
|
||||
server_redraw_session_group(src);
|
||||
if (src != dst) {
|
||||
session_group_synchronize_from(dst);
|
||||
server_redraw_session_group(dst);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-switch-client.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-switch-client.c,v 1.17 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
int cmd_switch_client_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_switch_client_send(struct cmd *, struct buffer *);
|
||||
void cmd_switch_client_recv(struct cmd *, struct buffer *);
|
||||
void cmd_switch_client_free(struct cmd *);
|
||||
size_t cmd_switch_client_print(struct cmd *, char *, size_t);
|
||||
|
||||
@@ -42,12 +40,10 @@ struct cmd_switch_client_data {
|
||||
const struct cmd_entry cmd_switch_client_entry = {
|
||||
"switch-client", "switchc",
|
||||
"[-c target-client] [-t target-session]",
|
||||
0,
|
||||
0, 0,
|
||||
NULL,
|
||||
cmd_switch_client_parse,
|
||||
cmd_switch_client_exec,
|
||||
cmd_switch_client_send,
|
||||
cmd_switch_client_recv,
|
||||
cmd_switch_client_free,
|
||||
cmd_switch_client_print
|
||||
};
|
||||
@@ -111,27 +107,6 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_switch_client_send(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_switch_client_data *data = self->data;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
cmd_send_string(b, data->name);
|
||||
cmd_send_string(b, data->target);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_switch_client_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_switch_client_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
data->name = cmd_recv_string(b);
|
||||
data->target = cmd_recv_string(b);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_switch_client_free(struct cmd *self)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-unbind-key.c,v 1.16 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-unbind-key.c,v 1.20 2009-07-28 23:19:06 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -26,23 +26,24 @@
|
||||
|
||||
int cmd_unbind_key_parse(struct cmd *, int, char **, char **);
|
||||
int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_unbind_key_send(struct cmd *, struct buffer *);
|
||||
void cmd_unbind_key_recv(struct cmd *, struct buffer *);
|
||||
void cmd_unbind_key_free(struct cmd *);
|
||||
|
||||
int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
struct cmd_unbind_key_data {
|
||||
int key;
|
||||
|
||||
int command_key;
|
||||
char *tablename;
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_unbind_key_entry = {
|
||||
"unbind-key", "unbind",
|
||||
"key",
|
||||
0,
|
||||
"[-cn] [-t key-table] key",
|
||||
0, 0,
|
||||
NULL,
|
||||
cmd_unbind_key_parse,
|
||||
cmd_unbind_key_exec,
|
||||
cmd_unbind_key_send,
|
||||
cmd_unbind_key_recv,
|
||||
cmd_unbind_key_free,
|
||||
NULL
|
||||
};
|
||||
@@ -51,12 +52,23 @@ int
|
||||
cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
{
|
||||
struct cmd_unbind_key_data *data;
|
||||
int opt;
|
||||
int opt, no_prefix = 0;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
data->command_key = 0;
|
||||
data->tablename = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "cnt:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
data->command_key = 1;
|
||||
break;
|
||||
case 'n':
|
||||
no_prefix = 1;
|
||||
break;
|
||||
case 't':
|
||||
data->tablename = xstrdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
@@ -70,6 +82,8 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
|
||||
xasprintf(cause, "unknown key: %s", argv[0]);
|
||||
goto error;
|
||||
}
|
||||
if (!no_prefix)
|
||||
data->key |= KEYC_PREFIX;
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -88,27 +102,33 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
|
||||
if (data == NULL)
|
||||
return (0);
|
||||
if (data->tablename != NULL)
|
||||
return (cmd_unbind_key_table(self, ctx));
|
||||
|
||||
key_bindings_remove(data->key);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_unbind_key_send(struct cmd *self, struct buffer *b)
|
||||
int
|
||||
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_unbind_key_data *data = self->data;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
|
||||
buffer_write(b, data, sizeof *data);
|
||||
}
|
||||
if ((mtab = mode_key_findtable(data->tablename)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", data->tablename);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_unbind_key_recv(struct cmd *self, struct buffer *b)
|
||||
{
|
||||
struct cmd_unbind_key_data *data;
|
||||
|
||||
self->data = data = xmalloc(sizeof *data);
|
||||
buffer_read(b, data, sizeof *data);
|
||||
mtmp.key = data->key & ~KEYC_PREFIX;
|
||||
mtmp.mode = data->command_key ? 1 : 0;
|
||||
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||
SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||
xfree(mbind);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -116,5 +136,7 @@ cmd_unbind_key_free(struct cmd *self)
|
||||
{
|
||||
struct cmd_unbind_key_data *data = self->data;
|
||||
|
||||
if (data->tablename != NULL)
|
||||
xfree(data->tablename);
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-unlink-window.c,v 1.13 2009-01-19 18:23:40 nicm Exp $ */
|
||||
/* $Id: cmd-unlink-window.c,v 1.19 2009-10-11 23:38:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -28,13 +28,11 @@ int cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_unlink_window_entry = {
|
||||
"unlink-window", "unlinkw",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
"[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||
0, CMD_CHFLAG('k'),
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_unlink_window_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -44,30 +42,29 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct cmd_target_data *data = self->data;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int destroyed;
|
||||
struct window *w;
|
||||
struct session *s, *s2;
|
||||
struct session_group *sg;
|
||||
u_int references;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||
return (-1);
|
||||
w = wl->window;
|
||||
|
||||
if (wl->window->references == 1) {
|
||||
sg = session_group_find(s);
|
||||
if (sg != NULL) {
|
||||
references = 0;
|
||||
TAILQ_FOREACH(s2, &sg->sessions, gentry)
|
||||
references++;
|
||||
} else
|
||||
references = 1;
|
||||
|
||||
if (!(data->chflags & CMD_CHFLAG('k')) && w->references == references) {
|
||||
ctx->error(ctx, "window is only linked to one session");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
destroyed = session_detach(s, wl);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (destroyed) {
|
||||
c->session = NULL;
|
||||
server_write_client(c, MSG_EXIT, NULL, 0);
|
||||
} else
|
||||
server_redraw_client(c);
|
||||
}
|
||||
|
||||
server_unlink_window(s, wl);
|
||||
recalculate_sizes();
|
||||
|
||||
return (0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-up-pane.c,v 1.7 2009-04-01 21:10:08 nicm Exp $ */
|
||||
/* $Id: cmd-up-pane.c,v 1.12 2009-07-28 22:12:16 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -29,12 +29,10 @@ int cmd_up_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
const struct cmd_entry cmd_up_pane_entry = {
|
||||
"up-pane", "upp",
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
0, 0,
|
||||
cmd_target_init,
|
||||
cmd_target_parse,
|
||||
cmd_up_pane_exec,
|
||||
cmd_target_send,
|
||||
cmd_target_recv,
|
||||
cmd_target_free,
|
||||
cmd_target_print
|
||||
};
|
||||
@@ -54,8 +52,8 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
w->active = TAILQ_PREV(w->active, window_panes, entry);
|
||||
if (w->active == NULL)
|
||||
w->active = TAILQ_LAST(&w->panes, window_panes);
|
||||
layout_refresh(w, 1);
|
||||
} while (w->active->flags & PANE_HIDDEN);
|
||||
} while (!window_pane_visible(w->active));
|
||||
server_status_window(wl->window);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
45
colour.c
45
colour.c
@@ -1,4 +1,4 @@
|
||||
/* $Id: colour.c,v 1.6 2009-05-18 15:42:30 nicm Exp $ */
|
||||
/* $Id: colour.c,v 1.7 2009-09-11 14:13:52 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@@ -18,13 +18,42 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
const char *
|
||||
colour_tostring(u_char c)
|
||||
/*
|
||||
* Colour to string conversion functions. Bit 8 of the colour means it is one
|
||||
* of the 256 colour palette.
|
||||
*/
|
||||
|
||||
void
|
||||
colour_set_fg(struct grid_cell *gc, int c)
|
||||
{
|
||||
if (c & 0x100)
|
||||
gc->flags |= GRID_FLAG_FG256;
|
||||
gc->fg = c;
|
||||
}
|
||||
|
||||
void
|
||||
colour_set_bg(struct grid_cell *gc, int c)
|
||||
{
|
||||
if (c & 0x100)
|
||||
gc->flags |= GRID_FLAG_BG256;
|
||||
gc->bg = c;
|
||||
}
|
||||
|
||||
const char *
|
||||
colour_tostring(int c)
|
||||
{
|
||||
static char s[32];
|
||||
|
||||
if (c & 0x100) {
|
||||
xsnprintf(s, sizeof s, "colour%u", c & ~0x100);
|
||||
return (s);
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
return ("black");
|
||||
@@ -51,6 +80,16 @@ colour_tostring(u_char c)
|
||||
int
|
||||
colour_fromstring(const char *s)
|
||||
{
|
||||
const char *errstr;
|
||||
int n;
|
||||
|
||||
if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) {
|
||||
n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
return (n | 0x100);
|
||||
}
|
||||
|
||||
if (strcasecmp(s, "black") == 0 || (s[0] == '0' && s[1] == '\0'))
|
||||
return (0);
|
||||
if (strcasecmp(s, "red") == 0 || (s[0] == '1' && s[1] == '\0'))
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user