mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
622 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5d2de7ec0 | ||
|
|
ca1d78f523 | ||
|
|
6daf06b1ad | ||
|
|
69b7c496ac | ||
|
|
1e981f4c6d | ||
|
|
b3de4a3dec | ||
|
|
81db6bab91 | ||
|
|
f2e54e1e2f | ||
|
|
e9d32f901a | ||
|
|
f835be4bb2 | ||
|
|
bfb700cf41 | ||
|
|
d0accdba88 | ||
|
|
f58721a9e8 | ||
|
|
325396046a | ||
|
|
c52548f6fd | ||
|
|
8edbbb9865 | ||
|
|
73c125f248 | ||
|
|
1721056f35 | ||
|
|
6eef24c37a | ||
|
|
973de5a704 | ||
|
|
57332be8da | ||
|
|
44737b06db | ||
|
|
d50e47fc4a | ||
|
|
9f02feb9d0 | ||
|
|
72d1be5ddd | ||
|
|
1935eb5c1e | ||
|
|
62e0ed5d7e | ||
|
|
945339b443 | ||
|
|
c930fd5ff6 | ||
|
|
dda70d4ef1 | ||
|
|
7d3d996383 | ||
|
|
d23561f381 | ||
|
|
cbf9224c5f | ||
|
|
c965870585 | ||
|
|
9ee93b3ea3 | ||
|
|
df680d7257 | ||
|
|
d02c4bda3a | ||
|
|
938768ed3d | ||
|
|
3368b602a8 | ||
|
|
b185449d07 | ||
|
|
c2cac69a22 | ||
|
|
1a0d3cd5d3 | ||
|
|
adc1f21eae | ||
|
|
994cb872cf | ||
|
|
66829ee12e | ||
|
|
1751da76d5 | ||
|
|
ba014c1a60 | ||
|
|
886c282679 | ||
|
|
ccf39fcdc1 | ||
|
|
ee65bde130 | ||
|
|
b091790622 | ||
|
|
a352570e9f | ||
|
|
d459314517 | ||
|
|
1286c56188 | ||
|
|
40982a01fb | ||
|
|
7aeb4473ad | ||
|
|
72a4602b88 | ||
|
|
30275bc610 | ||
|
|
3e498cdb49 | ||
|
|
7624800ddc | ||
|
|
f0ed61f53c | ||
|
|
a6cd84869e | ||
|
|
7fa55b0419 | ||
|
|
bf35441608 | ||
|
|
f52eac6225 | ||
|
|
2c08a3a559 | ||
|
|
2eb6d6e31b | ||
|
|
334c28afe7 | ||
|
|
5944230c50 | ||
|
|
8bcdd8fc21 | ||
|
|
d518067be6 | ||
|
|
f703a30dfe | ||
|
|
1a0951959f | ||
|
|
b347a994fd | ||
|
|
6126fa0995 | ||
|
|
85df418728 | ||
|
|
558e5639d0 | ||
|
|
d8d746b4b8 | ||
|
|
570028e9c0 | ||
|
|
7c3e7d6535 | ||
|
|
5b065e93b3 | ||
|
|
d3f37566e2 | ||
|
|
b8b31ad53e | ||
|
|
7f479ffdce | ||
|
|
4901d9ddc8 | ||
|
|
ffba21a60c | ||
|
|
98b81e9834 | ||
|
|
17ec688ced | ||
|
|
0b77d17b35 | ||
|
|
d0566a474a | ||
|
|
99e3cbc526 | ||
|
|
b85de1ddb3 | ||
|
|
c1ccefc62d | ||
|
|
6ac7abe8f0 | ||
|
|
909e1c1a86 | ||
|
|
7936ce3874 | ||
|
|
b8b85fbb0c | ||
|
|
282c5f9644 | ||
|
|
165aa59760 | ||
|
|
10c38436aa | ||
|
|
a0404b6902 | ||
|
|
eb26dbd072 | ||
|
|
6c093010e0 | ||
|
|
d2160e3f83 | ||
|
|
b822d24b15 | ||
|
|
fc54bfe6b0 | ||
|
|
1a49ebaa9f | ||
|
|
e4dc1568ce | ||
|
|
1bd0851ee8 | ||
|
|
1b7c2dd056 | ||
|
|
d45c12b6c9 | ||
|
|
90ae7682ed | ||
|
|
e6af0ad23e | ||
|
|
34674bb180 | ||
|
|
784b711393 | ||
|
|
81a548bcc4 | ||
|
|
fd1750af49 | ||
|
|
2bf2f5d58e | ||
|
|
40811eb8d4 | ||
|
|
2756d12750 | ||
|
|
7839993fe7 | ||
|
|
47a4a9992c | ||
|
|
d75dd2ab1c | ||
|
|
6e665708fc | ||
|
|
d3830e622f | ||
|
|
0538676aa3 | ||
|
|
4c9f41f1ad | ||
|
|
e588ddb5d6 | ||
|
|
f3ec8693e3 | ||
|
|
e9b09faab2 | ||
|
|
5ea6148362 | ||
|
|
9e0d7bddc0 | ||
|
|
aa0a57fd56 | ||
|
|
d86c70af96 | ||
|
|
4538c269d0 | ||
|
|
446eb11cde | ||
|
|
fa1375c09f | ||
|
|
f141e9b37a | ||
|
|
3fba377ddd | ||
|
|
01a4752503 | ||
|
|
d66cbf20f7 | ||
|
|
7e4314eccb | ||
|
|
7c71c3e27d | ||
|
|
5eeee39cc1 | ||
|
|
796974ddf6 | ||
|
|
75f5b3dab6 | ||
|
|
9f330897a8 | ||
|
|
710eeb2a33 | ||
|
|
3493b7dac7 | ||
|
|
d51b4f92d7 | ||
|
|
3d8a8ea0c6 | ||
|
|
2057812c8f | ||
|
|
13360ad541 | ||
|
|
9389cfbec9 | ||
|
|
7be152412e | ||
|
|
d0fa48db1e | ||
|
|
884a21d0f5 | ||
|
|
21bca549d3 | ||
|
|
bda970b3b1 | ||
|
|
75ec17f0b5 | ||
|
|
d62121e7bb | ||
|
|
06d101657f | ||
|
|
2f7ffab0e8 | ||
|
|
3ed5e56a39 | ||
|
|
a0802dd486 | ||
|
|
f2675cdf04 | ||
|
|
e3864c383f | ||
|
|
25c0dc5e6e | ||
|
|
8954d01f96 | ||
|
|
b2fe9bff3f | ||
|
|
a36da3a878 | ||
|
|
c103f2fbcb | ||
|
|
aa4920fea3 | ||
|
|
5532766b19 | ||
|
|
5dbf3cb036 | ||
|
|
ddf929390e | ||
|
|
23519fc0b4 | ||
|
|
04288fcd4c | ||
|
|
84c22d053b | ||
|
|
7581762c8e | ||
|
|
7673732c0f | ||
|
|
2dfd3fbd71 | ||
|
|
3a13e066ba | ||
|
|
bcd9bcae2a | ||
|
|
939f796f08 | ||
|
|
27364345bf | ||
|
|
35c19ffc28 | ||
|
|
b0b5cad496 | ||
|
|
965edf8a5c | ||
|
|
1c271852fc | ||
|
|
7ea560261c | ||
|
|
304ea079d2 | ||
|
|
c190c73240 | ||
|
|
e8567098a4 | ||
|
|
a9ebb62d54 | ||
|
|
bdea2f9eda | ||
|
|
f5b041e394 | ||
|
|
e496a548d7 | ||
|
|
3d39b18e31 | ||
|
|
a96a8a1aab | ||
|
|
064124cc5f | ||
|
|
7af5fec038 | ||
|
|
f884fff869 | ||
|
|
c7a121cfc0 | ||
|
|
777be296ee | ||
|
|
a0172a6ae5 | ||
|
|
1099442c0a | ||
|
|
18989cd430 | ||
|
|
828145456c | ||
|
|
097a046e4a | ||
|
|
3977dba761 | ||
|
|
a41cd8d75b | ||
|
|
662d471215 | ||
|
|
06b5805479 | ||
|
|
d6debc21c7 | ||
|
|
ddb52a2b15 | ||
|
|
13441e8cb8 | ||
|
|
a97d5b8e60 | ||
|
|
399d7380a5 | ||
|
|
c231381aa3 | ||
|
|
c30d60f7ae | ||
|
|
9fb9f78e43 | ||
|
|
a0cf65db77 | ||
|
|
2ee9c4df12 | ||
|
|
e6c77e7afb | ||
|
|
76cb088d16 | ||
|
|
907ad00300 | ||
|
|
88a4da9747 | ||
|
|
25c430b1cd | ||
|
|
772d61f3ed | ||
|
|
5b1cf02f2e | ||
|
|
66f4c60a84 | ||
|
|
fce095665c | ||
|
|
2555ac58cc | ||
|
|
e323101ede | ||
|
|
ce52e45d44 | ||
|
|
4f3c31a6b6 | ||
|
|
70bc8ef845 | ||
|
|
cd60e57b6a | ||
|
|
3d2b7d5bce | ||
|
|
04f54ab38f | ||
|
|
46c7dbef0f | ||
|
|
11b90bc959 | ||
|
|
792e2856c9 | ||
|
|
d89b35e682 | ||
|
|
a46ccbd883 | ||
|
|
5dda1abc32 | ||
|
|
55640a31b3 | ||
|
|
88428cff3a | ||
|
|
c24b58e2ee | ||
|
|
9e537c808b | ||
|
|
2c4543b9e9 | ||
|
|
b58bca9a72 | ||
|
|
27dcf470dc | ||
|
|
caa8290510 | ||
|
|
7f9b225cc2 | ||
|
|
4ccb2e2c21 | ||
|
|
cbee283c26 | ||
|
|
9fcda95a6f | ||
|
|
7ada64d5f8 | ||
|
|
20f0d917be | ||
|
|
e312db1408 | ||
|
|
743bd1275f | ||
|
|
69c86379e3 | ||
|
|
46b3c1a025 | ||
|
|
3ea893464f | ||
|
|
738e789dbd | ||
|
|
66afcf5be0 | ||
|
|
4b0ed56e32 | ||
|
|
dc2af8347b | ||
|
|
64ea8829af | ||
|
|
629cfec8a3 | ||
|
|
7f63658709 | ||
|
|
5e4d9a3197 | ||
|
|
982354765b | ||
|
|
5fe0576dcb | ||
|
|
1b083aa0fd | ||
|
|
399a15b9fc | ||
|
|
dfac36b6c3 | ||
|
|
771d7db3a6 | ||
|
|
00af2df102 | ||
|
|
be390c1991 | ||
|
|
2fd0cb7600 | ||
|
|
5f5d413408 | ||
|
|
972da2d498 | ||
|
|
e44bd9f750 | ||
|
|
777edd0269 | ||
|
|
855d6fe1fe | ||
|
|
b625ad6d8b | ||
|
|
97b5df35b1 | ||
|
|
7a87c7eff6 | ||
|
|
f90eb43fcb | ||
|
|
a09d8e88fc | ||
|
|
b5fda7ad2a | ||
|
|
58bb6f8c56 | ||
|
|
673eb160d4 | ||
|
|
e97e0d7e54 | ||
|
|
4119c476aa | ||
|
|
e2295014d9 | ||
|
|
43fb9835fa | ||
|
|
599dd2a560 | ||
|
|
d28a39d01d | ||
|
|
270d90ce1e | ||
|
|
0c969a7dfd | ||
|
|
111d993e75 | ||
|
|
0ef24f9912 | ||
|
|
87fe1c0b0e | ||
|
|
114d822d27 | ||
|
|
88b92df849 | ||
|
|
e4c0730bf1 | ||
|
|
8a40e10d55 | ||
|
|
e0961dfdf4 | ||
|
|
446fb0cb9c | ||
|
|
6fee3e9e4b | ||
|
|
748acdc77c | ||
|
|
410a3abbef | ||
|
|
304336a591 | ||
|
|
35452b3e55 | ||
|
|
ebd9c615c8 | ||
|
|
e9cef8bf30 | ||
|
|
e85f764f23 | ||
|
|
e2e85650ac | ||
|
|
2c14a771a8 | ||
|
|
d39b1a87a5 | ||
|
|
62db3c8efe | ||
|
|
efa06643b0 | ||
|
|
14fad6a5cc | ||
|
|
c71844de63 | ||
|
|
a05b8c4143 | ||
|
|
20636d956d | ||
|
|
66edb3392b | ||
|
|
86adcd4b26 | ||
|
|
a60687f9ba | ||
|
|
bb8457b166 | ||
|
|
3eae71b5b2 | ||
|
|
8094e82287 | ||
|
|
1ec4354998 | ||
|
|
ac1fe83596 | ||
|
|
c7d1849e1c | ||
|
|
7f191c7951 | ||
|
|
702ab8bab0 | ||
|
|
eaaeb28cda | ||
|
|
295d86911e | ||
|
|
c519f9a84c | ||
|
|
2243cfbe75 | ||
|
|
d644e5143f | ||
|
|
58932295fc | ||
|
|
8478895eeb | ||
|
|
8a6fbfa148 | ||
|
|
a1722d5c2e | ||
|
|
0ff9275ad7 | ||
|
|
d1e6ce2672 | ||
|
|
0ccd84d2ef | ||
|
|
29613f2f31 | ||
|
|
8c545bbfa8 | ||
|
|
f19836550b | ||
|
|
79f5fe6f5b | ||
|
|
2f5fa4ee9d | ||
|
|
db66d85176 | ||
|
|
f0efa576e0 | ||
|
|
ad5df9bc2f | ||
|
|
22a2949bd2 | ||
|
|
67b4d5b609 | ||
|
|
ad760b3bf7 | ||
|
|
8d59b189cc | ||
|
|
306a3b8d80 | ||
|
|
041a911c43 | ||
|
|
10682b9e7e | ||
|
|
c5504af4a6 | ||
|
|
49ac5b5fe0 | ||
|
|
d4785fe798 | ||
|
|
3d24c75d0f | ||
|
|
78543cce30 | ||
|
|
55bf2ecc68 | ||
|
|
51ac2a3202 | ||
|
|
48291f0eeb | ||
|
|
d5139d1401 | ||
|
|
3665be7c44 | ||
|
|
801d64a16e | ||
|
|
dd46c95e23 | ||
|
|
4920306486 | ||
|
|
66414029a1 | ||
|
|
51d989f5df | ||
|
|
c982279950 | ||
|
|
0c0953f3bd | ||
|
|
69fe5ca567 | ||
|
|
63b4fd5cac | ||
|
|
dd76497ab0 | ||
|
|
9b7e18f166 | ||
|
|
180faf73af | ||
|
|
6ddb06d372 | ||
|
|
69d97f6d4b | ||
|
|
f5de847a0c | ||
|
|
6bdc947f6b | ||
|
|
919bde7cb1 | ||
|
|
3d974b7267 | ||
|
|
c5ad47ee7c | ||
|
|
4d38b6d1fa | ||
|
|
9e879b4aab | ||
|
|
99934bf998 | ||
|
|
8840f2d629 | ||
|
|
d32a546d6e | ||
|
|
8aa40ec1c7 | ||
|
|
543420ccd2 | ||
|
|
064022548b | ||
|
|
7c00950967 | ||
|
|
b5516771d3 | ||
|
|
7b4084a15a | ||
|
|
412ac6bc3a | ||
|
|
a6ad44f111 | ||
|
|
97620bb5be | ||
|
|
49ed75d883 | ||
|
|
c41d92d27a | ||
|
|
a060aa2bf0 | ||
|
|
2ac6501698 | ||
|
|
06ac399ce6 | ||
|
|
dde5d49a5e | ||
|
|
89d3f13945 | ||
|
|
f47a063841 | ||
|
|
e964ff70e6 | ||
|
|
bc3580fa06 | ||
|
|
7fd4d49d56 | ||
|
|
ec75f9d1a3 | ||
|
|
6405fceee2 | ||
|
|
f9e46a373f | ||
|
|
d05debbe19 | ||
|
|
f8c86a9515 | ||
|
|
2c9cddd876 | ||
|
|
aaeee34c32 | ||
|
|
70397e4a95 | ||
|
|
43d904dbf3 | ||
|
|
1da64bf786 | ||
|
|
1cb1fb5bd4 | ||
|
|
208881a735 | ||
|
|
a2f52d4224 | ||
|
|
2ccb67cae4 | ||
|
|
b2a61348dd | ||
|
|
234f6d27c1 | ||
|
|
f339cfd315 | ||
|
|
c5239c5984 | ||
|
|
be13479f09 | ||
|
|
69a8d64716 | ||
|
|
3964309c67 | ||
|
|
243244d285 | ||
|
|
497b27dafb | ||
|
|
ca6d9f799e | ||
|
|
f1aa5f6a1d | ||
|
|
dc50de782a | ||
|
|
2e85eeea37 | ||
|
|
357da035b9 | ||
|
|
5aa54c863d | ||
|
|
42735d446e | ||
|
|
57eb334d5b | ||
|
|
5f904aa350 | ||
|
|
ee0f8adfac | ||
|
|
1ed37385c6 | ||
|
|
3a2e9d805a | ||
|
|
911ef4e69a | ||
|
|
1994ae4640 | ||
|
|
dbd8e47846 | ||
|
|
ce7bf1083e | ||
|
|
1db4ec6e63 | ||
|
|
1c82cf7660 | ||
|
|
e43fc6f08a | ||
|
|
31407b70e0 | ||
|
|
7d3c1016ce | ||
|
|
4c9f9438ff | ||
|
|
374dae6635 | ||
|
|
8c50f625b0 | ||
|
|
6fc96978c2 | ||
|
|
8e3767e344 | ||
|
|
b8b5631d9d | ||
|
|
c577b47cd5 | ||
|
|
cb6f36655e | ||
|
|
7905f4600d | ||
|
|
41c39e9bd9 | ||
|
|
f81d723264 | ||
|
|
afd5e978cf | ||
|
|
e68b9abd04 | ||
|
|
e487b87f6f | ||
|
|
1e20153b6e | ||
|
|
4621a52183 | ||
|
|
e90a742db8 | ||
|
|
b219d54503 | ||
|
|
3108d80b7e | ||
|
|
8a7d463b87 | ||
|
|
c3859d1df1 | ||
|
|
5a5e285be8 | ||
|
|
4d1d4d6e8e | ||
|
|
a96dd1932a | ||
|
|
693244795c | ||
|
|
255a4f8ce3 | ||
|
|
e2b26d910c | ||
|
|
293e331d69 | ||
|
|
2a91025581 | ||
|
|
37d34b6b83 | ||
|
|
44452823b7 | ||
|
|
e4bb87032e | ||
|
|
a6c4c2cca0 | ||
|
|
ba3b8ccc1d | ||
|
|
e5eee7de0c | ||
|
|
d8261019f1 | ||
|
|
9d165df18a | ||
|
|
7d1a8f7e9e | ||
|
|
8df3ec612a | ||
|
|
4c91c153cb | ||
|
|
cf2c0237f4 | ||
|
|
3d9fd1c7f2 | ||
|
|
d1e8fb33da | ||
|
|
1e3a4f2331 | ||
|
|
2ac1d46f46 | ||
|
|
77a2174685 | ||
|
|
3e270af17a | ||
|
|
10db7ec51b | ||
|
|
4f01bfc4bc | ||
|
|
1d591ada76 | ||
|
|
2bdc59fac8 | ||
|
|
784a74df0b | ||
|
|
82355d2f2d | ||
|
|
97a99d8718 | ||
|
|
755d4863c8 | ||
|
|
28544391f5 | ||
|
|
931b0103cd | ||
|
|
6e03b50771 | ||
|
|
362c460767 | ||
|
|
f4c815a1d9 | ||
|
|
fc6f08d5b7 | ||
|
|
68e370574a | ||
|
|
544c80d715 | ||
|
|
36fe146a74 | ||
|
|
caa29af2a9 | ||
|
|
0f31d231db | ||
|
|
102cb77435 | ||
|
|
7360ff4496 | ||
|
|
a6fd92bd8d | ||
|
|
06ac4b628d | ||
|
|
6c53a1ed68 | ||
|
|
6ad2c5c40f | ||
|
|
99cc0015f8 | ||
|
|
f1ce95915c | ||
|
|
aadc87f5a7 | ||
|
|
4d382ae8e6 | ||
|
|
418ba99078 | ||
|
|
648ce2f56a | ||
|
|
0648c58716 | ||
|
|
01da28efb1 | ||
|
|
6d6e1581b5 | ||
|
|
64da762c15 | ||
|
|
8903c1f167 | ||
|
|
a5521597b0 | ||
|
|
fe00607816 | ||
|
|
6e6d756109 | ||
|
|
85531fd404 | ||
|
|
c4c98df4f2 | ||
|
|
a3f4eb7b24 | ||
|
|
fdbfc7e349 | ||
|
|
c2e2107063 | ||
|
|
2ca8b7f359 | ||
|
|
3a09e01a8e | ||
|
|
d31315884c | ||
|
|
57ca428975 | ||
|
|
b0e2ef1a7d | ||
|
|
b237d9dd95 | ||
|
|
de194016ec | ||
|
|
e33ba57c13 | ||
|
|
44f8e1caff | ||
|
|
bc2e4a36df | ||
|
|
675c6b3773 | ||
|
|
f4472c16b2 | ||
|
|
854e8ae04d | ||
|
|
3e6d45acf6 | ||
|
|
a2c8af97e9 | ||
|
|
b18ff67646 | ||
|
|
6a5adfc0ba | ||
|
|
9714880283 | ||
|
|
3a0016a78a | ||
|
|
fb83914bd7 | ||
|
|
d5de489dc4 | ||
|
|
3fa4f691e3 | ||
|
|
8600fe054b | ||
|
|
8378be03d1 | ||
|
|
51a1dbfe09 | ||
|
|
8264e92b37 | ||
|
|
739a76634c | ||
|
|
47c097cb51 | ||
|
|
24d7d073ff | ||
|
|
39631edb98 | ||
|
|
9b8998aeec | ||
|
|
4aa4e9fb26 | ||
|
|
1fcc7f50ac | ||
|
|
6ef4f8e16c | ||
|
|
93224260ae | ||
|
|
991bfcf443 | ||
|
|
d762ced298 | ||
|
|
1bc910a963 | ||
|
|
63f451965c | ||
|
|
260419f48e | ||
|
|
c04aa90207 | ||
|
|
0679eb6a6d | ||
|
|
9a7e5bd1d3 | ||
|
|
827b311c81 | ||
|
|
e4679172e3 | ||
|
|
be10e8eee6 | ||
|
|
cb4553bd06 | ||
|
|
c68efec6c0 | ||
|
|
a75801320d | ||
|
|
241a746f32 | ||
|
|
47fbf87185 | ||
|
|
d210d99cce | ||
|
|
31f93d8445 | ||
|
|
2a609b332f | ||
|
|
18236c1c1b | ||
|
|
596e9d8068 | ||
|
|
589b4b8c6a | ||
|
|
60808bbded | ||
|
|
d4dc52ec84 | ||
|
|
c695c0c085 | ||
|
|
a91c598971 | ||
|
|
bf45619441 | ||
|
|
9b2aabb752 | ||
|
|
c0fb5edff9 | ||
|
|
5cdc9591d3 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,12 @@
|
||||
*.o
|
||||
*~
|
||||
*.diff
|
||||
*.patch
|
||||
*.core
|
||||
core
|
||||
tags
|
||||
.deps/
|
||||
compat/.dirstamp
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
config.log
|
||||
@@ -10,3 +16,4 @@ tmux
|
||||
Makefile
|
||||
Makefile.in
|
||||
configure
|
||||
tmux.1.*
|
||||
|
||||
24
.mailmap
Normal file
24
.mailmap
Normal file
@@ -0,0 +1,24 @@
|
||||
Bob Beck <beck@openbsd.org> beck <beck>
|
||||
Igor Sobrado <sobrado@openbsd.org> sobrado <sobrado>
|
||||
Jacek Masiulaniec <jacekm@openbsd.org> jacekm <jacekm>
|
||||
Jason McIntyre <jmc@openbsd.org> jcm <jcm>
|
||||
Joel Sing <jsing@openbsd.org> jsing <jsing>
|
||||
Marc Espie <espie@openbsd.org> espie <espie>
|
||||
Matthew Dempsky <matthew@openbsd.org> matthew <matthew>
|
||||
Matthias Kilian <kili@openbsd.org> kili <kili>
|
||||
Matthieu Herrb <matthieu@openbsd.org> matthieu <matthieu>
|
||||
Miod Vallat <miod@openbsd.org> miod <miod>
|
||||
Nicholas Marriott <nicm@openbsd.org> nicm <nicm>
|
||||
Nicholas Marriott <nicm@openbsd.org> no_author <no_author@example.org>
|
||||
<nicm@openbsd.org> <nicholas.marriott@gmail.com>
|
||||
Okan Demirmen <okan@openbsd.org> okan <okan>
|
||||
Philip Guenther <guenther@openbsd.org> guenther <guenther>
|
||||
Pierre-Yves Ritschard <pyr@openbsd.org> pyr <pyr>
|
||||
Ray Lai <ray@openbsd.org> ray <ray>
|
||||
Ryan McBride <mcbride@openbsd.org> mcbride <mcbride>
|
||||
Stefan Sperling <stsp@openbsd.org> stsp <stsp>
|
||||
Stuart Henderson <sthen@openbsd.org> sthen <sthen>
|
||||
Ted Unangst <tedu@openbsd.org> tedu <tedu>
|
||||
Theo Deraadt <deraadt@openbsd.org> deraadt <deraadt>
|
||||
Thomas Adam <thomas@xteddy.org> Thomas <thomas@xteddy.org>
|
||||
William Yodlowsky <william@openbsd.org> william <william>
|
||||
106
CHANGES
106
CHANGES
@@ -1,3 +1,109 @@
|
||||
CHANGES FROM 1.8 to 1.9, 20 February 2014
|
||||
|
||||
NOTE: This release has bumped the tmux protocol version. It is therefore
|
||||
advised that the prior tmux server is restarted when this version of tmux is
|
||||
installed, to avoid protocol mismatch errors for newer clients trying to
|
||||
talk to an older running tmux server.
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
|
||||
* 88 colour support has been removed.
|
||||
* 'default-path' has been removed. The new-window command accepts '-c' to
|
||||
cater for this. The previous value of "." can be replaced with: 'neww -c
|
||||
$PWD', the previous value of '' which meant current path of the pane can
|
||||
be specified as: 'neww -c "#{pane_current_path}"'
|
||||
|
||||
Deprecated Changes
|
||||
==================
|
||||
|
||||
* The single format specifiers: #A -> #Z (where defined) have been
|
||||
deprecated and replaced with longer-named equivalents, as listed in the
|
||||
FORMATS section of the tmux manpage.
|
||||
* The various foo-{fg,bg,attr} commands have been deprecated and replaced
|
||||
with equivalent foo-style option instead. Currently this is still
|
||||
backwards-compatible, but will be removed over time.
|
||||
|
||||
Normal Changes
|
||||
==============
|
||||
|
||||
* A new environment variable TMUX_TMPDIR is now honoured, allowing the
|
||||
socket directory to be set outside of TMPDIR (/tmp/ if not set).
|
||||
* If -s not given to swap-pane the current pane is assumed.
|
||||
* A #{pane_syncronized} format specifier has been added to be a conditional
|
||||
format if a pane is in a syncronised mode (c.f. syncronize-panes)
|
||||
* Tmux now runs under Cygwin natively.
|
||||
* Formats can now be nested within each other and expanded accordingly.
|
||||
* Added 'automatic-rename-format' option to allow the automatic rename
|
||||
mechanism to use something other than the default of
|
||||
#{pane_current_command}.
|
||||
* new-session learnt '-c' to specify the starting directory for that session
|
||||
and all subsequent windows therein.
|
||||
* The session name is now shown in the message printed to the terminal when
|
||||
a session is detached.
|
||||
* Lots more format specifiers have been added.
|
||||
* Server race conditions have been fixed; in particular commands are not run
|
||||
until after the configuration file is read completely.
|
||||
* Case insensitive searching in tmux's copy-mode is now possible.
|
||||
* attach-session and switch-client learnt the '-t' option to accept a window
|
||||
and/or a pane to use.
|
||||
* Copy-mode is only exited if no selection is in progress.
|
||||
* Paste key in copy-mode is now possible to enter text from the clipboard.
|
||||
* status-interval set to '0' now works as intended.
|
||||
* tmux now supports 256 colours running under fbterm.
|
||||
* Many bug fixes!
|
||||
|
||||
CHANGES FROM 1.7 to 1.8, 26 March 2013
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
|
||||
* layout redo/undo has been removed.
|
||||
|
||||
Normal Changes
|
||||
==============
|
||||
|
||||
* Add halfpage up/down bindings to copy mode.
|
||||
* Session choosing fixed to work with unattached sessions.
|
||||
* New window options window-status-last-{attr,bg,fg} to denote the last
|
||||
window which was active.
|
||||
* Scrolling in copy-mode now scrolls the region without moving the mouse
|
||||
cursor.
|
||||
* run-shell learnt '-t' to specify the pane to use when displaying output.
|
||||
* Support for middle-click pasting.
|
||||
* choose-tree learns '-u' to start uncollapsed.
|
||||
* select-window learnt '-T' to toggle to the last window if it's already
|
||||
current.
|
||||
* New session option 'assume-paste-time' for pasting text versus key-binding
|
||||
actions.
|
||||
* choose-* commands now work outside of an attached client.
|
||||
* Aliases are now shown for list-commands command.
|
||||
* Status learns about formats.
|
||||
* Free-form options can be set with set-option if prepended with an '@'
|
||||
sign.
|
||||
* capture-pane learnt '-p' to send to stdout, and '-e' for capturing escape
|
||||
sequences, and '-a' to capture the alternate screen, and '-P' to dump
|
||||
pending output.
|
||||
* Many new formats added (client_session, client_last_session, etc.)
|
||||
* Control mode, which is a way for a client to send tmux commands.
|
||||
Currently more useful to users of iterm2.
|
||||
* resize-pane learnt '-x' and '-y' for absolute pane sizing.
|
||||
* Config file loading now reports errors from all files which are loaded via
|
||||
the 'source-file' command.
|
||||
* 'copy-pipe' mode command to copy selection and pipe the selection to a
|
||||
command.
|
||||
* Panes can now emit focus notifications for certain applications
|
||||
which use those.
|
||||
* run-shell and if-shell now accept formats.
|
||||
* resize-pane learnt '-Z' for zooming a pane temporarily.
|
||||
* new-session learnt '-A' to make it behave like attach-session.
|
||||
* set-option learnt '-o' to prevent setting an option which is already set.
|
||||
* capture-pane and show-options learns '-q' to silence errors.
|
||||
* New command 'wait-for' which blocks a client until woken up again.
|
||||
* Resizing panes will now reflow the text inside them.
|
||||
* Lots and lots of bug fixes, fixing memory-leaks, etc.
|
||||
* Various manpage improvements.
|
||||
|
||||
CHANGES FROM 1.6 to 1.7, 13 October 2012
|
||||
|
||||
* tmux configuration files now support line-continuation with a "\" at the
|
||||
|
||||
21
COPYING
Normal file
21
COPYING
Normal file
@@ -0,0 +1,21 @@
|
||||
THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE.
|
||||
|
||||
The README, 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,
|
||||
typically:
|
||||
|
||||
Copyright (c) <author>
|
||||
|
||||
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.
|
||||
84
FAQ
84
FAQ
@@ -326,51 +326,6 @@ lock(1) or vlock(1)) by using the following:
|
||||
|
||||
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
|
||||
|
||||
* How can I open a new window in the same directory as the current window?
|
||||
|
||||
One option is to just run "TMUX= tmux" in the window. However, this only works if no
|
||||
command is running, so that you can input the command.
|
||||
|
||||
A workaround is to let tmux know about the current path through an environment
|
||||
variable. To do so, use the following command:
|
||||
|
||||
[ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD
|
||||
|
||||
Which sets TMUXPWD_i (where i is the number of the current window) to the path
|
||||
of the current directory. This command can be added to PS1, for example:
|
||||
|
||||
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)\h$ '
|
||||
|
||||
When a new window is created, the shell should be asked to change
|
||||
directory. You can define a new binding (for example, if using GNU bash):
|
||||
|
||||
bind-key C-c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
|
||||
|
||||
This solution will work even if a command is currently running in the terminal,
|
||||
but it will not work from a window that has just been swapped with another
|
||||
because TMUXPWD_i will not be updated after a swap. However, once a new prompt
|
||||
is displayed, TMUXPWD_i is updated properly.
|
||||
|
||||
* tmux doesn't start with "daemon failed"
|
||||
|
||||
tmux shows something similar to this when started:
|
||||
|
||||
fatal: server_start: daemon failed: No such file or directory
|
||||
fatal: main_dispatch: imsg_read failed
|
||||
|
||||
A possible reason is that /dev/null is not a character device or is otherwise
|
||||
inaccessible.
|
||||
|
||||
Check with:
|
||||
|
||||
file /dev/null
|
||||
ls -l /dev/null
|
||||
|
||||
If it is not a character device or has incorrect permissions, it can typically
|
||||
be recreated with:
|
||||
|
||||
cd /dev && rm null && ./MAKEDEV null
|
||||
|
||||
* vim displays reverse video instead of italics, while less displays italics
|
||||
(or just regular text) instead of reverse. What's wrong?
|
||||
|
||||
@@ -441,5 +396,44 @@ configuration file:
|
||||
Or the default window options:
|
||||
|
||||
$ tmux -Lfoo -f/dev/null start\; show -gw
|
||||
|
||||
* How do I copy a selection from tmux to the system's clipboard?
|
||||
|
||||
When running in xterm(1), tmux can automatically send copied text to the
|
||||
clipboard. This is controlled by the set-clipboard option and also needs this
|
||||
X resource to be set:
|
||||
|
||||
XTerm*disallowedWindowOps: 20,21,SetXprop
|
||||
|
||||
For rxvt-unicode (urxvt), there is an unofficial Perl extension here:
|
||||
|
||||
http://anti.teamidiot.de/static/nei/*/Code/urxvt/
|
||||
|
||||
Otherwise a key binding for copy mode using xclip (or xsel) works:
|
||||
|
||||
bind -temacs-copy C-y copy-pipe "xclip -i >/dev/null"
|
||||
|
||||
Or for inside and outside copy mode with the prefix key:
|
||||
|
||||
bind C-y run -b "tmux save-buffer - | xclip -i"
|
||||
|
||||
On OS X, reattach-to-usernamespace lets pbcopy/pbpaste work:
|
||||
|
||||
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
|
||||
|
||||
* Why do I see dots around a session when I attach to it?
|
||||
|
||||
tmux limits the size of the window to the smallest attached session. If
|
||||
it didn't do this then it would be impossible to see the entire window.
|
||||
The dots mark the size of the window tmux can display.
|
||||
|
||||
To avoid this, detach all other clients when attaching:
|
||||
|
||||
$ tmux attach -d
|
||||
|
||||
Or from inside tmux by detaching individual clients with C-b D or all
|
||||
using:
|
||||
|
||||
C-b : attach -d
|
||||
|
||||
$Id$
|
||||
|
||||
47
Makefile.am
47
Makefile.am
@@ -2,18 +2,18 @@
|
||||
|
||||
# Obvious program stuff.
|
||||
bin_PROGRAMS = tmux
|
||||
dist_man1_MANS = tmux.1
|
||||
CLEANFILES = tmux.1.mdoc tmux.1.man
|
||||
|
||||
# Distribution tarball options.
|
||||
EXTRA_DIST = \
|
||||
CHANGES FAQ NOTES TODO examples compat \
|
||||
array.h compat.h tmux.h osdep-*.c
|
||||
CHANGES FAQ README TODO COPYING examples compat \
|
||||
array.h compat.h tmux.h osdep-*.c mdoc2man.awk tmux.1
|
||||
dist-hook:
|
||||
grep "^#found_debug=" configure
|
||||
find $(distdir) -name .svn -type d|xargs rm -Rf
|
||||
|
||||
# Preprocessor flags.
|
||||
CPPFLAGS += @XOPEN_DEFINES@
|
||||
CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
|
||||
|
||||
# glibc as usual does things ass-backwards and hides useful things by default,
|
||||
# so everyone has to add this.
|
||||
@@ -24,14 +24,17 @@ endif
|
||||
# Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly
|
||||
# different flags.
|
||||
if IS_GCC
|
||||
CFLAGS += -std=c99
|
||||
CFLAGS += -std=gnu99
|
||||
if IS_DEBUG
|
||||
CFLAGS += -g -ggdb -O0
|
||||
CFLAGS += -O0 -g
|
||||
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
|
||||
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
CFLAGS += -Wdeclaration-after-statement
|
||||
CPPFLAGS += -DDEBUG
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
if IS_GCC4
|
||||
CPPFLAGS += -iquote. -I/usr/local/include
|
||||
@@ -45,8 +48,12 @@ endif
|
||||
|
||||
# Set flags for Solaris.
|
||||
if IS_SUNOS
|
||||
if IS_GCC
|
||||
CPPFLAGS += -D_XPG6 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
||||
else
|
||||
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
||||
endif
|
||||
endif
|
||||
|
||||
# Set flags for Sun CC.
|
||||
if IS_SUNCC
|
||||
@@ -101,6 +108,7 @@ dist_tmux_SOURCES = \
|
||||
cmd-new-window.c \
|
||||
cmd-paste-buffer.c \
|
||||
cmd-pipe-pane.c \
|
||||
cmd-queue.c \
|
||||
cmd-refresh-client.c \
|
||||
cmd-rename-session.c \
|
||||
cmd-rename-window.c \
|
||||
@@ -114,18 +122,14 @@ dist_tmux_SOURCES = \
|
||||
cmd-select-pane.c \
|
||||
cmd-select-window.c \
|
||||
cmd-send-keys.c \
|
||||
cmd-send-prefix.c \
|
||||
cmd-server-info.c \
|
||||
cmd-set-buffer.c \
|
||||
cmd-set-environment.c \
|
||||
cmd-set-option.c \
|
||||
cmd-show-buffer.c \
|
||||
cmd-show-environment.c \
|
||||
cmd-show-messages.c \
|
||||
cmd-show-options.c \
|
||||
cmd-source-file.c \
|
||||
cmd-split-window.c \
|
||||
cmd-start-server.c \
|
||||
cmd-string.c \
|
||||
cmd-suspend-client.c \
|
||||
cmd-swap-pane.c \
|
||||
@@ -133,13 +137,14 @@ dist_tmux_SOURCES = \
|
||||
cmd-switch-client.c \
|
||||
cmd-unbind-key.c \
|
||||
cmd-unlink-window.c \
|
||||
cmd-wait-for.c \
|
||||
cmd.c \
|
||||
colour.c \
|
||||
control.c \
|
||||
control-notify.c \
|
||||
environ.c \
|
||||
format.c \
|
||||
grid-utf8.c \
|
||||
grid-cell.c \
|
||||
grid-view.c \
|
||||
grid.c \
|
||||
input-keys.c \
|
||||
@@ -168,6 +173,7 @@ dist_tmux_SOURCES = \
|
||||
session.c \
|
||||
signal.c \
|
||||
status.c \
|
||||
style.c \
|
||||
tmux.c \
|
||||
tty-acs.c \
|
||||
tty-keys.c \
|
||||
@@ -228,6 +234,25 @@ endif
|
||||
if NO_B64_NTOP
|
||||
nodist_tmux_SOURCES += compat/b64_ntop.c
|
||||
endif
|
||||
if NO_CFMAKERAW
|
||||
nodist_tmux_SOURCES += compat/cfmakeraw.c
|
||||
endif
|
||||
if NO_OPENAT
|
||||
nodist_tmux_SOURCES += compat/openat.c
|
||||
endif
|
||||
|
||||
# Install tmux.1 in the right format.
|
||||
install-exec-hook:
|
||||
if test x@MANFORMAT@ = xmdoc; then \
|
||||
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1 \
|
||||
>$(srcdir)/tmux.1.mdoc; \
|
||||
else \
|
||||
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1| \
|
||||
$(AWK) -fmdoc2man.awk >$(srcdir)/tmux.1.man; \
|
||||
fi
|
||||
$(MKDIR_P) $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) $(srcdir)/tmux.1.@MANFORMAT@ \
|
||||
$(DESTDIR)$(mandir)/man1/tmux.1
|
||||
|
||||
# Update SF web site.
|
||||
upload-index.html: update-index.html
|
||||
|
||||
@@ -7,7 +7,7 @@ simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||
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).
|
||||
|
||||
Since the 1.2 release tmux depends on libevent. Download it from:
|
||||
tmux depends on libevent 2.x. Download it from:
|
||||
|
||||
http://www.monkey.org/~provos/libevent/
|
||||
|
||||
@@ -16,15 +16,16 @@ To build tmux from a release tarball, do:
|
||||
$ ./configure && make
|
||||
$ sudo make install
|
||||
|
||||
To get and build the latest version control checkout:
|
||||
To get and build the latest from version control:
|
||||
|
||||
$ git clone git://tmux.git.sourceforge.net/gitroot/tmux/tmux
|
||||
$ git clone git://git.code.sf.net/p/tmux/tmux-code tmux
|
||||
$ cd tmux
|
||||
$ sh autogen.sh
|
||||
$ ./configure && make
|
||||
|
||||
For more information see https://sourceforge.net/scm/?type=git&group_id=200378
|
||||
and http://git-scm.com.
|
||||
and http://git-scm.com. Patches should be sent by email to the mailing list at
|
||||
tmux-users@lists.sourceforge.net.
|
||||
|
||||
For documentation on using tmux, see the tmux.1 manpage. It can be viewed from
|
||||
the source tree with:
|
||||
@@ -34,25 +35,13 @@ the source tree with:
|
||||
Some common questions are answered in the FAQ file and a more extensive (but
|
||||
slightly out of date) guide is available in the OpenBSD FAQ at
|
||||
http://www.openbsd.org/faq/faq7.html#tmux. A rough todo list is in the TODO
|
||||
file.
|
||||
|
||||
A Vim syntax file is available in the examples directory. To install it:
|
||||
|
||||
- Drop the file in the syntax directory into runtimepath (such as
|
||||
~/.vim/syntax/tmux.vim).
|
||||
- Make the filetype recognisable by adding the following to filetype.vim
|
||||
(~/.vim/filetype.vim):
|
||||
|
||||
augroup filetypedetect
|
||||
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||||
augroup END
|
||||
|
||||
- Switch on syntax highlighting by adding "syntax enable" to .vimrc.
|
||||
file and some example configurations and a Vim syntax file are in the examples
|
||||
directory.
|
||||
|
||||
For debugging, running tmux with -v or -vv will generate server and client log
|
||||
files in the current directory.
|
||||
|
||||
tmux mailing lists are available. The visit:
|
||||
tmux mailing lists are available. Visit:
|
||||
|
||||
https://sourceforge.net/mail/?group_id=200378
|
||||
|
||||
@@ -64,8 +53,7 @@ welcome. Please send by email to:
|
||||
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.
|
||||
tmux. All other files have a license and copyright notice at their start.
|
||||
|
||||
-- Nicholas Marriott <nicm@users.sf.net>
|
||||
|
||||
71
SYNCING
71
SYNCING
@@ -1,10 +1,10 @@
|
||||
Preamble
|
||||
========
|
||||
|
||||
Tmux on SourceForge has two git repositories [1] "tmux" and "tmux-openbsd".
|
||||
Tmux on SourceForge has two git repositories [1] "tmux-code" and "tmux-openbsd".
|
||||
Here's a description of them:
|
||||
|
||||
* "tmux" is the portable version, the one which contains code for other
|
||||
* "tmux-code" is the portable version, the one which contains code for other
|
||||
operating systems, and autotools, etc., which isn't found or needed in the
|
||||
OpenBSD base system.
|
||||
|
||||
@@ -13,10 +13,12 @@ Here's a description of them:
|
||||
|
||||
Note: The "tmux-openbsd" repository is actually handled by "git cvsimport"
|
||||
running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS
|
||||
repository will take that long to appear in this git repository.
|
||||
repository will take at least that long to appear in this git repository.
|
||||
(It might take longer, depending on the CVS mirror used to import the
|
||||
OpenBSD code).
|
||||
|
||||
It is assumed that the person doing the sync has read/write access to the
|
||||
tmux repository on SourceForge already.
|
||||
tmux-code repository on SourceForge already.
|
||||
|
||||
If you've never used git before, git tracks meta-data about the committer
|
||||
and the author, as part of a commit, hence:
|
||||
@@ -35,69 +37,69 @@ this information has ever been set before.
|
||||
Cloning repositories
|
||||
====================
|
||||
|
||||
This involves having both tmux and tmux-openbsd cloned, as in:
|
||||
This involves having both tmux-code and tmux-openbsd cloned, as in:
|
||||
|
||||
% cd /some/where/useful
|
||||
% git clone ssh://${USER}@tmux.git.sf.net/gitroot/tmux/tmux
|
||||
% git clone ssh://${USER}@tmux.git.sf.net/gitroot/tmux/tmux-openbsd
|
||||
% git clone ssh://${USER}@git.code.sf.net/p/tmux/tmux
|
||||
% git clone ssh://${USER}@git.code.sf.net/p/tmux/tmux-openbsd
|
||||
|
||||
Note that you do not need additoinal checkouts to manage the sync -- an
|
||||
Note that you do not need additional checkouts to manage the sync -- an
|
||||
existing clone of either repositories will suffice. So if you already have
|
||||
these checkouts existing, skip that.
|
||||
|
||||
Adding in git-remotes
|
||||
=====================
|
||||
|
||||
Because the portable "tmux" git repository and the "tmux-openbsd" repository do
|
||||
not inherently share any history between each other, the history has been
|
||||
faked between them. This "faking of history" is something which has to be
|
||||
told to git for the purposes of comparing the "tmux" and "tmux-openbsd"
|
||||
repositories for syncing. To do this, we must reference the clone of the
|
||||
"tmux-openbsd" repository from the "tmux" repository, as shown by the
|
||||
following command:
|
||||
Because the portable "tmux-code" git repository and the "tmux-openbsd"
|
||||
repository do not inherently share any history between each other, the
|
||||
history has been faked between them. This "faking of history" is something
|
||||
which has to be told to git for the purposes of comparing the "tmux" and
|
||||
"tmux-openbsd" repositories for syncing. To do this, we must reference the
|
||||
clone of the "tmux-openbsd" repository from the "tmux-code" repository, as
|
||||
shown by the following command:
|
||||
|
||||
% cd /path/to/tmux
|
||||
% cd /path/to/tmux-code
|
||||
% git remote add obsd-tmux file:///path/to/tmux-openbsd
|
||||
|
||||
So that now, the remote "obsd-tmux" can be used to reference branches and
|
||||
commits from the "tmux-openbsd" repository, but from the context of the
|
||||
portable "tmux" repository, which makes sense because it's the "tmux"
|
||||
portable "tmux-code" repository, which makes sense because it's the "tmux"
|
||||
repository which will have the updates applied to them.
|
||||
|
||||
Fetching updates
|
||||
================
|
||||
|
||||
To ensure the latest commits from "tmux-openbsd" can be found from within
|
||||
"tmux", we have to ensure the "master" branch from "tmux-openbsd" is
|
||||
up-to-date first, and then reference that update in "tmux", as in:
|
||||
"tmux-code", we have to ensure the "master" branch from "tmux-openbsd" is
|
||||
up-to-date first, and then reference that update in "tmux-code", as in:
|
||||
|
||||
% cd /path/to/tmux-openbsd
|
||||
% git checkout master
|
||||
% git pull
|
||||
|
||||
Then back in "tmux":
|
||||
Then back in "tmux-code":
|
||||
|
||||
% cd /path/to/tmux
|
||||
% git fetch obsd-tmux
|
||||
% cd /path/to/tmux-code
|
||||
% git fetch obsd-tmux-code
|
||||
|
||||
Creating the necessary branches
|
||||
===============================
|
||||
|
||||
Now that "tmux" can see commits and branches from "tmux-openbsd" by way of
|
||||
the remote name "obsd-tmux", we can now create the master branch from
|
||||
"tmux-openbsd" in the "tmux" repository:
|
||||
Now that "tmux-code" can see commits and branches from "tmux-openbsd" by way
|
||||
of the remote name "obsd-tmux", we can now create the master branch from
|
||||
"tmux-openbsd" in the "tmux-code" repository:
|
||||
|
||||
% git checkout -b obsd-master obsd-tmux/master
|
||||
|
||||
Adding in the fake history points
|
||||
=================================
|
||||
|
||||
To tie both the "master" branch from "tmux" and the "obsd-master" branch
|
||||
from "tmux-openbsd" together, the fake history points added to the "tmux"
|
||||
repository need to be added. To do this, we must add an additional refspec
|
||||
line, as in:
|
||||
To tie both the "master" branch from "tmux-code" and the "obsd-master"
|
||||
branch from "tmux-openbsd" together, the fake history points added to the
|
||||
"tmux-code" repository need to be added. To do this, we must add an
|
||||
additional refspec line, as in:
|
||||
|
||||
% cd /path/to/tmux
|
||||
% cd /path/to/tmux-code
|
||||
% git config --add remote.origin.fetch '+refs/replace/*:refs/replace/*'
|
||||
% git fetch origin
|
||||
|
||||
@@ -108,8 +110,7 @@ Make sure the "master" branch is checked out:
|
||||
|
||||
% git checkout master
|
||||
|
||||
The following will show commits on OpenBSD not yet synched with tmux
|
||||
portable:
|
||||
The following will show commits on OpenBSD not yet synched with "tmux-code":
|
||||
|
||||
% git log master..obsd-master
|
||||
|
||||
@@ -137,7 +138,7 @@ Release tmux for next version
|
||||
don't have debugging enabled, otherwise make(1) aborts when
|
||||
preparing the distribution.
|
||||
|
||||
2. Update and commit NOTES and CHANGES. The former should be checked for
|
||||
2. Update and commit README and CHANGES. The former should be checked for
|
||||
anything outdated and updated with a list of things that might break
|
||||
upgrades and the latter should mention all the major changes since
|
||||
the last version.
|
||||
@@ -150,7 +151,7 @@ Release tmux for next version
|
||||
|
||||
Push the tag out with:
|
||||
|
||||
% git push --tags
|
||||
% git push 1.X
|
||||
|
||||
4. Build the tarball with make dist. Now that it's using autoconf there
|
||||
shouldn't be any weird files (such as the original and rejection files
|
||||
@@ -170,4 +171,4 @@ Release tmux for next version
|
||||
|
||||
9. Update freshmeat.
|
||||
|
||||
[1] http://tmux.git.sourceforge.net/git/gitweb-index.cgi
|
||||
[1] https://sourceforge.net/p/tmux/_list/git
|
||||
|
||||
287
TODO
287
TODO
@@ -1,170 +1,133 @@
|
||||
NOTES
|
||||
=====
|
||||
- command bits and pieces:
|
||||
* use "--" to mark start of command w/ neww etc to avoid quoting
|
||||
* why doesn't command-prompt work if made read-only?
|
||||
* allow multiple targets: fnmatch for -t/-c, for example detach all
|
||||
clients with -t*
|
||||
* add -c for new-session like new-window
|
||||
* attach should take a pane and select it as well as attaching
|
||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
||||
and command prompt
|
||||
* last-pane across sessions
|
||||
* exact match operator for targets (or break the substring match
|
||||
and require eg x* instead of just x)
|
||||
|
||||
This file describes rough notes regarding ideas for potential future tmux
|
||||
development. It's not necessarily guaranteed that items in this TODO file
|
||||
will ever get implemented.
|
||||
- make command sequences more usable
|
||||
* don't require space after ;
|
||||
* options for error handling: && and ||?
|
||||
|
||||
It is asked therefore, that anyone thinking of undertaking a task in this
|
||||
TODO file, email tmux-users@lists.sf.net to discuss the feature.
|
||||
- options bits and pieces:
|
||||
* set-remain-on-exit is a complete hack
|
||||
* way to set socket path from config file
|
||||
|
||||
Thie file is split up between tmux user interface (UI) issues, and terminal
|
||||
compatibility issues.
|
||||
- format improvements:
|
||||
* option to quote format (#{session_name:quoted})
|
||||
* formats need conditions for >0 (for #P)
|
||||
* some way to pad # stuff with spaces, #!2T maybe
|
||||
* status stuff is redundant with formats
|
||||
* last window update time and format for it
|
||||
* formats to show if a window is linked into multiple sessions, into
|
||||
multiple attached sessions, and is the active window in multiple
|
||||
attached sessions?
|
||||
|
||||
TMUX UI ISSUES
|
||||
==============
|
||||
- choose mode improvements:
|
||||
* choose-pane command (augment choose-tree to do this?)
|
||||
* choose-mode and copy-mode are very similar, make choose-mode a subset?
|
||||
* flag to choose-* for sort order
|
||||
* choose mode would be better per client than per window
|
||||
* two choices (first one then second, for swap-pane and join-pane)
|
||||
|
||||
- improve monitor-*:
|
||||
* straighten out rules for multiple clients
|
||||
* think about what happens across sessions
|
||||
* monitor changes within a region
|
||||
* perhaps monitor /all/ panes in the window not just one
|
||||
|
||||
- improve mouse support:
|
||||
* bind commands to mouse in different areas?
|
||||
* more fine-grained options
|
||||
* commands executed when clicking on a pattern (URL)
|
||||
* send arrow key sequences for mouse scroll wheel in alternate screen
|
||||
* mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets
|
||||
the flag on w/o checking the others before calling tty_update_mode)
|
||||
|
||||
- hooks!
|
||||
|
||||
- implicitly add exec to the commands for new windows (switch to disable it)?
|
||||
- bring back detach-session to detach all clients on a session?
|
||||
- allow fnmatch for -c, so that you can, eg, detach all clients
|
||||
- garbage collect window history (100 lines at a time?) if it hasn't been used
|
||||
in $x time
|
||||
- flags to centre screen in window
|
||||
- activity/bell should be per-window not per-link? what if it is cur win in
|
||||
session not being watched?
|
||||
- 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
|
||||
- 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?
|
||||
- would be nice to be able to use "--" to mark start of command w/ neww etc
|
||||
to avoid quoting
|
||||
- make command sequences more usable: don't require space after ;, handle
|
||||
errors better
|
||||
- attach should have a flag to create session if it doesn't exist
|
||||
- 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
|
||||
- way to set socket path from config file
|
||||
- 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??
|
||||
- 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)
|
||||
- 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)
|
||||
-- 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
|
||||
- commands should be able to succeed or fail and have || or && for command
|
||||
lists
|
||||
- some way to KEEP a command running continually and just use its LAST line of
|
||||
output
|
||||
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
|
||||
the terminal - www/ruby-addressable; make regress
|
||||
- support esc-esc to quit in modes
|
||||
- fix ctrl+F1-F4 output. to what?
|
||||
- better utf8 support: window names, prompt input, message display
|
||||
- session history for client and last-session command
|
||||
- option to change status line colour when current window is in a mode?
|
||||
- option to move copy mode indicator into status line
|
||||
- list-buffer/show-buffer should display UTF-8
|
||||
- selection behaviour closer to vi in vi mode
|
||||
- live update: server started with -U connects to server, requests sessions and
|
||||
windows, receives fds
|
||||
- sort out inheriting config from shell on new sessions/windows:
|
||||
should pick up default-path/termios/etc from client if possible,
|
||||
else leave empty/default
|
||||
- link panes into multiple windows
|
||||
- bells should be passed between sessions with visual-bell etc
|
||||
sequence until its shell exits, to allow them to be used from the config file
|
||||
- better session sharing: create-socket command to create socket somewhere (-r
|
||||
flag for readonly)
|
||||
- multiline status line (no?)
|
||||
- flag for absolute pane size to resize-pane
|
||||
- sanity check input to socket
|
||||
- support title stack, both internally and externally
|
||||
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
||||
- command to show status line information briefly when it is off
|
||||
- some way to pad # stuff with spaces, #!2T maybe
|
||||
- a binding to "scroll down and exit at bottom" copy mode
|
||||
- some way to pass keystrokes in copy mode through to underlying window
|
||||
- last window update time and # replacement for it for display-message
|
||||
- find-window across sessions - other ways to make session handling easier?
|
||||
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
|
||||
prompt?
|
||||
- command to toggle selection not to move it in copy-mode
|
||||
- audit of escape sequence support vs xterm
|
||||
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
|
||||
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
|
||||
- something for -t "last window in session" so a session can be used as a stack
|
||||
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
|
||||
ptr then when program inside died, sends MSG_SOMETHING with wait status to
|
||||
client
|
||||
- bind commands to key sequences? -- make it so ALL keys go through a table,
|
||||
first an implicit table in which C-b is the only default binding to a
|
||||
command that says "next key from $othertable" and so on. means -n can
|
||||
go away as well
|
||||
- monitor, bell etc should monitor /all/ panes in the window not just one
|
||||
- a history of commands that can be reversed (reverse member of each command,
|
||||
and a buffer) info() when changing to same window
|
||||
- way to add dest for break-pane; maybe some easier way to unbreak-pane
|
||||
- case insensitive searching
|
||||
- configurable borders and empty space filler for when panes < window?
|
||||
- mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets the
|
||||
flag on w/o checking the others before calling tty_update_mode)
|
||||
- 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
|
||||
- pass shell commands as argv rather than strings, allow them to be specified
|
||||
in commands without quotes
|
||||
- numeric prefix in copy mode should be paste buffer for C-w
|
||||
- named buffers and allow gaps in the stack
|
||||
- get rid of separate UTF-8 cell stuff: add 1 byte to cell and store BMP as
|
||||
uint16_t+3 bits of flags. anything <=0xffff is Unicode, higher are used to
|
||||
build tree of combined characters/non-BMP (LRU dropped when full)
|
||||
- entry in FAQ about what to do when someone does mkdir /tmp/tmux-1000
|
||||
- monitor-activity is broken in several ways with multiple clients
|
||||
- monitor-activity should be more powerful (eg set a region)
|
||||
- maybe a way to put pane names instead of window names in status line
|
||||
- support for borderless panes
|
||||
- run-shell/if-shell should support status_replace stuff
|
||||
- wait-pane command or another way to make it synchronous/wait for command to
|
||||
finish
|
||||
- last-pane across sessions
|
||||
- attach should take a pane and select it as well as attaching
|
||||
- panes should have names like windows
|
||||
- command-prompt doesn't work if made read-only. why?
|
||||
- option to quote format eg #{session_name:quoted}
|
||||
- formats need conditions for >0 (for #P)
|
||||
- fetch full command line on !Linux, and add option to strip prefixes
|
||||
such as "sh " "/bin/sh " etc etc
|
||||
- synchronize-windows option
|
||||
- append to buffer in copy mode
|
||||
- way to paste w/o trailing whitespace
|
||||
- flag to switch-client to switch all clients
|
||||
- history of layouts and undo/redo flags to selectl
|
||||
- way to tag a layout as a number/name
|
||||
- optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
|
||||
- support multibyte key strings
|
||||
- allow commands to be executed when certaing patterns in a screen
|
||||
are clicked on with the mouse
|
||||
- flag to make next/previous commands skip a window
|
||||
- way to do tmux command/run-shell from mode keys
|
||||
- send command to all windows
|
||||
- choose-pane command
|
||||
- Augment choose-tree to do this? TA to investigate.
|
||||
- choose-mode and copy-mode are very similar. Perhaps make choose-mode a
|
||||
subset of copy-mode in that it inherits key-bindings and other traits but
|
||||
not all.
|
||||
* display-time but message-fg/bg/attr
|
||||
* list-* vs show-*
|
||||
* split-window -> split-pane??
|
||||
|
||||
- better UTF-8 support:
|
||||
* #22T can split in the middle of UTF-8 characters!
|
||||
* window names and titles
|
||||
* message display
|
||||
* prompt input
|
||||
* multibyte key input
|
||||
* buffer_sample and the choose-* could show UTF-8 properly
|
||||
|
||||
- copy/paste improvements:
|
||||
* incremental searching
|
||||
* append to buffer
|
||||
* paste w/o trailing whitespace
|
||||
* named buffers and allow gaps in the stack
|
||||
* command to toggle selection not to move it in copy-mode
|
||||
|
||||
- layout stuff
|
||||
* way to tag a layout as a number/name
|
||||
* maybe keep last layout + size around and if size reverts just put it
|
||||
back
|
||||
* revamp layouts: they are too complicated, should be more closely
|
||||
integrated, should support hints, layout sets should just be a
|
||||
special case of custom layouts, and we should support panes that are
|
||||
not attached to a cell at all. this could be the time to introduce
|
||||
panelink to replace layout_cell
|
||||
* way to set hints/limits about pane size for resizing
|
||||
* panning over window (window larger than visible)
|
||||
|
||||
- terminfo bits
|
||||
* use a better termcap internally instead of screen, perhaps xterm
|
||||
* use screen-256color when started on 256 colour terminal?
|
||||
* need a tmux terminfo entry to document the extensions we are using in
|
||||
upstream terminfo
|
||||
* support title stack, both internally and externally (restore on
|
||||
detach) http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
|
||||
|
||||
- code cleanup
|
||||
* instead of separate window and session options, just one master
|
||||
options list with each option having a type (window or session), then
|
||||
options on window, on session, and global. for window options we look
|
||||
window->session->global, and for session we look session->global
|
||||
* the way pane, window, session destroy is handled is too complicated
|
||||
and the distinction between session.c, window.c and server-fn.c
|
||||
functions is not clear. could we just have kill_pane(),
|
||||
kill_window(), unlink_window(), kill_session() that fix up all data
|
||||
structures (flagging sessions as dead) and return a value to say
|
||||
whether clients need to be checked for dead sessions? sort of like
|
||||
session_detach now but more so. or some other scheme to make it
|
||||
simpler and clearer? also would be nice to remove/rename server-fn.c
|
||||
* more readable way to work out the various things commands need to
|
||||
know about the client, notably:
|
||||
- is this the config file? (cmdq->c == NULL)
|
||||
- is this a command client? (cmdq->c != NULL &&
|
||||
cmdq->c->session == NULL)
|
||||
- is this a control client?
|
||||
- can i do stdin or stdout to this client?
|
||||
or even guarantee that cmdq->c != NULL and provide a better way to
|
||||
tell when in the config file - then we use cmdq->c if we need a
|
||||
client w/o a session else cmd_current_client
|
||||
* optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
|
||||
|
||||
- miscellaneous
|
||||
* way to keep a job running just read its last line of output for #()
|
||||
link panes into multiple windows
|
||||
* live update: server started with -U connects to server, requests
|
||||
sessions and windows, receives file descriptors
|
||||
* there are inconsistencies in what we get from old shell and what
|
||||
comes from config for new sessions and windows
|
||||
* multiline status line?
|
||||
* bind commands to key sequences -- make it so ALL keys go through a
|
||||
table, first an implicit table in which C-b is the only default
|
||||
binding to a command that says "next key from $othertable" and so
|
||||
on. means -n can go away as well
|
||||
|
||||
TERMINAL ISSUES
|
||||
================
|
||||
|
||||
- use a better termcap internally instead of screen, perhaps xterm
|
||||
- clear window title on exit (see using xterm title stack)
|
||||
- get it passing all the vttest tests that don't require resizing the terminal
|
||||
- support for bce
|
||||
- use screen-256color when started on 256 colour terminal??
|
||||
- if-shell/run-shell should block further command execution in the same command
|
||||
- possibly support rxvt-unicode extended mouse input (1015)
|
||||
- wrap/no wrap esc seq DEC CSI ? 7 h/l
|
||||
* We need a tmux terminfo entry to document the extensions we are using in
|
||||
upstream terminfo. Must NOT change (only add or remove) anything from
|
||||
TERM=screen so we can fallback!
|
||||
|
||||
119
arguments.c
119
arguments.c
@@ -20,9 +20,25 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Manipulate command arguments.
|
||||
*/
|
||||
|
||||
struct args_entry *args_find(struct args *, u_char);
|
||||
|
||||
RB_GENERATE(args_tree, args_entry, entry, args_cmp);
|
||||
|
||||
/* Arguments tree comparison function. */
|
||||
int
|
||||
args_cmp(struct args_entry *a1, struct args_entry *a2)
|
||||
{
|
||||
return (a1->flag - a2->flag);
|
||||
}
|
||||
|
||||
/* Create an arguments set with no flags. */
|
||||
struct args *
|
||||
args_create(int argc, ...)
|
||||
@@ -32,8 +48,6 @@ args_create(int argc, ...)
|
||||
int i;
|
||||
|
||||
args = xcalloc(1, sizeof *args);
|
||||
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
|
||||
fatal("bit_alloc failed");
|
||||
|
||||
args->argc = argc;
|
||||
if (argc == 0)
|
||||
@@ -49,35 +63,36 @@ args_create(int argc, ...)
|
||||
return (args);
|
||||
}
|
||||
|
||||
/* Find a flag in the arguments tree. */
|
||||
struct args_entry *
|
||||
args_find(struct args *args, u_char ch)
|
||||
{
|
||||
struct args_entry entry;
|
||||
|
||||
entry.flag = ch;
|
||||
return (RB_FIND(args_tree, &args->tree, &entry));
|
||||
}
|
||||
|
||||
/* Parse an argv and argc into a new argument set. */
|
||||
struct args *
|
||||
args_parse(const char *template, int argc, char **argv)
|
||||
{
|
||||
struct args *args;
|
||||
char *ptr;
|
||||
int opt;
|
||||
|
||||
args = xcalloc(1, sizeof *args);
|
||||
if ((args->flags = bit_alloc(SCHAR_MAX)) == NULL)
|
||||
fatal("bit_alloc failed");
|
||||
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
||||
if (opt < 0 || opt >= SCHAR_MAX)
|
||||
if (opt < 0)
|
||||
continue;
|
||||
if (opt == '?' || (ptr = strchr(template, opt)) == NULL) {
|
||||
free(args->flags);
|
||||
free(args);
|
||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
bit_set(args->flags, opt);
|
||||
if (ptr[1] == ':') {
|
||||
free(args->values[opt]);
|
||||
args->values[opt] = xstrdup(optarg);
|
||||
}
|
||||
args_set(args, opt, optarg);
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
@@ -92,14 +107,17 @@ args_parse(const char *template, int argc, char **argv)
|
||||
void
|
||||
args_free(struct args *args)
|
||||
{
|
||||
u_int i;
|
||||
struct args_entry *entry;
|
||||
struct args_entry *entry1;
|
||||
|
||||
cmd_free_argv(args->argc, args->argv);
|
||||
|
||||
for (i = 0; i < SCHAR_MAX; i++)
|
||||
free(args->values[i]);
|
||||
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
||||
RB_REMOVE(args_tree, &args->tree, entry);
|
||||
free(entry->value);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
free(args->flags);
|
||||
free(args);
|
||||
}
|
||||
|
||||
@@ -107,9 +125,10 @@ args_free(struct args *args)
|
||||
size_t
|
||||
args_print(struct args *args, char *buf, size_t len)
|
||||
{
|
||||
size_t off;
|
||||
int i;
|
||||
const char *quotes;
|
||||
size_t off;
|
||||
int i;
|
||||
const char *quotes;
|
||||
struct args_entry *entry;
|
||||
|
||||
/* There must be at least one byte at the start. */
|
||||
if (len == 0)
|
||||
@@ -118,23 +137,23 @@ args_print(struct args *args, char *buf, size_t len)
|
||||
|
||||
/* Process the flags first. */
|
||||
buf[off++] = '-';
|
||||
for (i = 0; i < SCHAR_MAX; i++) {
|
||||
if (!bit_test(args->flags, i) || args->values[i] != NULL)
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->value != NULL)
|
||||
continue;
|
||||
|
||||
if (off == len - 1) {
|
||||
buf[off] = '\0';
|
||||
return (len);
|
||||
}
|
||||
buf[off++] = i;
|
||||
buf[off++] = entry->flag;
|
||||
buf[off] = '\0';
|
||||
}
|
||||
if (off == 1)
|
||||
buf[--off] = '\0';
|
||||
|
||||
/* Then the flags with arguments. */
|
||||
for (i = 0; i < SCHAR_MAX; i++) {
|
||||
if (!bit_test(args->flags, i) || args->values[i] == NULL)
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->value == NULL)
|
||||
continue;
|
||||
|
||||
if (off >= len) {
|
||||
@@ -142,12 +161,13 @@ args_print(struct args *args, char *buf, size_t len)
|
||||
return (len);
|
||||
}
|
||||
|
||||
if (strchr(args->values[i], ' ') != NULL)
|
||||
if (strchr(entry->value, ' ') != NULL)
|
||||
quotes = "\"";
|
||||
else
|
||||
quotes = "";
|
||||
off += xsnprintf(buf + off, len - off, "%s-%c %s%s%s",
|
||||
off != 0 ? " " : "", i, quotes, args->values[i], quotes);
|
||||
off != 0 ? " " : "", entry->flag, quotes, entry->value,
|
||||
quotes);
|
||||
}
|
||||
|
||||
/* And finally the argument vector. */
|
||||
@@ -172,42 +192,55 @@ args_print(struct args *args, char *buf, size_t len)
|
||||
int
|
||||
args_has(struct args *args, u_char ch)
|
||||
{
|
||||
return (bit_test(args->flags, ch));
|
||||
return (args_find(args, ch) == NULL ? 0 : 1);
|
||||
}
|
||||
|
||||
/* Set argument value. */
|
||||
/* Set argument value in the arguments tree. */
|
||||
void
|
||||
args_set(struct args *args, u_char ch, const char *value)
|
||||
{
|
||||
free(args->values[ch]);
|
||||
struct args_entry *entry;
|
||||
|
||||
/* Replace existing argument. */
|
||||
if ((entry = args_find(args, ch)) != NULL) {
|
||||
free(entry->value);
|
||||
entry->value = NULL;
|
||||
} else {
|
||||
entry = xcalloc(1, sizeof *entry);
|
||||
entry->flag = ch;
|
||||
RB_INSERT(args_tree, &args->tree, entry);
|
||||
}
|
||||
|
||||
if (value != NULL)
|
||||
args->values[ch] = xstrdup(value);
|
||||
else
|
||||
args->values[ch] = NULL;
|
||||
bit_set(args->flags, ch);
|
||||
entry->value = xstrdup(value);
|
||||
}
|
||||
|
||||
/* Get argument value. Will be NULL if it isn't present. */
|
||||
const char *
|
||||
args_get(struct args *args, u_char ch)
|
||||
{
|
||||
return (args->values[ch]);
|
||||
struct args_entry *entry;
|
||||
|
||||
if ((entry = args_find(args, ch)) == NULL)
|
||||
return (NULL);
|
||||
return (entry->value);
|
||||
}
|
||||
|
||||
/* Convert an argument value to a number. */
|
||||
long long
|
||||
args_strtonum(struct args *args,
|
||||
u_char ch, long long minval, long long maxval, char **cause)
|
||||
args_strtonum(struct args *args, u_char ch, long long minval, long long maxval,
|
||||
char **cause)
|
||||
{
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
struct args_entry *entry;
|
||||
|
||||
if (!args_has(args, ch)) {
|
||||
if ((entry = args_find(args, ch)) == NULL) {
|
||||
*cause = xstrdup("missing");
|
||||
return (0);
|
||||
}
|
||||
|
||||
ll = strtonum(args->values[ch], minval, maxval, &errstr);
|
||||
ll = strtonum(entry->value, minval, maxval, &errstr);
|
||||
if (errstr != NULL) {
|
||||
*cause = xstrdup(errstr);
|
||||
return (0);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/bin/sh
|
||||
# $Id$
|
||||
|
||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
||||
fi
|
||||
|
||||
die()
|
||||
{
|
||||
|
||||
207
cfg.c
207
cfg.c
@@ -19,6 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -26,150 +27,140 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Config file parser. Pretty quick and simple, each line is parsed into a
|
||||
* argv array and executed as a command.
|
||||
*/
|
||||
struct cmd_q *cfg_cmd_q;
|
||||
int cfg_finished;
|
||||
int cfg_references;
|
||||
struct causelist cfg_causes;
|
||||
struct client *cfg_client;
|
||||
|
||||
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
|
||||
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
|
||||
|
||||
char *cfg_cause;
|
||||
int cfg_finished;
|
||||
struct causelist cfg_causes = ARRAY_INITIALIZER;
|
||||
|
||||
/* ARGSUSED */
|
||||
void printflike2
|
||||
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||
{
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void printflike2
|
||||
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&cfg_cause, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void printflike2
|
||||
cfg_add_cause(struct causelist *causes, const char *fmt, ...)
|
||||
{
|
||||
char *cause;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&cause, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
ARRAY_ADD(causes, cause);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load configuration file. Returns -1 for an error with a list of messages in
|
||||
* causes. Note that causes must be initialised by the caller!
|
||||
*/
|
||||
int
|
||||
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
|
||||
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
|
||||
{
|
||||
FILE *f;
|
||||
u_int n;
|
||||
char *buf, *line, *cause;
|
||||
size_t len;
|
||||
u_int n, found;
|
||||
char *buf, *copy, *line, *cause1, *msg;
|
||||
size_t len, oldlen;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
enum cmd_retval retval;
|
||||
|
||||
log_debug("loading %s", path);
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
|
||||
xasprintf(cause, "%s: %s", path, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
n = 0;
|
||||
|
||||
n = found = 0;
|
||||
line = NULL;
|
||||
retval = CMD_RETURN_NORMAL;
|
||||
while ((buf = fgetln(f, &len))) {
|
||||
/* Trim \n. */
|
||||
if (buf[len - 1] == '\n')
|
||||
len--;
|
||||
log_debug("%s: %.*s", path, (int)len, buf);
|
||||
|
||||
if (line != NULL)
|
||||
line = xrealloc(line, 1, strlen(line) + len + 1);
|
||||
else {
|
||||
/* Current line is the continuation of the previous one. */
|
||||
if (line != NULL) {
|
||||
oldlen = strlen(line);
|
||||
line = xrealloc(line, 1, oldlen + len + 1);
|
||||
} else {
|
||||
oldlen = 0;
|
||||
line = xmalloc(len + 1);
|
||||
*line = '\0';
|
||||
}
|
||||
|
||||
/* Append buffer to line. strncat will terminate. */
|
||||
strncat(line, buf, len);
|
||||
/* Append current line to the previous. */
|
||||
memcpy(line + oldlen, buf, len);
|
||||
line[oldlen + len] = '\0';
|
||||
n++;
|
||||
|
||||
/* Continuation: get next line? */
|
||||
len = strlen(line);
|
||||
if (len > 0 && line[len - 1] == '\\') {
|
||||
line[len - 1] = '\0';
|
||||
|
||||
/* Ignore escaped backslash at EOL. */
|
||||
if (len > 1 && line[len - 2] != '\\')
|
||||
continue;
|
||||
}
|
||||
buf = line;
|
||||
copy = line;
|
||||
line = NULL;
|
||||
|
||||
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
|
||||
free(buf);
|
||||
if (cause == NULL)
|
||||
continue;
|
||||
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
|
||||
free(cause);
|
||||
/* Skip empty lines. */
|
||||
buf = copy;
|
||||
while (isspace((u_char)*buf))
|
||||
buf++;
|
||||
if (*buf == '\0') {
|
||||
free(copy);
|
||||
continue;
|
||||
} else
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* Parse and run the command. */
|
||||
if (cmd_string_parse(buf, &cmdlist, path, n, &cause1) != 0) {
|
||||
free(copy);
|
||||
if (cause1 == NULL)
|
||||
continue;
|
||||
xasprintf(&msg, "%s:%u: %s", path, n, cause1);
|
||||
ARRAY_ADD(&cfg_causes, msg);
|
||||
free(cause1);
|
||||
continue;
|
||||
}
|
||||
free(copy);
|
||||
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
cfg_cause = 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;
|
||||
|
||||
cfg_cause = NULL;
|
||||
switch (cmd_list_exec(cmdlist, &ctx)) {
|
||||
case CMD_RETURN_YIELD:
|
||||
if (retval != CMD_RETURN_ATTACH)
|
||||
retval = CMD_RETURN_YIELD;
|
||||
break;
|
||||
case CMD_RETURN_ATTACH:
|
||||
retval = CMD_RETURN_ATTACH;
|
||||
break;
|
||||
case CMD_RETURN_ERROR:
|
||||
case CMD_RETURN_NORMAL:
|
||||
break;
|
||||
}
|
||||
cmdq_append(cmdq, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
if (cfg_cause != NULL) {
|
||||
cfg_add_cause(
|
||||
causes, "%s: %d: %s", path, n, cfg_cause);
|
||||
free(cfg_cause);
|
||||
}
|
||||
found++;
|
||||
}
|
||||
if (line != NULL) {
|
||||
cfg_add_cause(causes,
|
||||
"%s: %d: line continuation at end of file", path, n);
|
||||
if (line != NULL)
|
||||
free(line);
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return (retval);
|
||||
return (found);
|
||||
}
|
||||
|
||||
void
|
||||
cfg_default_done(unused struct cmd_q *cmdq)
|
||||
{
|
||||
if (--cfg_references != 0)
|
||||
return;
|
||||
cfg_finished = 1;
|
||||
|
||||
if (!RB_EMPTY(&sessions))
|
||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
||||
|
||||
cmdq_free(cfg_cmd_q);
|
||||
cfg_cmd_q = NULL;
|
||||
|
||||
if (cfg_client != NULL) {
|
||||
/*
|
||||
* The client command queue starts with client_exit set to 1 so
|
||||
* only continue if not empty (that is, we have been delayed
|
||||
* during configuration parsing for long enough that the
|
||||
* MSG_COMMAND has arrived), else the client will exit before
|
||||
* the MSG_COMMAND which might tell it not to.
|
||||
*/
|
||||
if (!TAILQ_EMPTY(&cfg_client->cmdq->queue))
|
||||
cmdq_continue(cfg_client->cmdq);
|
||||
cfg_client->references--;
|
||||
cfg_client = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cfg_show_causes(struct session *s)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
char *cause;
|
||||
u_int i;
|
||||
|
||||
if (s == NULL || ARRAY_EMPTY(&cfg_causes))
|
||||
return;
|
||||
wp = s->curw->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
window_copy_init_for_output(wp);
|
||||
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||
window_copy_add(wp, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
ARRAY_FREE(&cfg_causes);
|
||||
}
|
||||
|
||||
239
client.c
239
client.c
@@ -48,13 +48,14 @@ enum {
|
||||
} client_exitreason = CLIENT_EXIT_NONE;
|
||||
int client_exitval;
|
||||
enum msgtype client_exittype;
|
||||
const char *client_exitsession;
|
||||
int client_attached;
|
||||
|
||||
int client_get_lock(char *);
|
||||
int client_connect(char *, int);
|
||||
void client_send_identify(int);
|
||||
void client_send_environ(void);
|
||||
void client_write_server(enum msgtype, void *, size_t);
|
||||
int client_write_one(enum msgtype, int, const void *, size_t);
|
||||
int client_write_server(enum msgtype, const void *, size_t);
|
||||
void client_update_event(void);
|
||||
void client_signal(int, short, void *);
|
||||
void client_stdin_callback(int, short, void *);
|
||||
@@ -78,8 +79,8 @@ client_get_lock(char *lockfile)
|
||||
if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1)
|
||||
fatal("open failed");
|
||||
|
||||
if (flock(lockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
|
||||
while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
|
||||
if (lockf(lockfd, F_TLOCK, 0) == -1 && errno == EAGAIN) {
|
||||
while (lockf(lockfd, F_LOCK, 0) == -1 && errno == EINTR)
|
||||
/* nothing */;
|
||||
close(lockfd);
|
||||
return (-1);
|
||||
@@ -117,10 +118,15 @@ retry:
|
||||
close(fd);
|
||||
|
||||
xasprintf(&lockfile, "%s.lock", path);
|
||||
if ((lockfd = client_get_lock(lockfile)) == -1)
|
||||
if ((lockfd = client_get_lock(lockfile)) == -1) {
|
||||
free(lockfile);
|
||||
goto retry;
|
||||
if (unlink(path) != 0 && errno != ENOENT)
|
||||
}
|
||||
if (unlink(path) != 0 && errno != ENOENT) {
|
||||
free(lockfile);
|
||||
close(lockfd);
|
||||
return (-1);
|
||||
}
|
||||
fd = server_start(lockfd, lockfile);
|
||||
free(lockfile);
|
||||
close(lockfd);
|
||||
@@ -138,12 +144,24 @@ failed:
|
||||
const char *
|
||||
client_exit_message(void)
|
||||
{
|
||||
static char msg[256];
|
||||
|
||||
switch (client_exitreason) {
|
||||
case CLIENT_EXIT_NONE:
|
||||
break;
|
||||
case CLIENT_EXIT_DETACHED:
|
||||
if (client_exitsession != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "detached "
|
||||
"(from session %s)", client_exitsession);
|
||||
return (msg);
|
||||
}
|
||||
return ("detached");
|
||||
case CLIENT_EXIT_DETACHED_HUP:
|
||||
if (client_exitsession != NULL) {
|
||||
xsnprintf(msg, sizeof msg, "detached and SIGHUP "
|
||||
"(from session %s)", client_exitsession);
|
||||
return (msg);
|
||||
}
|
||||
return ("detached and SIGHUP");
|
||||
case CLIENT_EXIT_LOST_TTY:
|
||||
return ("lost tty");
|
||||
@@ -165,12 +183,13 @@ client_main(int argc, char **argv, int flags)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
struct msg_command_data cmddata;
|
||||
int cmdflags, fd;
|
||||
struct msg_command_data *data;
|
||||
int cmdflags, fd, i;
|
||||
pid_t ppid;
|
||||
enum msgtype msg;
|
||||
char *cause;
|
||||
struct termios tio, saved_tio;
|
||||
size_t size;
|
||||
|
||||
/* Set up the initial command. */
|
||||
cmdflags = 0;
|
||||
@@ -179,7 +198,7 @@ client_main(int argc, char **argv, int flags)
|
||||
cmdflags = CMD_STARTSERVER;
|
||||
} else if (argc == 0) {
|
||||
msg = MSG_COMMAND;
|
||||
cmdflags = CMD_STARTSERVER|CMD_SENDENVIRON|CMD_CANTNEST;
|
||||
cmdflags = CMD_STARTSERVER|CMD_CANTNEST;
|
||||
} else {
|
||||
msg = MSG_COMMAND;
|
||||
|
||||
@@ -188,7 +207,8 @@ client_main(int argc, char **argv, int flags)
|
||||
* later in server) but it is necessary to get the start server
|
||||
* flag.
|
||||
*/
|
||||
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
|
||||
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
fprintf(stderr, "%s\n", cause);
|
||||
return (1);
|
||||
}
|
||||
@@ -196,8 +216,6 @@ client_main(int argc, char **argv, int flags)
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||
cmdflags |= CMD_STARTSERVER;
|
||||
if (cmd->entry->flags & CMD_SENDENVIRON)
|
||||
cmdflags |= CMD_SENDENVIRON;
|
||||
if (cmd->entry->flags & CMD_CANTNEST)
|
||||
cmdflags |= CMD_CANTNEST;
|
||||
}
|
||||
@@ -219,7 +237,8 @@ client_main(int argc, char **argv, int flags)
|
||||
/* Initialise the client socket and start the server. */
|
||||
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "failed to connect to server\n");
|
||||
fprintf(stderr, "failed to connect to server: %s\n",
|
||||
strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -237,7 +256,7 @@ client_main(int argc, char **argv, int flags)
|
||||
setblocking(STDIN_FILENO, 0);
|
||||
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
||||
client_stdin_callback, NULL);
|
||||
if (flags & IDENTIFY_TERMIOS) {
|
||||
if (flags & CLIENT_CONTROLCONTROL) {
|
||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
||||
fprintf(stderr, "tcgetattr failed: %s\n",
|
||||
strerror(errno));
|
||||
@@ -260,26 +279,33 @@ client_main(int argc, char **argv, int flags)
|
||||
/* Establish signal handlers. */
|
||||
set_signals(client_signal);
|
||||
|
||||
/* Send initial environment. */
|
||||
if (cmdflags & CMD_SENDENVIRON)
|
||||
client_send_environ();
|
||||
/* Send identify messages. */
|
||||
client_send_identify(flags);
|
||||
|
||||
/* Send first command. */
|
||||
if (msg == MSG_COMMAND) {
|
||||
/* Fill in command line arguments. */
|
||||
cmddata.pid = environ_pid;
|
||||
cmddata.idx = environ_idx;
|
||||
/* How big is the command? */
|
||||
size = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
size += strlen(argv[i]) + 1;
|
||||
data = xmalloc((sizeof *data) + size);
|
||||
|
||||
/* Prepare command for server. */
|
||||
cmddata.argc = argc;
|
||||
if (cmd_pack_argv(
|
||||
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
||||
data->argc = argc;
|
||||
if (cmd_pack_argv(argc, argv, (char*)(data + 1), size) != 0) {
|
||||
fprintf(stderr, "command too long\n");
|
||||
free(data);
|
||||
return (1);
|
||||
}
|
||||
size += sizeof *data;
|
||||
|
||||
client_write_server(msg, &cmddata, sizeof cmddata);
|
||||
/* Send the command. */
|
||||
if (client_write_server(msg, data, size) != 0) {
|
||||
fprintf(stderr, "failed to send command\n");
|
||||
free(data);
|
||||
return (1);
|
||||
}
|
||||
free(data);
|
||||
} else if (msg == MSG_SHELL)
|
||||
client_write_server(msg, NULL, 0);
|
||||
|
||||
@@ -295,57 +321,75 @@ client_main(int argc, char **argv, int flags)
|
||||
ppid = getppid();
|
||||
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
||||
kill(ppid, SIGHUP);
|
||||
} else if (flags & IDENTIFY_TERMIOS)
|
||||
} else if (flags & CLIENT_CONTROLCONTROL) {
|
||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
||||
printf("%%exit %s\n", client_exit_message());
|
||||
else
|
||||
printf("%%exit\n");
|
||||
printf("\033\\");
|
||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||
}
|
||||
setblocking(STDIN_FILENO, 1);
|
||||
return (client_exitval);
|
||||
}
|
||||
|
||||
/* Send identify message to server with the file descriptors. */
|
||||
/* Send identify messages to server. */
|
||||
void
|
||||
client_send_identify(int flags)
|
||||
{
|
||||
struct msg_identify_data data;
|
||||
char *term;
|
||||
int fd;
|
||||
const char *s;
|
||||
char **ss;
|
||||
int fd;
|
||||
|
||||
data.flags = flags;
|
||||
client_write_one(MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
|
||||
|
||||
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
|
||||
*data.cwd = '\0';
|
||||
if ((s = getenv("TERM")) == NULL)
|
||||
s = "";
|
||||
client_write_one(MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
|
||||
|
||||
term = getenv("TERM");
|
||||
if (term == NULL ||
|
||||
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
|
||||
*data.term = '\0';
|
||||
if ((s = ttyname(STDIN_FILENO)) == NULL)
|
||||
s = "";
|
||||
client_write_one(MSG_IDENTIFY_TTYNAME, -1, s, strlen(s) + 1);
|
||||
|
||||
if ((fd = open(".", O_RDONLY)) == -1)
|
||||
fd = open("/", O_RDONLY);
|
||||
client_write_one(MSG_IDENTIFY_CWD, fd, NULL, 0);
|
||||
|
||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||
fatal("dup failed");
|
||||
imsg_compose(&client_ibuf,
|
||||
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
|
||||
client_write_one(MSG_IDENTIFY_STDIN, fd, NULL, 0);
|
||||
|
||||
for (ss = environ; *ss != NULL; ss++)
|
||||
client_write_one(MSG_IDENTIFY_ENVIRON, -1, *ss, strlen(*ss) + 1);
|
||||
|
||||
client_write_one(MSG_IDENTIFY_DONE, -1, NULL, 0);
|
||||
|
||||
client_update_event();
|
||||
}
|
||||
|
||||
/* Forward entire environment to server. */
|
||||
void
|
||||
client_send_environ(void)
|
||||
/* Helper to send one message. */
|
||||
int
|
||||
client_write_one(enum msgtype type, int fd, const void *buf, size_t len)
|
||||
{
|
||||
struct msg_environ_data data;
|
||||
char **var;
|
||||
int retval;
|
||||
|
||||
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);
|
||||
}
|
||||
retval = imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, fd,
|
||||
(void*)buf, len);
|
||||
if (retval != 1)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Write a message to the server without a file descriptor. */
|
||||
void
|
||||
client_write_server(enum msgtype type, void *buf, size_t len)
|
||||
int
|
||||
client_write_server(enum msgtype type, const void *buf, size_t len)
|
||||
{
|
||||
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
||||
client_update_event();
|
||||
int retval;
|
||||
|
||||
retval = client_write_one(type, -1, buf, len);
|
||||
if (retval == 0)
|
||||
client_update_event();
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* Update client event based on whether it needs to read or read and write. */
|
||||
@@ -364,7 +408,6 @@ client_update_event(void)
|
||||
}
|
||||
|
||||
/* Callback to handle signals in the client. */
|
||||
/* ARGSUSED */
|
||||
void
|
||||
client_signal(int sig, unused short events, unused void *data)
|
||||
{
|
||||
@@ -411,7 +454,6 @@ client_signal(int sig, unused short events, unused void *data)
|
||||
}
|
||||
|
||||
/* Callback for client imsg read events. */
|
||||
/* ARGSUSED */
|
||||
void
|
||||
client_callback(unused int fd, short events, void *data)
|
||||
{
|
||||
@@ -432,7 +474,7 @@ client_callback(unused int fd, short events, void *data)
|
||||
}
|
||||
|
||||
if (events & EV_WRITE) {
|
||||
if (msgbuf_write(&client_ibuf.w) < 0)
|
||||
if (msgbuf_write(&client_ibuf.w) < 0 && errno != EAGAIN)
|
||||
goto lost_server;
|
||||
}
|
||||
|
||||
@@ -446,7 +488,6 @@ lost_server:
|
||||
}
|
||||
|
||||
/* Callback for client stdin read events. */
|
||||
/* ARGSUSED */
|
||||
void
|
||||
client_stdin_callback(unused int fd, unused short events, unused void *data1)
|
||||
{
|
||||
@@ -482,33 +523,33 @@ client_write(int fd, const char *data, size_t size)
|
||||
|
||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||
int
|
||||
client_dispatch_wait(void *data)
|
||||
client_dispatch_wait(void *data0)
|
||||
{
|
||||
struct imsg imsg;
|
||||
ssize_t n, datalen;
|
||||
struct msg_shell_data shelldata;
|
||||
struct msg_exit_data exitdata;
|
||||
struct msg_stdout_data stdoutdata;
|
||||
struct msg_stderr_data stderrdata;
|
||||
const char *shellcmd = data;
|
||||
struct imsg imsg;
|
||||
char *data;
|
||||
ssize_t n, datalen;
|
||||
struct msg_stdout_data stdoutdata;
|
||||
struct msg_stderr_data stderrdata;
|
||||
int retval;
|
||||
|
||||
for (;;) {
|
||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||
fatalx("imsg_get failed");
|
||||
if (n == 0)
|
||||
return (0);
|
||||
|
||||
data = imsg.data;
|
||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||
|
||||
log_debug("got %d from server", imsg.hdr.type);
|
||||
switch (imsg.hdr.type) {
|
||||
case MSG_EXIT:
|
||||
case MSG_SHUTDOWN:
|
||||
if (datalen != sizeof exitdata) {
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
} else {
|
||||
memcpy(&exitdata, imsg.data, sizeof exitdata);
|
||||
client_exitval = exitdata.retcode;
|
||||
if (datalen != sizeof retval && datalen != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
if (datalen == sizeof retval) {
|
||||
memcpy(&retval, data, sizeof retval);
|
||||
client_exitval = retval;
|
||||
}
|
||||
imsg_free(&imsg);
|
||||
return (-1);
|
||||
@@ -518,6 +559,7 @@ client_dispatch_wait(void *data)
|
||||
|
||||
event_del(&client_stdin);
|
||||
client_attached = 1;
|
||||
client_write_server(MSG_RESIZE, NULL, 0);
|
||||
break;
|
||||
case MSG_STDIN:
|
||||
if (datalen != 0)
|
||||
@@ -527,17 +569,19 @@ client_dispatch_wait(void *data)
|
||||
break;
|
||||
case MSG_STDOUT:
|
||||
if (datalen != sizeof stdoutdata)
|
||||
fatalx("bad MSG_STDOUT");
|
||||
memcpy(&stdoutdata, imsg.data, sizeof stdoutdata);
|
||||
fatalx("bad MSG_STDOUT size");
|
||||
memcpy(&stdoutdata, data, sizeof stdoutdata);
|
||||
|
||||
client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size);
|
||||
client_write(STDOUT_FILENO, stdoutdata.data,
|
||||
stdoutdata.size);
|
||||
break;
|
||||
case MSG_STDERR:
|
||||
if (datalen != sizeof stderrdata)
|
||||
fatalx("bad MSG_STDERR");
|
||||
memcpy(&stderrdata, imsg.data, sizeof stderrdata);
|
||||
fatalx("bad MSG_STDERR size");
|
||||
memcpy(&stderrdata, data, sizeof stderrdata);
|
||||
|
||||
client_write(STDERR_FILENO, stderrdata.data, stderrdata.size);
|
||||
client_write(STDERR_FILENO, stderrdata.data,
|
||||
stderrdata.size);
|
||||
break;
|
||||
case MSG_VERSION:
|
||||
if (datalen != 0)
|
||||
@@ -551,23 +595,19 @@ client_dispatch_wait(void *data)
|
||||
imsg_free(&imsg);
|
||||
return (-1);
|
||||
case MSG_SHELL:
|
||||
if (datalen != sizeof shelldata)
|
||||
fatalx("bad MSG_SHELL size");
|
||||
memcpy(&shelldata, imsg.data, sizeof shelldata);
|
||||
shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_SHELL string");
|
||||
|
||||
clear_signals(0);
|
||||
|
||||
shell_exec(shelldata.shell, shellcmd);
|
||||
shell_exec(data, data0);
|
||||
/* NOTREACHED */
|
||||
case MSG_DETACH:
|
||||
case MSG_DETACHKILL:
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
break;
|
||||
case MSG_EXITED:
|
||||
imsg_free(&imsg);
|
||||
return (-1);
|
||||
default:
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
imsg_free(&imsg);
|
||||
@@ -575,29 +615,31 @@ client_dispatch_wait(void *data)
|
||||
}
|
||||
|
||||
/* Dispatch imsgs in attached state (after MSG_READY). */
|
||||
/* ARGSUSED */
|
||||
int
|
||||
client_dispatch_attached(void)
|
||||
{
|
||||
struct imsg imsg;
|
||||
struct msg_lock_data lockdata;
|
||||
struct sigaction sigact;
|
||||
ssize_t n, datalen;
|
||||
struct imsg imsg;
|
||||
struct sigaction sigact;
|
||||
char *data;
|
||||
ssize_t n, datalen;
|
||||
|
||||
for (;;) {
|
||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||
fatalx("imsg_get failed");
|
||||
if (n == 0)
|
||||
return (0);
|
||||
|
||||
data = imsg.data;
|
||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||
|
||||
log_debug("got %d from server", imsg.hdr.type);
|
||||
switch (imsg.hdr.type) {
|
||||
case MSG_DETACHKILL:
|
||||
case MSG_DETACH:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_DETACH size");
|
||||
case MSG_DETACHKILL:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_DETACH string");
|
||||
|
||||
client_exitsession = xstrdup(data);
|
||||
client_exittype = imsg.hdr.type;
|
||||
if (imsg.hdr.type == MSG_DETACHKILL)
|
||||
client_exitreason = CLIENT_EXIT_DETACHED_HUP;
|
||||
@@ -606,8 +648,7 @@ client_dispatch_attached(void)
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
break;
|
||||
case MSG_EXIT:
|
||||
if (datalen != 0 &&
|
||||
datalen != sizeof (struct msg_exit_data))
|
||||
if (datalen != 0 && datalen != sizeof (int))
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
client_write_server(MSG_EXITING, NULL, 0);
|
||||
@@ -640,16 +681,12 @@ client_dispatch_attached(void)
|
||||
kill(getpid(), SIGTSTP);
|
||||
break;
|
||||
case MSG_LOCK:
|
||||
if (datalen != sizeof lockdata)
|
||||
fatalx("bad MSG_LOCK size");
|
||||
memcpy(&lockdata, imsg.data, sizeof lockdata);
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_LOCK string");
|
||||
|
||||
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
|
||||
system(lockdata.cmd);
|
||||
system(data);
|
||||
client_write_server(MSG_UNLOCK, NULL, 0);
|
||||
break;
|
||||
default:
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
imsg_free(&imsg);
|
||||
|
||||
15
clock.c
15
clock.c
@@ -103,13 +103,20 @@ clock_draw(struct screen_write_ctx *ctx, int colour, int style)
|
||||
struct grid_cell gc;
|
||||
char tim[64], *ptr;
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
u_int i, j, x, y, idx;
|
||||
|
||||
t = time(NULL);
|
||||
if (style == 0)
|
||||
strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
|
||||
else
|
||||
strftime(tim, sizeof tim, "%H:%M", localtime(&t));
|
||||
tm = localtime(&t);
|
||||
if (style == 0) {
|
||||
strftime(tim, sizeof tim, "%l:%M ", localtime(&t));
|
||||
if (tm->tm_hour >= 12)
|
||||
strlcat(tim, "PM", sizeof tim);
|
||||
else
|
||||
strlcat(tim, "AM", sizeof tim);
|
||||
} else
|
||||
strftime(tim, sizeof tim, "%H:%M", tm);
|
||||
|
||||
|
||||
screen_write_clearscreen(ctx);
|
||||
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,41 +30,65 @@
|
||||
* Attach existing session to the current terminal.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_attach_session_entry = {
|
||||
"attach-session", "attach",
|
||||
"drt:", 0, 0,
|
||||
"[-dr] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON,
|
||||
NULL,
|
||||
"c:drt:", 0, 0,
|
||||
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_CANTNEST|CMD_STARTSERVER,
|
||||
NULL,
|
||||
cmd_attach_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
||||
const char *cflag)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
const char *update;
|
||||
char *cause;
|
||||
u_int i;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
struct winlink *wl = NULL;
|
||||
struct window *w = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
const char *update;
|
||||
char *cause;
|
||||
u_int i;
|
||||
int fd;
|
||||
struct format_tree *ft;
|
||||
char *cp;
|
||||
|
||||
if (RB_EMPTY(&sessions)) {
|
||||
ctx->error(ctx, "no sessions");
|
||||
cmdq_error(cmdq, "no sessions");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (tflag == NULL) {
|
||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = cmd_lookup_windowid(tflag);
|
||||
if (w == NULL && (wp = cmd_lookup_paneid(tflag)) != NULL)
|
||||
w = wp->window;
|
||||
if (w != NULL)
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
}
|
||||
|
||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||
if (cmdq->client == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (ctx->cmdclient == NULL) {
|
||||
if (args_has(self->args, 'd')) {
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
session_set_current(s, wl);
|
||||
}
|
||||
|
||||
if (cmdq->client->session != NULL) {
|
||||
if (dflag) {
|
||||
/*
|
||||
* Can't use server_write_session in case attaching to
|
||||
* the same session as currently attached to.
|
||||
@@ -69,43 +97,99 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
if (c == ctx->curclient)
|
||||
if (c == cmdq->client)
|
||||
continue;
|
||||
server_write_client(c, MSG_DETACH, NULL, 0);
|
||||
server_write_client(c, MSG_DETACH,
|
||||
c->session->name,
|
||||
strlen(c->session->name) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
ctx->curclient->session = s;
|
||||
notify_attached_session_changed(ctx->curclient);
|
||||
if (cflag != NULL) {
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, s->curw);
|
||||
format_window_pane(ft, s->curw->window->active);
|
||||
cp = format_expand(ft, cflag);
|
||||
format_free(ft);
|
||||
|
||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
||||
free(cp);
|
||||
if (fd == -1) {
|
||||
cmdq_error(cmdq, "bad working directory: %s",
|
||||
strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
close(s->cwd);
|
||||
s->cwd = fd;
|
||||
}
|
||||
|
||||
cmdq->client->session = s;
|
||||
notify_attached_session_changed(cmdq->client);
|
||||
session_update_activity(s);
|
||||
server_redraw_client(ctx->curclient);
|
||||
server_redraw_client(cmdq->client);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
} else {
|
||||
if (server_client_open(ctx->cmdclient, s, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
if (server_client_open(cmdq->client, s, &cause) != 0) {
|
||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'r'))
|
||||
ctx->cmdclient->flags |= CLIENT_READONLY;
|
||||
if (cflag != NULL) {
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, s->curw);
|
||||
format_window_pane(ft, s->curw->window->active);
|
||||
cp = format_expand(ft, cflag);
|
||||
format_free(ft);
|
||||
|
||||
if (args_has(self->args, 'd'))
|
||||
server_write_session(s, MSG_DETACH, NULL, 0);
|
||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
||||
free(cp);
|
||||
if (fd == -1) {
|
||||
cmdq_error(cmdq, "bad working directory: %s",
|
||||
strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
close(s->cwd);
|
||||
s->cwd = fd;
|
||||
}
|
||||
|
||||
ctx->cmdclient->session = s;
|
||||
notify_attached_session_changed(ctx->cmdclient);
|
||||
session_update_activity(s);
|
||||
server_write_ready(ctx->cmdclient);
|
||||
if (rflag)
|
||||
cmdq->client->flags |= CLIENT_READONLY;
|
||||
|
||||
if (dflag) {
|
||||
server_write_session(s, MSG_DETACH, s->name,
|
||||
strlen(s->name) + 1);
|
||||
}
|
||||
|
||||
update = options_get_string(&s->options, "update-environment");
|
||||
environ_update(update, &ctx->cmdclient->environ, &s->environ);
|
||||
environ_update(update, &cmdq->client->environ, &s->environ);
|
||||
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
cmdq->client->session = s;
|
||||
notify_attached_session_changed(cmdq->client);
|
||||
session_update_activity(s);
|
||||
server_redraw_client(cmdq->client);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
|
||||
server_write_ready(cmdq->client);
|
||||
cmdq->client_exit = 0;
|
||||
}
|
||||
recalculate_sizes();
|
||||
server_update_socket();
|
||||
|
||||
return (CMD_RETURN_ATTACH);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
return (cmd_attach_session(cmdq, args_get(args, 't'),
|
||||
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c')));
|
||||
}
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
* Bind a key to a command, this recurses through cmd_*.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_bind_key_check(struct args *);
|
||||
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int);
|
||||
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_q *, int);
|
||||
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
"bind-key", "bind",
|
||||
@@ -38,43 +37,42 @@ const struct cmd_entry cmd_bind_key_entry = {
|
||||
"[-cnr] [-t key-table] key command [arguments]",
|
||||
0,
|
||||
NULL,
|
||||
cmd_bind_key_check,
|
||||
cmd_bind_key_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_bind_key_check(struct args *args)
|
||||
{
|
||||
if (args_has(args, 't')) {
|
||||
if (args->argc != 2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if (args->argc < 2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
char *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
int key;
|
||||
|
||||
if (args_has(args, 't')) {
|
||||
if (args->argc != 2 && args->argc != 3) {
|
||||
cmdq_error(cmdq, "not enough arguments");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (args->argc < 2) {
|
||||
cmdq_error(cmdq, "not enough arguments");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
if (key == KEYC_NONE) {
|
||||
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_bind_key_table(self, ctx, key));
|
||||
return (cmd_bind_key_table(self, cmdq, key));
|
||||
|
||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
|
||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
|
||||
&cause);
|
||||
if (cmdlist == NULL) {
|
||||
ctx->error(ctx, "%s", cause);
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -86,36 +84,50 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||
cmd_bind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
enum mode_key_cmd cmd;
|
||||
const char *arg;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
|
||||
if (cmd == MODEKEY_NONE) {
|
||||
ctx->error(ctx, "unknown command: %s", args->argv[1]);
|
||||
cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (cmd != MODEKEYCOPY_COPYPIPE) {
|
||||
if (args->argc != 2) {
|
||||
cmdq_error(cmdq, "no argument allowed");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
arg = NULL;
|
||||
} else {
|
||||
if (args->argc != 3) {
|
||||
cmdq_error(cmdq, "no argument given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
arg = args->argv[2];
|
||||
}
|
||||
|
||||
mtmp.key = key;
|
||||
mtmp.mode = !!args_has(args, 'c');
|
||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||
mbind->cmd = cmd;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
|
||||
mbind = xmalloc(sizeof *mbind);
|
||||
mbind->key = mtmp.key;
|
||||
mbind->mode = mtmp.mode;
|
||||
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||
}
|
||||
mbind = xmalloc(sizeof *mbind);
|
||||
mbind->key = mtmp.key;
|
||||
mbind->mode = mtmp.mode;
|
||||
mbind->cmd = cmd;
|
||||
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||
mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Break pane off into a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_break_pane_entry = {
|
||||
"break-pane", "breakp",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_break_pane_entry = {
|
||||
"[-dP] [-F format] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_break_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -54,15 +53,17 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
const char *template;
|
||||
char *cp;
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
ctx->error(ctx, "can't break with only one pane");
|
||||
cmdq_error(cmdq, "can't break with only one pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
w = wl->window;
|
||||
server_unzoom_window(w);
|
||||
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
if (wp == w->active) {
|
||||
w->active = w->last;
|
||||
@@ -82,7 +83,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
name = default_window_name(w);
|
||||
window_set_name(w, name);
|
||||
free(name);
|
||||
layout_init(w);
|
||||
layout_init(w, wp);
|
||||
|
||||
base_idx = options_get_number(&s->options, "base-index");
|
||||
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||
@@ -93,19 +94,18 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
server_status_session_group(s);
|
||||
|
||||
if (args_has(args, 'P')) {
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(ctx, NULL)) != NULL)
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, wl);
|
||||
format_window_pane(ft, wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", cp);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -24,40 +24,90 @@
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Write the entire contents of a pane to a buffer.
|
||||
* Write the entire contents of a pane to a buffer or stdout.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
||||
char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
||||
size_t *);
|
||||
char *cmd_capture_pane_history(struct args *, struct cmd_q *,
|
||||
struct window_pane *, size_t *);
|
||||
|
||||
const struct cmd_entry cmd_capture_pane_entry = {
|
||||
"capture-pane", "capturep",
|
||||
"b:E:S:t:", 0, 0,
|
||||
"[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]",
|
||||
"ab:CeE:JpPqS:t:", 0, 0,
|
||||
"[-aCeJpPq] [-b buffer-index] [-E end-line] [-S start-line]"
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_capture_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *
|
||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
||||
{
|
||||
buf = xrealloc(buf, 1, *len + linelen + 1);
|
||||
memcpy(buf + *len, line, linelen);
|
||||
*len += linelen;
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
||||
size_t *len)
|
||||
{
|
||||
char *buf, *line, tmp[5];
|
||||
size_t linelen;
|
||||
u_int i;
|
||||
|
||||
if (wp->ictx.since_ground == NULL)
|
||||
return (xstrdup(""));
|
||||
|
||||
line = EVBUFFER_DATA(wp->ictx.since_ground);
|
||||
linelen = EVBUFFER_LENGTH(wp->ictx.since_ground);
|
||||
|
||||
buf = xstrdup("");
|
||||
if (args_has(args, 'C')) {
|
||||
for (i = 0; i < linelen; i++) {
|
||||
if (line[i] >= ' ') {
|
||||
tmp[0] = line[i];
|
||||
tmp[1] = '\0';
|
||||
} else
|
||||
xsnprintf(tmp, sizeof tmp, "\\%03o", line[i]);
|
||||
buf = cmd_capture_pane_append(buf, len, tmp,
|
||||
strlen(tmp));
|
||||
}
|
||||
} else
|
||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
|
||||
struct window_pane *wp, size_t *len)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
char *buf, *line, *cause;
|
||||
struct screen *s;
|
||||
struct grid *gd;
|
||||
int buffer, n;
|
||||
u_int i, limit, top, bottom, tmp;
|
||||
size_t len, linelen;
|
||||
const struct grid_line *gl;
|
||||
struct grid_cell *gc = NULL;
|
||||
int n, with_codes, escape_c0, join_lines;
|
||||
u_int i, sx, top, bottom, tmp;
|
||||
char *cause, *buf, *line;
|
||||
size_t linelen;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
s = &wp->base;
|
||||
gd = s->grid;
|
||||
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
sx = screen_size_x(&wp->base);
|
||||
if (args_has(args, 'a')) {
|
||||
gd = wp->saved_grid;
|
||||
if (gd == NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "no alternate screen");
|
||||
return (NULL);
|
||||
}
|
||||
return (xstrdup(""));
|
||||
}
|
||||
} else
|
||||
gd = wp->base.grid;
|
||||
|
||||
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
@@ -87,37 +137,80 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
top = tmp;
|
||||
}
|
||||
|
||||
with_codes = args_has(args, 'e');
|
||||
escape_c0 = args_has(args, 'C');
|
||||
join_lines = args_has(args, 'J');
|
||||
|
||||
buf = NULL;
|
||||
for (i = top; i <= bottom; i++) {
|
||||
line = grid_string_cells(s->grid, 0, i, screen_size_x(s));
|
||||
linelen = strlen(line);
|
||||
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
||||
escape_c0, !join_lines);
|
||||
linelen = strlen(line);
|
||||
|
||||
buf = xrealloc(buf, 1, len + linelen + 1);
|
||||
memcpy(buf + len, line, linelen);
|
||||
len += linelen;
|
||||
buf[len++] = '\n';
|
||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
||||
|
||||
free(line);
|
||||
gl = grid_peek_line(gd, i);
|
||||
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
|
||||
buf[(*len)++] = '\n';
|
||||
|
||||
free(line);
|
||||
}
|
||||
return (buf);
|
||||
}
|
||||
|
||||
limit = options_get_number(&global_options, "buffer-limit");
|
||||
enum cmd_retval
|
||||
cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct window_pane *wp;
|
||||
char *buf, *cause;
|
||||
int buffer;
|
||||
u_int limit;
|
||||
size_t len;
|
||||
|
||||
if (!args_has(args, 'b')) {
|
||||
paste_add(&global_buffers, buf, len, limit);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
free(buf);
|
||||
free(cause);
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
free(buf);
|
||||
len = 0;
|
||||
if (args_has(args, 'P'))
|
||||
buf = cmd_capture_pane_pending(args, wp, &len);
|
||||
else
|
||||
buf = cmd_capture_pane_history(args, cmdq, wp, &len);
|
||||
if (buf == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'p')) {
|
||||
c = cmdq->client;
|
||||
if (c == NULL ||
|
||||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) {
|
||||
cmdq_error(cmdq, "can't write to stdout");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
evbuffer_add(c->stdout_data, buf, len);
|
||||
if (args_has(args, 'P') && len > 0)
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_push_stdout(c);
|
||||
} else {
|
||||
limit = options_get_number(&global_options, "buffer-limit");
|
||||
if (!args_has(args, 'b')) {
|
||||
paste_add(&global_buffers, buf, len, limit);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(buf);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
free(buf);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -27,10 +27,7 @@
|
||||
* Enter choice mode to choose a buffer.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_buffer_callback(struct window_choose_data *);
|
||||
void cmd_choose_buffer_free(struct window_choose_data *);
|
||||
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
"choose-buffer", NULL,
|
||||
@@ -38,14 +35,14 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct window_choose_data *cdata;
|
||||
struct winlink *wl;
|
||||
struct paste_buffer *pb;
|
||||
@@ -53,15 +50,15 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
const char *template;
|
||||
u_int idx;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
if ((c = cmd_current_client(cmdq)) == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = CHOOSE_BUFFER_TEMPLATE;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (paste_get_top(&global_buffers) == NULL)
|
||||
@@ -77,9 +74,8 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
idx = 0;
|
||||
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
|
||||
cdata = window_choose_data_create(ctx);
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = idx - 1;
|
||||
cdata->client->references++;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
format_add(cdata->ft, "line", "%u", idx - 1);
|
||||
@@ -93,34 +89,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
free(action);
|
||||
|
||||
window_choose_ready(wl->window->active,
|
||||
0, cmd_choose_buffer_callback, cmd_choose_buffer_free);
|
||||
window_choose_ready(wl->window->active, 0, NULL);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_buffer_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
window_choose_ctx(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_buffer_free(struct window_choose_data *data)
|
||||
{
|
||||
struct window_choose_data *cdata = data;
|
||||
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
cdata->client->references--;
|
||||
|
||||
free(cdata->command);
|
||||
free(cdata->ft_template);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
* Enter choice mode to choose a client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_choose_client_callback(struct window_choose_data *);
|
||||
void cmd_choose_client_free(struct window_choose_data *);
|
||||
|
||||
const struct cmd_entry cmd_choose_client_entry = {
|
||||
"choose-client", NULL,
|
||||
@@ -38,32 +37,31 @@ const struct cmd_entry cmd_choose_client_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_client_exec
|
||||
};
|
||||
|
||||
struct cmd_choose_client_data {
|
||||
struct client *client;
|
||||
char *template;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct client *c1;
|
||||
struct window_choose_data *cdata;
|
||||
struct winlink *wl;
|
||||
struct client *c;
|
||||
const char *template;
|
||||
char *action;
|
||||
u_int i, idx, cur;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
if ((c = cmd_current_client(cmdq)) == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
@@ -79,30 +77,29 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
cur = idx = 0;
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
c1 = ARRAY_ITEM(&clients, i);
|
||||
if (c1 == NULL || c1->session == NULL || c1->tty.path == NULL)
|
||||
continue;
|
||||
if (c == ctx->curclient)
|
||||
if (c1 == cmdq->client)
|
||||
cur = idx;
|
||||
idx++;
|
||||
|
||||
cdata = window_choose_data_create(ctx);
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = i;
|
||||
cdata->client->references++;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
format_add(cdata->ft, "line", "%u", i);
|
||||
format_session(cdata->ft, c->session);
|
||||
format_client(cdata->ft, c);
|
||||
format_session(cdata->ft, c1->session);
|
||||
format_client(cdata->ft, c1);
|
||||
|
||||
cdata->command = cmd_template_replace(action, c->tty.path, 1);
|
||||
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
}
|
||||
free(action);
|
||||
|
||||
window_choose_ready(wl->window->active,
|
||||
cur, cmd_choose_client_callback, cmd_choose_client_free);
|
||||
window_choose_ready(wl->window->active, cur,
|
||||
cmd_choose_client_callback);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -114,7 +111,7 @@ cmd_choose_client_callback(struct window_choose_data *cdata)
|
||||
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
if (cdata->start_client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
if (cdata->idx > ARRAY_LENGTH(&clients) - 1)
|
||||
@@ -123,19 +120,5 @@ cmd_choose_client_callback(struct window_choose_data *cdata)
|
||||
if (c == NULL || c->session == NULL)
|
||||
return;
|
||||
|
||||
window_choose_ctx(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_client_free(struct window_choose_data *cdata)
|
||||
{
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
cdata->client->references--;
|
||||
|
||||
free(cdata->ft_template);
|
||||
free(cdata->command);
|
||||
format_free(cdata->ft);
|
||||
free(cdata);
|
||||
window_choose_data_run(cdata);
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@
|
||||
* Enter choose mode to choose a custom list.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_list_callback(struct window_choose_data *);
|
||||
void cmd_choose_list_free(struct window_choose_data *);
|
||||
enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_choose_list_entry = {
|
||||
"choose-list", NULL,
|
||||
@@ -42,28 +39,28 @@ const struct cmd_entry cmd_choose_list_entry = {
|
||||
"[-l items] " CMD_TARGET_WINDOW_USAGE "[template]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_list_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_choose_list_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct winlink *wl;
|
||||
const char *list1;
|
||||
char *template, *item, *copy, *list;
|
||||
u_int idx;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
if ((c = cmd_current_client(cmdq)) == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((list1 = args_get(args, 'l')) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
@@ -80,7 +77,7 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
if (*item == '\0') /* no empty entries */
|
||||
continue;
|
||||
window_choose_add_item(wl->window->active, ctx, wl, item,
|
||||
window_choose_add_item(wl->window->active, c, wl, item,
|
||||
template, idx);
|
||||
idx++;
|
||||
}
|
||||
@@ -92,32 +89,9 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
window_choose_ready(wl->window->active, 0, cmd_choose_list_callback,
|
||||
cmd_choose_list_free);
|
||||
window_choose_ready(wl->window->active, 0, NULL);
|
||||
|
||||
free(template);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_list_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
if (cdata == NULL || (cdata->client->flags & CLIENT_DEAD))
|
||||
return;
|
||||
|
||||
window_choose_ctx(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_list_free(struct window_choose_data *cdata)
|
||||
{
|
||||
cdata->session->references--;
|
||||
cdata->client->references--;
|
||||
|
||||
free(cdata->ft_template);
|
||||
free(cdata->command);
|
||||
format_free(cdata->ft);
|
||||
free(cdata);
|
||||
|
||||
}
|
||||
|
||||
@@ -32,19 +32,15 @@
|
||||
* Enter choice mode to choose a session and/or window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
void cmd_choose_tree_callback(struct window_choose_data *);
|
||||
void cmd_choose_tree_free(struct window_choose_data *);
|
||||
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_choose_tree_entry = {
|
||||
"choose-tree", NULL,
|
||||
"S:W:swb:c:t:", 0, 1,
|
||||
"[-sw] [-b session-template] [-c window template] [-S format] " \
|
||||
"S:W:swub:c:t:", 0, 1,
|
||||
"[-suw] [-b session-template] [-c window template] [-S format] " \
|
||||
"[-W format] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
@@ -54,7 +50,6 @@ const struct cmd_entry cmd_choose_session_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
@@ -64,16 +59,16 @@ const struct cmd_entry cmd_choose_window_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl, *wm;
|
||||
struct session *s, *s2;
|
||||
struct client *c;
|
||||
struct window_choose_data *wcd = NULL;
|
||||
const char *ses_template, *win_template;
|
||||
char *final_win_action, *cur_win_template;
|
||||
@@ -86,14 +81,12 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
ses_template = win_template = NULL;
|
||||
ses_action = win_action = NULL;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
if ((c = cmd_current_client(cmdq)) == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
s = ctx->curclient->session;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
@@ -175,7 +168,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
|
||||
wcd = window_choose_add_session(wl->window->active,
|
||||
ctx, s2, ses_template, (char *)ses_action, idx_ses);
|
||||
c, s2, ses_template, ses_action, idx_ses);
|
||||
|
||||
/* If we're just choosing sessions, skip choosing windows. */
|
||||
if (sflag && !wflag) {
|
||||
@@ -204,8 +197,9 @@ windows_only:
|
||||
cur_win = idx_ses;
|
||||
}
|
||||
|
||||
xasprintf(&final_win_action, "%s ; %s", win_action,
|
||||
wcd ? wcd->command : "");
|
||||
xasprintf(&final_win_action, "%s %s %s",
|
||||
wcd != NULL ? wcd->command : "",
|
||||
wcd != NULL ? ";" : "", win_action);
|
||||
|
||||
if (win_ses != win_max)
|
||||
cur_win_template = final_win_template_middle;
|
||||
@@ -213,12 +207,13 @@ windows_only:
|
||||
cur_win_template = final_win_template_last;
|
||||
|
||||
window_choose_add_window(wl->window->active,
|
||||
ctx, s2, wm, cur_win_template,
|
||||
c, s2, wm, cur_win_template,
|
||||
final_win_action,
|
||||
(wflag && !sflag) ? win_ses : idx_ses);
|
||||
|
||||
free(final_win_action);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're just drawing windows, don't consider moving on to
|
||||
* other sessions as we only list windows in this session.
|
||||
@@ -229,33 +224,12 @@ windows_only:
|
||||
free(final_win_template_middle);
|
||||
free(final_win_template_last);
|
||||
|
||||
window_choose_ready(wl->window->active, cur_win,
|
||||
cmd_choose_tree_callback, cmd_choose_tree_free);
|
||||
window_choose_ready(wl->window->active, cur_win, NULL);
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
window_choose_expand_all(wl->window->active);
|
||||
window_choose_set_current(wl->window->active, cur_win);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_tree_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
if (cdata->client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
window_choose_ctx(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_choose_tree_free(struct window_choose_data *cdata)
|
||||
{
|
||||
cdata->session->references--;
|
||||
cdata->client->references--;
|
||||
|
||||
free(cdata->ft_template);
|
||||
free(cdata->command);
|
||||
format_free(cdata->ft);
|
||||
free(cdata);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Clear pane history.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_clear_history_entry = {
|
||||
"clear-history", "clearhist",
|
||||
@@ -32,18 +32,17 @@ const struct cmd_entry cmd_clear_history_entry = {
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_clear_history_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_clear_history_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
struct grid *gd;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
gd = wp->base.grid;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Enter clock mode.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_clock_mode_entry = {
|
||||
"clock-mode", NULL,
|
||||
@@ -32,17 +32,16 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_clock_mode_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_clock_mode_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
window_pane_set_mode(wp, &window_clock_mode);
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
*/
|
||||
|
||||
void cmd_command_prompt_key_binding(struct cmd *, int);
|
||||
int cmd_command_prompt_check(struct args *);
|
||||
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
int cmd_command_prompt_callback(void *, const char *);
|
||||
void cmd_command_prompt_free(void *);
|
||||
@@ -42,7 +41,6 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
||||
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
0,
|
||||
cmd_command_prompt_key_binding,
|
||||
NULL,
|
||||
cmd_command_prompt_exec
|
||||
};
|
||||
|
||||
@@ -85,7 +83,7 @@ cmd_command_prompt_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *inputs, *prompts;
|
||||
@@ -94,7 +92,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *prompt, *ptr, *input = NULL;
|
||||
size_t n;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (c->prompt_string != NULL)
|
||||
@@ -150,7 +148,6 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause, *new_template, *prompt, *ptr;
|
||||
char *input = NULL;
|
||||
|
||||
@@ -175,7 +172,7 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
|
||||
if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
@@ -184,16 +181,7 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
return (0);
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = c;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
ctx.print = key_bindings_print;
|
||||
ctx.info = key_bindings_info;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmdq_run(c->cmdq, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
void cmd_confirm_before_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
int cmd_confirm_before_callback(void *, const char *);
|
||||
void cmd_confirm_before_free(void *);
|
||||
@@ -38,13 +38,12 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
||||
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||
0,
|
||||
cmd_confirm_before_key_binding,
|
||||
NULL,
|
||||
cmd_confirm_before_exec
|
||||
};
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
struct client *c;
|
||||
char *cmd;
|
||||
struct client *client;
|
||||
};
|
||||
|
||||
void
|
||||
@@ -66,7 +65,7 @@ cmd_confirm_before_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
@@ -74,12 +73,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *cmd, *copy, *new_prompt, *ptr;
|
||||
const char *prompt;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if ((prompt = args_get(args, 'p')) != NULL)
|
||||
@@ -93,48 +87,43 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(args->argv[0]);
|
||||
cdata->c = c;
|
||||
status_prompt_set(cdata->c, new_prompt, NULL,
|
||||
|
||||
cdata->client = c;
|
||||
cdata->client->references++;
|
||||
|
||||
status_prompt_set(c, new_prompt, NULL,
|
||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||
PROMPT_SINGLE);
|
||||
|
||||
free(new_prompt);
|
||||
return (CMD_RETURN_YIELD);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_confirm_before_callback(void *data, const char *s)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct client *c = cdata->client;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_ctx ctx;
|
||||
char *cause;
|
||||
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
return (0);
|
||||
|
||||
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 (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
cmdq_error(c->cmdq, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.curclient = c;
|
||||
|
||||
ctx.error = key_bindings_error;
|
||||
ctx.print = key_bindings_print;
|
||||
ctx.info = key_bindings_info;
|
||||
|
||||
ctx.cmdclient = NULL;
|
||||
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
cmdq_run(c->cmdq, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
return (0);
|
||||
@@ -144,6 +133,9 @@ void
|
||||
cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct client *c = cdata->client;
|
||||
|
||||
c->references--;
|
||||
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
void cmd_copy_mode_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_copy_mode_entry = {
|
||||
"copy-mode", NULL,
|
||||
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
||||
"[-u] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
cmd_copy_mode_key_binding,
|
||||
NULL,
|
||||
cmd_copy_mode_exec
|
||||
};
|
||||
|
||||
@@ -46,17 +45,19 @@ cmd_copy_mode_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_init_from_pane(wp);
|
||||
if (wp->mode != &window_copy_mode) {
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_init_from_pane(wp);
|
||||
}
|
||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||
window_copy_pageup(wp);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Delete a paste buffer.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
"delete-buffer", "deleteb",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
CMD_BUFFER_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_delete_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_delete_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
char *cause;
|
||||
@@ -52,13 +51,13 @@ cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (paste_free_index(&global_buffers, buffer) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Detach a client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_detach_client_entry = {
|
||||
"detach-client", "detach",
|
||||
@@ -32,17 +34,16 @@ const struct cmd_entry cmd_detach_client_entry = {
|
||||
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
CMD_READONLY,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_detach_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c, *c2;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
u_int i;
|
||||
|
||||
if (args_has(args, 'P'))
|
||||
@@ -51,30 +52,37 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
msgtype = MSG_DETACH;
|
||||
|
||||
if (args_has(args, 's')) {
|
||||
s = cmd_find_session(ctx, args_get(args, 's'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 's'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && c->session == s)
|
||||
server_write_client(c, msgtype, NULL, 0);
|
||||
if (c == NULL || c->session != s)
|
||||
continue;
|
||||
server_write_client(c, msgtype, c->session->name,
|
||||
strlen(c->session->name) + 1);
|
||||
}
|
||||
} else {
|
||||
c = cmd_find_client(ctx, args_get(args, 't'));
|
||||
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c2 = ARRAY_ITEM(&clients, i);
|
||||
if (c2 == NULL || c == c2)
|
||||
if (c2 == NULL || c2->session == NULL ||
|
||||
c2 == c)
|
||||
continue;
|
||||
server_write_client(c2, msgtype, NULL, 0);
|
||||
server_write_client(c2, msgtype,
|
||||
c2->session->name,
|
||||
strlen(c2->session->name) + 1);
|
||||
}
|
||||
} else
|
||||
server_write_client(c, msgtype, NULL, 0);
|
||||
} else {
|
||||
server_write_client(c, msgtype, c->session->name,
|
||||
strlen(c->session->name) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_STOP);
|
||||
}
|
||||
|
||||
@@ -27,20 +27,20 @@
|
||||
* Displays a message in the status line.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_display_message_entry = {
|
||||
"display-message", "display",
|
||||
"c:pt:F:", 0, 1,
|
||||
"[-p] [-c target-client] [-t target-pane] [-F format] [message]",
|
||||
"[-p] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE
|
||||
" [message]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_display_message_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
@@ -54,24 +54,33 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
time_t t;
|
||||
size_t len;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 't')) {
|
||||
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
|
||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
wl = cmd_find_pane(ctx, NULL, &s, &wp);
|
||||
wl = cmd_find_pane(cmdq, NULL, &s, &wp);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'F') && args->argc != 0) {
|
||||
ctx->error(ctx, "only one of -F or argument must be given");
|
||||
cmdq_error(cmdq, "only one of -F or argument must be given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'c')) {
|
||||
c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
c = cmd_current_client(cmdq);
|
||||
if (c == NULL && !args_has(self->args, 'p')) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (args->argc != 0)
|
||||
template = args->argv[0];
|
||||
@@ -79,7 +88,8 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
ft = format_create();
|
||||
format_client(ft, c);
|
||||
if (c != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, wl);
|
||||
format_window_pane(ft, wp);
|
||||
@@ -90,11 +100,11 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
msg = format_expand(ft, out);
|
||||
if (args_has(self->args, 'p'))
|
||||
ctx->print(ctx, "%s", msg);
|
||||
cmdq_print(cmdq, "%s", msg);
|
||||
else
|
||||
status_message_set(c, "%s", msg);
|
||||
|
||||
free(msg);
|
||||
format_free(ft);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Display panes on a client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
"display-panes", "displayp",
|
||||
@@ -32,17 +32,16 @@ const struct cmd_entry cmd_display_panes_entry = {
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_display_panes_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
server_set_identify(c);
|
||||
|
||||
@@ -28,10 +28,9 @@
|
||||
* Find window containing text.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_find_window_callback(struct window_choose_data *);
|
||||
void cmd_find_window_free(struct window_choose_data *);
|
||||
|
||||
/* Flags for determining matching behavior. */
|
||||
#define CMD_FIND_WINDOW_BY_TITLE 0x1
|
||||
@@ -49,7 +48,6 @@ const struct cmd_entry cmd_find_window_entry = {
|
||||
"[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_find_window_exec
|
||||
};
|
||||
|
||||
@@ -128,9 +126,10 @@ cmd_find_window_match(struct cmd_find_window_data_list *find_list,
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct window_choose_data *cdata;
|
||||
struct session *s;
|
||||
struct winlink *wl, *wm;
|
||||
@@ -139,13 +138,13 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
const char *template;
|
||||
u_int i, match_flags;
|
||||
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->error(ctx, "must be run interactively");
|
||||
if ((c = cmd_current_client(cmdq)) == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
s = ctx->curclient->session;
|
||||
s = c->session;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
@@ -162,7 +161,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
free(searchstr);
|
||||
|
||||
if (ARRAY_LENGTH(&find_list) == 0) {
|
||||
ctx->error(ctx, "no windows matching: %s", str);
|
||||
cmdq_error(cmdq, "no windows matching: %s", str);
|
||||
ARRAY_FREE(&find_list);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -180,9 +179,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
for (i = 0; i < ARRAY_LENGTH(&find_list); i++) {
|
||||
wm = ARRAY_ITEM(&find_list, i).wl;
|
||||
|
||||
cdata = window_choose_data_create(ctx);
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = wm->idx;
|
||||
cdata->client->references++;
|
||||
cdata->wl = wm;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
@@ -193,12 +191,12 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
ARRAY_ITEM(&find_list, i).list_ctx);
|
||||
format_session(cdata->ft, s);
|
||||
format_winlink(cdata->ft, s, wm);
|
||||
format_window_pane(cdata->ft, wm->window->active);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
}
|
||||
|
||||
window_choose_ready(wl->window->active,
|
||||
0, cmd_find_window_callback, cmd_find_window_free);
|
||||
window_choose_ready(wl->window->active, 0, cmd_find_window_callback);
|
||||
|
||||
out:
|
||||
ARRAY_FREE(&find_list);
|
||||
@@ -214,7 +212,7 @@ cmd_find_window_callback(struct window_choose_data *cdata)
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
s = cdata->session;
|
||||
s = cdata->start_session;
|
||||
if (!session_alive(s))
|
||||
return;
|
||||
|
||||
@@ -227,16 +225,3 @@ cmd_find_window_callback(struct window_choose_data *cdata)
|
||||
recalculate_sizes();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cmd_find_window_free(struct window_choose_data *cdata)
|
||||
{
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
cdata->session->references--;
|
||||
|
||||
free(cdata->ft_template);
|
||||
format_free(cdata->ft);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Cause client to report an error and exit with 1 if session doesn't exist.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_has_session_entry = {
|
||||
"has-session", "has",
|
||||
@@ -32,16 +32,15 @@ const struct cmd_entry cmd_has_session_entry = {
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_has_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_has_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL)
|
||||
if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
116
cmd-if-shell.c
116
cmd-if-shell.c
@@ -29,33 +29,61 @@
|
||||
* Executes a tmux command if a shell command returns true or false.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_if_shell_callback(struct job *);
|
||||
void cmd_if_shell_done(struct cmd_q *);
|
||||
void cmd_if_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_if_shell_entry = {
|
||||
"if-shell", "if",
|
||||
"", 2, 3,
|
||||
"shell-command command [command]",
|
||||
"bt:", 2, 3,
|
||||
"[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_if_shell_exec
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
char *cmd_if;
|
||||
char *cmd_else;
|
||||
struct cmd_ctx ctx;
|
||||
struct cmd_q *cmdq;
|
||||
int bflag;
|
||||
int started;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_if_shell_data *cdata;
|
||||
const char *shellcmd = args->argv[0];
|
||||
char *shellcmd;
|
||||
struct client *c;
|
||||
struct session *s = NULL;
|
||||
struct winlink *wl = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
struct format_tree *ft;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
||||
else {
|
||||
c = cmd_find_client(cmdq, NULL, 1);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
s = c->session;
|
||||
wl = s->curw;
|
||||
wp = wl->window->active;
|
||||
}
|
||||
}
|
||||
|
||||
ft = format_create();
|
||||
if (s != NULL)
|
||||
format_session(ft, s);
|
||||
if (s != NULL && wl != NULL)
|
||||
format_winlink(ft, s, wl);
|
||||
if (wp != NULL)
|
||||
format_window_pane(ft, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
||||
@@ -63,56 +91,86 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
||||
else
|
||||
cdata->cmd_else = NULL;
|
||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||
cdata->bflag = args_has(args, 'b');
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
ctx->cmdclient->references++;
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references++;
|
||||
cdata->started = 0;
|
||||
cdata->cmdq = cmdq;
|
||||
cmdq->references++;
|
||||
|
||||
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||
job_run(shellcmd, s, cmd_if_shell_callback, cmd_if_shell_free, cdata);
|
||||
free(shellcmd);
|
||||
|
||||
return (CMD_RETURN_YIELD); /* don't let client exit */
|
||||
if (cdata->bflag)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job->data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
struct cmd_q *cmdq = cdata->cmdq, *cmdq1;
|
||||
struct cmd_list *cmdlist;
|
||||
char *cause, *cmd;
|
||||
|
||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) {
|
||||
if (cmdq->dead)
|
||||
return;
|
||||
|
||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||
cmd = cdata->cmd_else;
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
} else
|
||||
else
|
||||
cmd = cdata->cmd_if;
|
||||
if (cmd_string_parse(cmd, &cmdlist, &cause) != 0) {
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "%s", cause);
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_list_exec(cmdlist, ctx);
|
||||
cdata->started = 1;
|
||||
|
||||
cmdq1 = cmdq_new(cmdq->client);
|
||||
cmdq1->emptyfn = cmd_if_shell_done;
|
||||
cmdq1->data = cdata;
|
||||
|
||||
cmdq_run(cmdq1, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_if_shell_done(struct cmd_q *cmdq1)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = cmdq1->data;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
|
||||
if (cmdq1->client_exit >= 0)
|
||||
cmdq->client_exit = cmdq1->client_exit;
|
||||
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
|
||||
cmdq_free(cmdq1);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_if_shell_free(void *data)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
|
||||
if (ctx->cmdclient != NULL) {
|
||||
ctx->cmdclient->references--;
|
||||
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||
}
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references--;
|
||||
if (cdata->started)
|
||||
return;
|
||||
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
*/
|
||||
|
||||
void cmd_join_pane_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
enum cmd_retval join_pane(struct cmd *, struct cmd_ctx *, int);
|
||||
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
|
||||
|
||||
const struct cmd_entry cmd_join_pane_entry = {
|
||||
"join-pane", "joinp",
|
||||
@@ -39,7 +39,6 @@ const struct cmd_entry cmd_join_pane_entry = {
|
||||
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||
0,
|
||||
cmd_join_pane_key_binding,
|
||||
NULL,
|
||||
cmd_join_pane_exec
|
||||
};
|
||||
|
||||
@@ -49,7 +48,6 @@ const struct cmd_entry cmd_move_pane_entry = {
|
||||
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_join_pane_exec
|
||||
};
|
||||
|
||||
@@ -68,13 +66,13 @@ cmd_join_pane_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
return (join_pane(self, ctx, self->entry == &cmd_join_pane_entry));
|
||||
return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
||||
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *dst_s;
|
||||
@@ -86,23 +84,25 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
|
||||
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
|
||||
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), &dst_s, &dst_wp);
|
||||
if (dst_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
dst_w = dst_wl->window;
|
||||
dst_idx = dst_wl->idx;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
||||
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
|
||||
if (src_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src_w = src_wl->window;
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (not_same_window && src_w == dst_w) {
|
||||
ctx->error(ctx, "can't join a pane to its own window");
|
||||
cmdq_error(cmdq, "can't join a pane to its own window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!not_same_window && src_wp == dst_wp) {
|
||||
ctx->error(ctx, "source and target panes must be different");
|
||||
cmdq_error(cmdq, "source and target panes must be different");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
||||
if (args_has(args, 'l')) {
|
||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "size %s", cause);
|
||||
cmdq_error(cmdq, "size %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "percentage %s", cause);
|
||||
cmdq_error(cmdq, "percentage %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
|
||||
}
|
||||
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
|
||||
if (lc == NULL) {
|
||||
ctx->error(ctx, "create pane failed: pane too small");
|
||||
cmdq_error(cmdq, "create pane failed: pane too small");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Kill pane.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_kill_pane_entry = {
|
||||
"kill-pane", "killp",
|
||||
@@ -34,19 +34,19 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
"[-a] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_kill_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp;
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
/* Only one pane, kill the window. */
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Kill the server and do nothing else.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_kill_server_entry = {
|
||||
"kill-server", NULL,
|
||||
@@ -35,15 +35,23 @@ const struct cmd_entry cmd_kill_server_entry = {
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
cmd_kill_server_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_start_server_entry = {
|
||||
"start-server", "start",
|
||||
"", 0, 0,
|
||||
"",
|
||||
CMD_STARTSERVER,
|
||||
NULL,
|
||||
cmd_kill_server_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
cmd_kill_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
|
||||
{
|
||||
kill(getpid(), SIGTERM);
|
||||
if (self->entry == &cmd_kill_server_entry)
|
||||
kill(getpid(), SIGTERM);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Note this deliberately has no alias to make it hard to hit by accident.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_kill_session_entry = {
|
||||
"kill-session", NULL,
|
||||
@@ -35,17 +35,16 @@ const struct cmd_entry cmd_kill_session_entry = {
|
||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_kill_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s, *s2, *s3;
|
||||
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Destroy window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_kill_window_entry = {
|
||||
"kill-window", "killw",
|
||||
@@ -32,18 +32,17 @@ const struct cmd_entry cmd_kill_window_entry = {
|
||||
"[-a] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_kill_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl, *wl2, *wl3;
|
||||
struct session *s;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Link a window into another session.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_link_window_entry = {
|
||||
"link-window", "linkw",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_link_window_entry = {
|
||||
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_link_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *src, *dst;
|
||||
@@ -47,15 +46,15 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *cause;
|
||||
int idx, kflag, dflag;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
kflag = args_has(self->args, 'k');
|
||||
dflag = args_has(self->args, 'd');
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||
ctx->error(ctx, "can't link window: %s", cause);
|
||||
cmdq_error(cmdq, "can't link window: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* List paste buffers.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_list_buffers_entry = {
|
||||
"list-buffers", "lsb",
|
||||
@@ -35,13 +35,11 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
"[-F format]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_buffers_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct paste_buffer *pb;
|
||||
@@ -60,7 +58,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
format_paste_buffer(ft, pb);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* List all clients.
|
||||
*/
|
||||
|
||||
int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_list_clients_entry = {
|
||||
"list-clients", "lsc",
|
||||
@@ -36,13 +36,11 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
"[-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
CMD_READONLY,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_clients_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
@@ -53,7 +51,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *line;
|
||||
|
||||
if (args_has(args, 't')) {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
@@ -76,7 +74,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
format_client(ft, c);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* List all commands with usages.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_list_commands_entry = {
|
||||
"list-commands", "lscm",
|
||||
@@ -32,18 +32,23 @@ const struct cmd_entry cmd_list_commands_entry = {
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_commands_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_commands_exec(unused struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
const struct cmd_entry **entryp;
|
||||
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
if ((*entryp)->alias != NULL) {
|
||||
cmdq_print(cmdq, "%s (%s) %s", (*entryp)->name,
|
||||
(*entryp)->alias, (*entryp)->usage);
|
||||
} else {
|
||||
cmdq_print(cmdq, "%s %s", (*entryp)->name,
|
||||
(*entryp)->usage);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
* List key bindings.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
|
||||
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_list_keys_entry = {
|
||||
"list-keys", "lsk",
|
||||
@@ -35,12 +35,11 @@ const struct cmd_entry cmd_list_keys_entry = {
|
||||
"[-t key-table]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_keys_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct key_binding *bd;
|
||||
@@ -50,7 +49,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
int width, keywidth;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_list_keys_table(self, ctx));
|
||||
return (cmd_list_keys_table(self, cmdq));
|
||||
|
||||
width = 0;
|
||||
|
||||
@@ -91,14 +90,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
continue;
|
||||
|
||||
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
|
||||
ctx->print(ctx, "bind-key %s", tmp);
|
||||
cmdq_print(cmdq, "bind-key %s", tmp);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
enum cmd_retval
|
||||
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename;
|
||||
@@ -109,7 +108,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -138,9 +137,12 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
||||
mode = "c";
|
||||
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||
if (cmdstr != NULL) {
|
||||
ctx->print(ctx, "bind-key -%st %s%s %*s %s",
|
||||
cmdq_print(cmdq, "bind-key -%st %s%s %*s %s%s%s%s",
|
||||
mode, any_mode && *mode == '\0' ? " " : "",
|
||||
mtab->name, (int) width, key, cmdstr);
|
||||
mtab->name, (int) width, key, cmdstr,
|
||||
mbind->arg != NULL ? " \"" : "",
|
||||
mbind->arg != NULL ? mbind->arg : "",
|
||||
mbind->arg != NULL ? "\"": "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,70 +27,69 @@
|
||||
* List panes on given window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_list_panes_server(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_list_panes_server(struct cmd *, struct cmd_q *);
|
||||
void cmd_list_panes_session(
|
||||
struct cmd *, struct session *, struct cmd_ctx *, int);
|
||||
struct cmd *, struct session *, struct cmd_q *, int);
|
||||
void cmd_list_panes_window(struct cmd *,
|
||||
struct session *, struct winlink *, struct cmd_ctx *, int);
|
||||
struct session *, struct winlink *, struct cmd_q *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_panes_entry = {
|
||||
"list-panes", "lsp",
|
||||
"asF:t:", 0, 0,
|
||||
"[-as] [-F format] [-t target]",
|
||||
"[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_panes_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_panes_server(self, ctx);
|
||||
cmd_list_panes_server(self, cmdq);
|
||||
else if (args_has(args, 's')) {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmd_list_panes_session(self, s, ctx, 1);
|
||||
cmd_list_panes_session(self, s, cmdq, 1);
|
||||
} else {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmd_list_panes_window(self, s, wl, ctx, 0);
|
||||
cmd_list_panes_window(self, s, wl, cmdq, 0);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_panes_server(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
cmd_list_panes_session(self, s, ctx, 2);
|
||||
cmd_list_panes_session(self, s, cmdq, 2);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_panes_session(
|
||||
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
|
||||
struct cmd *self, struct session *s, struct cmd_q *cmdq, int type)
|
||||
{
|
||||
struct winlink *wl;
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows)
|
||||
cmd_list_panes_window(self, s, wl, ctx, type);
|
||||
cmd_list_panes_window(self, s, wl, cmdq, type);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_panes_window(struct cmd *self,
|
||||
struct session *s, struct winlink *wl, struct cmd_ctx *ctx, int type)
|
||||
struct session *s, struct winlink *wl, struct cmd_q *cmdq, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
@@ -135,7 +134,7 @@ cmd_list_panes_window(struct cmd *self,
|
||||
format_window_pane(ft, wp);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* List all sessions.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_list_sessions_entry = {
|
||||
"list-sessions", "ls",
|
||||
@@ -36,12 +36,11 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
"[-F format]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_sessions_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -60,7 +59,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
format_session(ft, s);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
* List windows on given session.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_list_windows_server(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
|
||||
void cmd_list_windows_session(
|
||||
struct cmd *, struct session *, struct cmd_ctx *, int);
|
||||
struct cmd *, struct session *, struct cmd_q *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_windows_entry = {
|
||||
"list-windows", "lsw",
|
||||
@@ -39,40 +39,39 @@ const struct cmd_entry cmd_list_windows_entry = {
|
||||
"[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_list_windows_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_windows_server(self, ctx);
|
||||
cmd_list_windows_server(self, cmdq);
|
||||
else {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmd_list_windows_session(self, s, ctx, 0);
|
||||
cmd_list_windows_session(self, s, cmdq, 0);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_windows_server(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
cmd_list_windows_session(self, s, ctx, 1);
|
||||
cmd_list_windows_session(self, s, cmdq, 1);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_windows_session(
|
||||
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
|
||||
struct cmd *self, struct session *s, struct cmd_q *cmdq, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -99,9 +98,10 @@ cmd_list_windows_session(
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, wl);
|
||||
format_window_pane(ft, wl->window->active);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
76
cmd-list.c
76
cmd-list.c
@@ -24,7 +24,8 @@
|
||||
#include "tmux.h"
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_parse(int argc, char **argv, char **cause)
|
||||
cmd_list_parse(int argc, char **argv, const char* file, u_int line,
|
||||
char **cause)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
@@ -34,7 +35,7 @@ cmd_list_parse(int argc, char **argv, char **cause)
|
||||
|
||||
copy_argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
cmdlist = xmalloc(sizeof *cmdlist);
|
||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
||||
cmdlist->references = 1;
|
||||
TAILQ_INIT(&cmdlist->list);
|
||||
|
||||
@@ -55,7 +56,7 @@ cmd_list_parse(int argc, char **argv, char **cause)
|
||||
if (arglen != 1)
|
||||
new_argc++;
|
||||
|
||||
cmd = cmd_parse(new_argc, new_argv, cause);
|
||||
cmd = cmd_parse(new_argc, new_argv, file, line, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
@@ -64,7 +65,8 @@ cmd_list_parse(int argc, char **argv, char **cause)
|
||||
}
|
||||
|
||||
if (lastsplit != argc) {
|
||||
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
|
||||
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit,
|
||||
file, line, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
@@ -79,75 +81,21 @@ bad:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct client *c = ctx->curclient;
|
||||
struct cmd *cmd;
|
||||
enum cmd_retval retval;
|
||||
int guards, n;
|
||||
|
||||
guards = 0;
|
||||
if (c != NULL && c->session != NULL)
|
||||
guards = c->flags & CLIENT_CONTROL;
|
||||
|
||||
notify_disable();
|
||||
|
||||
retval = 0;
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
if (guards)
|
||||
ctx->print(ctx, "%%begin");
|
||||
n = cmd_exec(cmd, ctx);
|
||||
if (guards)
|
||||
ctx->print(ctx, "%%end");
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case CMD_RETURN_ERROR:
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_RETURN_ATTACH:
|
||||
/* Client is being attached (send MSG_READY). */
|
||||
retval = CMD_RETURN_ATTACH;
|
||||
|
||||
/*
|
||||
* Mangle the context to treat any following commands
|
||||
* as if they were called from inside.
|
||||
*/
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->curclient = ctx->cmdclient;
|
||||
ctx->cmdclient = NULL;
|
||||
|
||||
ctx->error = key_bindings_error;
|
||||
ctx->print = key_bindings_print;
|
||||
ctx->info = key_bindings_info;
|
||||
}
|
||||
break;
|
||||
case CMD_RETURN_YIELD:
|
||||
if (retval == CMD_RETURN_NORMAL)
|
||||
retval = CMD_RETURN_YIELD;
|
||||
break;
|
||||
case CMD_RETURN_NORMAL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notify_enable();
|
||||
return (retval);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmd *cmd, *cmd1;
|
||||
|
||||
if (--cmdlist->references != 0)
|
||||
return;
|
||||
|
||||
while (!TAILQ_EMPTY(&cmdlist->list)) {
|
||||
cmd = TAILQ_FIRST(&cmdlist->list);
|
||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||
cmd_free(cmd);
|
||||
args_free(cmd->args);
|
||||
free(cmd->file);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
free(cmdlist);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -30,7 +31,7 @@
|
||||
* Loads a paste buffer from a file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
void cmd_load_buffer_callback(struct client *, int, void *);
|
||||
|
||||
const struct cmd_entry cmd_load_buffer_entry = {
|
||||
@@ -39,29 +40,28 @@ const struct cmd_entry cmd_load_buffer_entry = {
|
||||
CMD_BUFFER_USAGE " path",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_load_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = ctx->cmdclient;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s;
|
||||
FILE *f;
|
||||
const char *path, *newpath, *wd;
|
||||
const char *path;
|
||||
char *pdata, *new_pdata, *cause;
|
||||
size_t psize;
|
||||
u_int limit;
|
||||
int ch, error, buffer, *buffer_ptr;
|
||||
int ch, error, buffer, *buffer_ptr, cwd, fd;
|
||||
|
||||
if (!args_has(args, 'b'))
|
||||
buffer = -1;
|
||||
else {
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -72,31 +72,28 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
buffer_ptr = xmalloc(sizeof *buffer_ptr);
|
||||
*buffer_ptr = buffer;
|
||||
|
||||
error = server_set_stdin_callback (c, cmd_load_buffer_callback,
|
||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
||||
buffer_ptr, &cause);
|
||||
if (error != 0) {
|
||||
ctx->error(ctx, "%s: %s", path, cause);
|
||||
cmdq_error(cmdq, "%s: %s", path, cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_YIELD);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
if (c != NULL)
|
||||
wd = c->cwd;
|
||||
else if ((s = cmd_current_session(ctx, 0)) != NULL) {
|
||||
wd = options_get_string(&s->options, "default-path");
|
||||
if (*wd == '\0')
|
||||
wd = s->cwd;
|
||||
} else
|
||||
wd = NULL;
|
||||
if (wd != NULL && *wd != '\0') {
|
||||
newpath = get_full_path(wd, path);
|
||||
if (newpath != NULL)
|
||||
path = newpath;
|
||||
}
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||
if (c != NULL && c->session == NULL)
|
||||
cwd = c->cwd;
|
||||
else if ((s = cmd_current_session(cmdq, 0)) != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = AT_FDCWD;
|
||||
|
||||
if ((fd = openat(cwd, path, O_RDONLY)) == -1 ||
|
||||
(f = fdopen(fd, "rb")) == NULL) {
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -105,14 +102,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
while ((ch = getc(f)) != EOF) {
|
||||
/* Do not let the server die due to memory exhaustion. */
|
||||
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||
ctx->error(ctx, "realloc error: %s", strerror(errno));
|
||||
cmdq_error(cmdq, "realloc error: %s", strerror(errno));
|
||||
goto error;
|
||||
}
|
||||
pdata = new_pdata;
|
||||
pdata[psize++] = ch;
|
||||
}
|
||||
if (ferror(f)) {
|
||||
ctx->error(ctx, "%s: read error", path);
|
||||
cmdq_error(cmdq, "%s: read error", path);
|
||||
goto error;
|
||||
}
|
||||
if (pdata != NULL)
|
||||
@@ -126,7 +123,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
free(pdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -153,12 +150,13 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
c->stdin_callback = NULL;
|
||||
|
||||
c->references--;
|
||||
c->flags |= CLIENT_EXIT;
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
psize = EVBUFFER_LENGTH(c->stdin_data);
|
||||
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
|
||||
free(data);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
|
||||
pdata[psize] = '\0';
|
||||
@@ -171,7 +169,11 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
/* No context so can't use server_client_msg_error. */
|
||||
evbuffer_add_printf(c->stderr_data, "no buffer %d\n", *buffer);
|
||||
server_push_stderr(c);
|
||||
free(pdata);
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
out:
|
||||
cmdq_continue(c->cmdq);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* Lock commands.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_lock_server_entry = {
|
||||
"lock-server", "lock",
|
||||
@@ -36,7 +36,6 @@ const struct cmd_entry cmd_lock_server_entry = {
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_lock_server_exec
|
||||
};
|
||||
|
||||
@@ -46,7 +45,6 @@ const struct cmd_entry cmd_lock_session_entry = {
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_lock_server_exec
|
||||
};
|
||||
|
||||
@@ -56,13 +54,11 @@ const struct cmd_entry cmd_lock_client_entry = {
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_lock_server_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
cmd_lock_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
@@ -71,11 +67,13 @@ cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
if (self->entry == &cmd_lock_server_entry)
|
||||
server_lock();
|
||||
else if (self->entry == &cmd_lock_session_entry) {
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_lock_session(s);
|
||||
} else {
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_lock_client(c);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Move a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_move_window_entry = {
|
||||
"move-window", "movew",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_move_window_entry = {
|
||||
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_move_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *src, *dst, *s;
|
||||
@@ -48,7 +47,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
int idx, kflag, dflag;
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
session_renumber_windows(s);
|
||||
@@ -57,15 +56,15 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
|
||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
kflag = args_has(self->args, 'k');
|
||||
dflag = args_has(self->args, 'd');
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
|
||||
ctx->error(ctx, "can't move window: %s", cause);
|
||||
cmdq_error(cmdq, "can't move window: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -30,86 +32,101 @@
|
||||
* Create a new session and attach to the current terminal unless -d is given.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_new_session_check(struct args *);
|
||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_new_session_entry = {
|
||||
"new-session", "new",
|
||||
"dn:s:t:x:y:", 0, 1,
|
||||
"[-d] [-n window-name] [-s session-name] [-t target-session] "
|
||||
"[-x width] [-y height] [command]",
|
||||
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
|
||||
"Ac:dDF:n:Ps:t:x:y:", 0, 1,
|
||||
"[-AdDP] [-c start-directory] [-F format] [-n window-name] "
|
||||
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
||||
"[command]",
|
||||
CMD_STARTSERVER|CMD_CANTNEST,
|
||||
NULL,
|
||||
cmd_new_session_check,
|
||||
cmd_new_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_new_session_check(struct args *args)
|
||||
{
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
|
||||
return (CMD_RETURN_ERROR);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s, *old_s, *groupwith;
|
||||
struct client *c = cmdq->client, *c0;
|
||||
struct session *s, *groupwith;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct environ env;
|
||||
struct termios tio, *tiop;
|
||||
struct passwd *pw;
|
||||
const char *newname, *target, *update, *cwd, *errstr;
|
||||
char *cmd, *cause;
|
||||
int detached, idx;
|
||||
u_int sx, sy, i;
|
||||
const char *newname, *target, *update, *errstr, *template;
|
||||
char *cmd, *cause, *cp;
|
||||
int detached, already_attached, idx, cwd, fd = -1;
|
||||
u_int sx, sy;
|
||||
struct format_tree *ft;
|
||||
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
||||
cmdq_error(cmdq, "command or window name given with target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
newname = args_get(args, 's');
|
||||
if (newname != NULL) {
|
||||
if (!session_check_name(newname)) {
|
||||
ctx->error(ctx, "bad session name: %s", newname);
|
||||
cmdq_error(cmdq, "bad session name: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
ctx->error(ctx, "duplicate session: %s", newname);
|
||||
if (args_has(args, 'A')) {
|
||||
return (cmd_attach_session(cmdq, newname,
|
||||
args_has(args, 'D'), 0, NULL));
|
||||
}
|
||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
groupwith = cmd_find_session(ctx, target, 0);
|
||||
groupwith = cmd_find_session(cmdq, target, 0);
|
||||
if (groupwith == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
groupwith = NULL;
|
||||
|
||||
/*
|
||||
* 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 = args_has(args, 'd');
|
||||
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
|
||||
if (c == NULL)
|
||||
detached = 1;
|
||||
|
||||
/* Is this client already attached? */
|
||||
already_attached = 0;
|
||||
if (c != NULL && c->session != NULL)
|
||||
already_attached = 1;
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create();
|
||||
if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c0);
|
||||
cp = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
|
||||
if (cp != NULL && *cp != '\0') {
|
||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
||||
free(cp);
|
||||
if (fd == -1) {
|
||||
cmdq_error(cmdq, "bad working directory: %s",
|
||||
strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (cp != NULL)
|
||||
free(cp);
|
||||
cwd = fd;
|
||||
} else if (c != NULL && c->session == NULL)
|
||||
cwd = c->cwd;
|
||||
else if ((c0 = cmd_current_client(cmdq)) != NULL)
|
||||
cwd = c0->session->cwd;
|
||||
else {
|
||||
fd = open(".", O_RDONLY);
|
||||
cwd = fd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save the termios settings, part of which is used for new windows in
|
||||
* this session.
|
||||
@@ -119,60 +136,42 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
* 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)
|
||||
if (!detached && !already_attached && c->tty.fd != -1) {
|
||||
if (tcgetattr(c->tty.fd, &tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
tiop = &tio;
|
||||
} else
|
||||
tiop = NULL;
|
||||
|
||||
/* Open the terminal if necessary. */
|
||||
if (!detached && ctx->cmdclient != NULL) {
|
||||
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
if (!detached && !already_attached) {
|
||||
if (server_client_open(c, NULL, &cause) != 0) {
|
||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||
cwd = ctx->cmdclient->cwd;
|
||||
else {
|
||||
pw = getpwuid(getuid());
|
||||
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
|
||||
cwd = pw->pw_dir;
|
||||
else
|
||||
cwd = "/";
|
||||
}
|
||||
|
||||
/* Find new session size. */
|
||||
if (ctx->cmdclient != NULL) {
|
||||
sx = ctx->cmdclient->tty.sx;
|
||||
sy = ctx->cmdclient->tty.sy;
|
||||
} else if (ctx->curclient != NULL) {
|
||||
sx = ctx->curclient->tty.sx;
|
||||
sy = ctx->curclient->tty.sy;
|
||||
if (c != NULL) {
|
||||
sx = c->tty.sx;
|
||||
sy = c->tty.sy;
|
||||
} else {
|
||||
sx = 80;
|
||||
sy = 24;
|
||||
}
|
||||
if (detached) {
|
||||
if (args_has(args, 'x')) {
|
||||
sx = strtonum(
|
||||
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "width %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (detached && args_has(args, 'x')) {
|
||||
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(cmdq, "width %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
sy = strtonum(
|
||||
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "height %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
if (detached && args_has(args, 'y')) {
|
||||
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(cmdq, "height %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (sy > 0 && options_get_number(&global_s_options, "status"))
|
||||
@@ -193,25 +192,23 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
/* 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);
|
||||
if (c != NULL)
|
||||
environ_update(update, &c->environ, &env);
|
||||
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
cmdq_error(cmdq, "create session failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
environ_free(&env);
|
||||
|
||||
/* Set the initial window name if one given. */
|
||||
if (cmd != NULL && args_has(args, 'n')) {
|
||||
w = s->curw->window;
|
||||
|
||||
window_set_name(w, args_get(args, 'n'));
|
||||
|
||||
options_set_number(&w->options, "automatic-rename", 0);
|
||||
}
|
||||
|
||||
@@ -230,25 +227,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
* taking this session and needs to get MSG_READY and stay around.
|
||||
*/
|
||||
if (!detached) {
|
||||
if (ctx->cmdclient != NULL) {
|
||||
server_write_ready(ctx->cmdclient);
|
||||
|
||||
old_s = ctx->cmdclient->session;
|
||||
if (old_s != NULL)
|
||||
ctx->cmdclient->last_session = old_s;
|
||||
ctx->cmdclient->session = s;
|
||||
notify_attached_session_changed(ctx->cmdclient);
|
||||
session_update_activity(s);
|
||||
server_redraw_client(ctx->cmdclient);
|
||||
} else {
|
||||
old_s = ctx->curclient->session;
|
||||
if (old_s != NULL)
|
||||
ctx->curclient->last_session = old_s;
|
||||
ctx->curclient->session = s;
|
||||
notify_attached_session_changed(ctx->curclient);
|
||||
session_update_activity(s);
|
||||
server_redraw_client(ctx->curclient);
|
||||
}
|
||||
if (!already_attached)
|
||||
server_write_ready(c);
|
||||
else if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
notify_attached_session_changed(c);
|
||||
session_update_activity(s);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
recalculate_sizes();
|
||||
server_update_socket();
|
||||
@@ -257,17 +243,35 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
* If there are still configuration file errors to display, put the new
|
||||
* session's current window into more mode and display them now.
|
||||
*/
|
||||
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
|
||||
wp = s->curw->window->active;
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
window_copy_init_for_output(wp);
|
||||
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||
window_copy_add(wp, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
ARRAY_FREE(&cfg_causes);
|
||||
if (cfg_finished)
|
||||
cfg_show_causes(s);
|
||||
|
||||
/* Print if requested. */
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_SESSION_TEMPLATE;
|
||||
|
||||
ft = format_create();
|
||||
if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c0);
|
||||
format_session(ft, s);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
|
||||
if (!detached)
|
||||
cmdq->client_exit = 0;
|
||||
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,35 +30,32 @@
|
||||
* Create a new window.
|
||||
*/
|
||||
|
||||
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_new_window_entry = {
|
||||
"new-window", "neww",
|
||||
"ac:dF:kn:Pt:", 0, 1,
|
||||
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
|
||||
"[-t target-window] [command]",
|
||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_new_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct client *c;
|
||||
const char *cmd, *cwd;
|
||||
const char *template;
|
||||
char *cause;
|
||||
int idx, last, detached;
|
||||
const char *cmd, *template;
|
||||
char *cause, *cp;
|
||||
int idx, last, detached, cwd, fd = -1;
|
||||
struct format_tree *ft;
|
||||
char *cp;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
idx = wl->idx + 1;
|
||||
@@ -65,7 +66,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
break;
|
||||
}
|
||||
if (last == INT_MAX) {
|
||||
ctx->error(ctx, "no free window indexes");
|
||||
cmdq_error(cmdq, "no free window indexes");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -76,11 +77,42 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
server_unlink_window(s, wl);
|
||||
}
|
||||
} else {
|
||||
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
|
||||
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
detached = args_has(args, 'd');
|
||||
|
||||
if (args->argc == 0)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
else
|
||||
cmd = args->argv[0];
|
||||
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, s->curw);
|
||||
format_window_pane(ft, s->curw->window->active);
|
||||
cp = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
|
||||
if (cp != NULL && *cp != '\0') {
|
||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
||||
free(cp);
|
||||
if (fd == -1) {
|
||||
cmdq_error(cmdq, "bad working directory: %s",
|
||||
strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (cp != NULL)
|
||||
free(cp);
|
||||
cwd = fd;
|
||||
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
else
|
||||
cwd = s->cwd;
|
||||
|
||||
wl = NULL;
|
||||
if (idx != -1)
|
||||
wl = winlink_find_by_index(&s->windows, idx);
|
||||
@@ -101,19 +133,13 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
if (args->argc == 0)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
else
|
||||
cmd = args->argv[0];
|
||||
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(&s->options, "base-index");
|
||||
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
|
||||
if (wl == NULL) {
|
||||
ctx->error(ctx, "create window failed: %s", cause);
|
||||
cmdq_error(cmdq, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
if (!detached) {
|
||||
session_select(s, wl->idx);
|
||||
@@ -126,18 +152,25 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(ctx, NULL)) != NULL)
|
||||
format_client(ft, c);
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, wl);
|
||||
format_window_pane(ft, wl->window->active);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", cp);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -27,23 +27,22 @@
|
||||
* Paste paste buffer if present.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_paste_buffer_filter(struct window_pane *,
|
||||
const char *, size_t, const char *, int bracket);
|
||||
const char *, size_t, const char *, int);
|
||||
|
||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
"paste-buffer", "pasteb",
|
||||
"db:prs:t:", 0, 0,
|
||||
"[-dpr] [-s separator] [-b buffer-index] [-t target-pane]",
|
||||
"[-dpr] [-s separator] [-b buffer-index] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_paste_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
@@ -54,7 +53,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
int buffer;
|
||||
int pflag;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (!args_has(args, 'b'))
|
||||
@@ -62,7 +61,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else {
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -73,7 +72,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else {
|
||||
pb = paste_get_index(&global_buffers, buffer);
|
||||
if (pb == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -86,9 +85,8 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else
|
||||
sepstr = "\r";
|
||||
}
|
||||
pflag = args_has(args, 'p') &&
|
||||
(wp->screen->mode & MODE_BRACKETPASTE);
|
||||
cmd_paste_buffer_filter(wp, pb->data, pb->size, sepstr, pflag);
|
||||
pflag = (wp->screen->mode & MODE_BRACKETPASTE);
|
||||
paste_send_pane(pb, wp, sepstr, args_has(args, 'p') && pflag);
|
||||
}
|
||||
|
||||
/* Delete the buffer if -d. */
|
||||
@@ -101,30 +99,3 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Add bytes to a buffer and filter '\n' according to separator. */
|
||||
void
|
||||
cmd_paste_buffer_filter(struct window_pane *wp,
|
||||
const char *data, size_t size, const char *sep, int bracket)
|
||||
{
|
||||
const char *end = data + size;
|
||||
const char *lf;
|
||||
size_t seplen;
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[200~", 6);
|
||||
|
||||
seplen = strlen(sep);
|
||||
while ((lf = memchr(data, '\n', end - data)) != NULL) {
|
||||
if (lf != data)
|
||||
bufferevent_write(wp->event, data, lf - data);
|
||||
bufferevent_write(wp->event, sep, seplen);
|
||||
data = lf + 1;
|
||||
}
|
||||
|
||||
if (end != data)
|
||||
bufferevent_write(wp->event, data, end - data);
|
||||
|
||||
if (bracket)
|
||||
bufferevent_write(wp->event, "\033[201~", 6);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
* Open pipe to redirect pane output. If already open, close first.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||
|
||||
@@ -41,12 +41,11 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
"[-o] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_pipe_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
@@ -54,9 +53,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *command;
|
||||
int old_fd, pipe_fd[2], null_fd;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
c = cmd_find_client(ctx, NULL);
|
||||
c = cmd_find_client(cmdq, NULL, 1);
|
||||
|
||||
/* Destroy the old pipe. */
|
||||
old_fd = wp->pipe_fd;
|
||||
@@ -81,14 +80,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
/* Open the new pipe. */
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||
cmdq_error(cmdq, "socketpair error: %s", strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Fork the child. */
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
ctx->error(ctx, "fork error: %s", strerror(errno));
|
||||
cmdq_error(cmdq, "fork error: %s", strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 0:
|
||||
/* Child process. */
|
||||
@@ -130,7 +129,6 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
cmd_pipe_pane_error_callback(
|
||||
unused struct bufferevent *bufev, unused short what, void *data)
|
||||
|
||||
281
cmd-queue.c
Normal file
281
cmd-queue.c
Normal file
@@ -0,0 +1,281 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 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 <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Create new command queue. */
|
||||
struct cmd_q *
|
||||
cmdq_new(struct client *c)
|
||||
{
|
||||
struct cmd_q *cmdq;
|
||||
|
||||
cmdq = xcalloc(1, sizeof *cmdq);
|
||||
cmdq->references = 1;
|
||||
cmdq->dead = 0;
|
||||
|
||||
cmdq->client = c;
|
||||
cmdq->client_exit = -1;
|
||||
|
||||
TAILQ_INIT(&cmdq->queue);
|
||||
cmdq->item = NULL;
|
||||
cmdq->cmd = NULL;
|
||||
|
||||
return (cmdq);
|
||||
}
|
||||
|
||||
/* Free command queue */
|
||||
int
|
||||
cmdq_free(struct cmd_q *cmdq)
|
||||
{
|
||||
if (--cmdq->references != 0)
|
||||
return (cmdq->dead);
|
||||
|
||||
cmdq_flush(cmdq);
|
||||
free(cmdq);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void printflike2
|
||||
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct window *w;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
if (c == NULL)
|
||||
/* nothing */;
|
||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
||||
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_push_stdout(c);
|
||||
} else {
|
||||
w = c->session->curw->window;
|
||||
if (w->active->mode != &window_copy_mode) {
|
||||
window_pane_reset_mode(w->active);
|
||||
window_pane_set_mode(w->active, &window_copy_mode);
|
||||
window_copy_init_for_output(w->active);
|
||||
}
|
||||
window_copy_vadd(w->active, fmt, ap);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* Show info from command. */
|
||||
void printflike2
|
||||
cmdq_info(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
va_list ap;
|
||||
char *msg;
|
||||
|
||||
if (options_get_number(&global_options, "quiet"))
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
if (c == NULL)
|
||||
/* nothing */;
|
||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
||||
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_push_stdout(c);
|
||||
} else {
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
*msg = toupper((u_char) *msg);
|
||||
status_message_set(c, "%s", msg);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
||||
}
|
||||
|
||||
/* Show error from command. */
|
||||
void printflike2
|
||||
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct cmd *cmd = cmdq->cmd;
|
||||
va_list ap;
|
||||
char *msg, *cause;
|
||||
size_t msglen;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msglen = xvasprintf(&msg, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (c == NULL) {
|
||||
xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
|
||||
ARRAY_ADD(&cfg_causes, cause);
|
||||
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
evbuffer_add(c->stderr_data, msg, msglen);
|
||||
evbuffer_add(c->stderr_data, "\n", 1);
|
||||
|
||||
server_push_stderr(c);
|
||||
c->retval = 1;
|
||||
} else {
|
||||
*msg = toupper((u_char) *msg);
|
||||
status_message_set(c, "%s", msg);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
}
|
||||
|
||||
/* Print a guard line. */
|
||||
int
|
||||
cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
|
||||
if (c == NULL)
|
||||
return 0;
|
||||
if (!(c->flags & CLIENT_CONTROL))
|
||||
return 0;
|
||||
|
||||
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
|
||||
(long) cmdq->time, cmdq->number, flags);
|
||||
server_push_stdout(c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Add command list to queue and begin processing if needed. */
|
||||
void
|
||||
cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist)
|
||||
{
|
||||
cmdq_append(cmdq, cmdlist);
|
||||
|
||||
if (cmdq->item == NULL) {
|
||||
cmdq->cmd = NULL;
|
||||
cmdq_continue(cmdq);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add command list to queue. */
|
||||
void
|
||||
cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist)
|
||||
{
|
||||
struct cmd_q_item *item;
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->cmdlist = cmdlist;
|
||||
TAILQ_INSERT_TAIL(&cmdq->queue, item, qentry);
|
||||
cmdlist->references++;
|
||||
}
|
||||
|
||||
/* Continue processing command queue. Returns 1 if finishes empty. */
|
||||
int
|
||||
cmdq_continue(struct cmd_q *cmdq)
|
||||
{
|
||||
struct cmd_q_item *next;
|
||||
enum cmd_retval retval;
|
||||
int empty, guard, flags;
|
||||
char s[1024];
|
||||
|
||||
notify_disable();
|
||||
|
||||
empty = TAILQ_EMPTY(&cmdq->queue);
|
||||
if (empty)
|
||||
goto empty;
|
||||
|
||||
if (cmdq->item == NULL) {
|
||||
cmdq->item = TAILQ_FIRST(&cmdq->queue);
|
||||
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
|
||||
} else
|
||||
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
|
||||
|
||||
do {
|
||||
next = TAILQ_NEXT(cmdq->item, qentry);
|
||||
|
||||
while (cmdq->cmd != NULL) {
|
||||
cmd_print(cmdq->cmd, s, sizeof s);
|
||||
log_debug("cmdq %p: %s (client %d)", cmdq, s,
|
||||
cmdq->client != NULL ? cmdq->client->ibuf.fd : -1);
|
||||
|
||||
cmdq->time = time(NULL);
|
||||
cmdq->number++;
|
||||
|
||||
flags = !!(cmdq->cmd->flags & CMD_CONTROL);
|
||||
guard = cmdq_guard(cmdq, "begin", flags);
|
||||
|
||||
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
|
||||
|
||||
if (guard) {
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
cmdq_guard(cmdq, "error", flags);
|
||||
else
|
||||
cmdq_guard(cmdq, "end", flags);
|
||||
}
|
||||
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
break;
|
||||
if (retval == CMD_RETURN_WAIT)
|
||||
goto out;
|
||||
if (retval == CMD_RETURN_STOP) {
|
||||
cmdq_flush(cmdq);
|
||||
goto empty;
|
||||
}
|
||||
|
||||
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
|
||||
cmd_list_free(cmdq->item->cmdlist);
|
||||
free(cmdq->item);
|
||||
|
||||
cmdq->item = next;
|
||||
if (cmdq->item != NULL)
|
||||
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
|
||||
} while (cmdq->item != NULL);
|
||||
|
||||
empty:
|
||||
if (cmdq->client_exit > 0)
|
||||
cmdq->client->flags |= CLIENT_EXIT;
|
||||
if (cmdq->emptyfn != NULL)
|
||||
cmdq->emptyfn(cmdq); /* may free cmdq */
|
||||
empty = 1;
|
||||
|
||||
out:
|
||||
notify_enable();
|
||||
return (empty);
|
||||
}
|
||||
|
||||
/* Flush command queue. */
|
||||
void
|
||||
cmdq_flush(struct cmd_q *cmdq)
|
||||
{
|
||||
struct cmd_q_item *item, *item1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(item, &cmdq->queue, qentry, item1) {
|
||||
TAILQ_REMOVE(&cmdq->queue, item, qentry);
|
||||
cmd_list_free(item->cmdlist);
|
||||
free(item);
|
||||
}
|
||||
cmdq->item = NULL;
|
||||
}
|
||||
@@ -24,28 +24,49 @@
|
||||
* Refresh client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_refresh_client_entry = {
|
||||
"refresh-client", "refresh",
|
||||
"St:", 0, 0,
|
||||
"[-S] " CMD_TARGET_CLIENT_USAGE,
|
||||
"C:St:", 0, 0,
|
||||
"[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_refresh_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
const char *size;
|
||||
u_int w, h;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'S')) {
|
||||
if (args_has(args, 'C')) {
|
||||
if ((size = args_get(args, 'C')) == NULL) {
|
||||
cmdq_error(cmdq, "missing size");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (sscanf(size, "%u,%u", &w, &h) != 2) {
|
||||
cmdq_error(cmdq, "bad size argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (w < PANE_MINIMUM || w > 5000 ||
|
||||
h < PANE_MINIMUM || h > 5000) {
|
||||
cmdq_error(cmdq, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!(c->flags & CLIENT_CONTROL)) {
|
||||
cmdq_error(cmdq, "not a control client");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (tty_set_size(&c->tty, w, h))
|
||||
recalculate_sizes();
|
||||
} else if (args_has(args, 'S')) {
|
||||
status_update_jobs(c);
|
||||
server_status_client(c);
|
||||
} else
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Change session name.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_rename_session_entry = {
|
||||
"rename-session", "rename",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
CMD_TARGET_SESSION_USAGE " new-name",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_rename_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -47,15 +46,15 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
newname = args->argv[0];
|
||||
if (!session_check_name(newname)) {
|
||||
ctx->error(ctx, "bad session name: %s", newname);
|
||||
cmdq_error(cmdq, "bad session name: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
ctx->error(ctx, "duplicate session: %s", newname);
|
||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
RB_REMOVE(sessions, &sessions, s);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Rename a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_rename_window_entry = {
|
||||
"rename-window", "renamew",
|
||||
@@ -34,18 +34,17 @@ const struct cmd_entry cmd_rename_window_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_rename_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
window_set_name(wl->window, args->argv[0]);
|
||||
|
||||
@@ -27,15 +27,14 @@
|
||||
*/
|
||||
|
||||
void cmd_resize_pane_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_resize_pane_entry = {
|
||||
"resize-pane", "resizep",
|
||||
"DLRt:U", 0, 1,
|
||||
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||
"DLRt:Ux:y:Z", 0, 1,
|
||||
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||
0,
|
||||
cmd_resize_pane_key_binding,
|
||||
NULL,
|
||||
cmd_resize_pane_exec
|
||||
};
|
||||
|
||||
@@ -75,6 +74,10 @@ cmd_resize_pane_key_binding(struct cmd *self, int key)
|
||||
self->args = args_create(1, "5");
|
||||
args_set(self->args, 'R', NULL);
|
||||
break;
|
||||
case 'z':
|
||||
self->args = args_create(0);
|
||||
args_set(self->args, 'Z', NULL);
|
||||
break;
|
||||
default:
|
||||
self->args = args_create(0);
|
||||
break;
|
||||
@@ -82,28 +85,63 @@ cmd_resize_pane_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
struct window_pane *wp;
|
||||
u_int adjust;
|
||||
int x, y;
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
if (args_has(args, 'Z')) {
|
||||
if (w->flags & WINDOW_ZOOMED)
|
||||
window_unzoom(w);
|
||||
else
|
||||
window_zoom(wp);
|
||||
server_redraw_window(w);
|
||||
server_status_window(w);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args->argc == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "adjustment %s", errstr);
|
||||
cmdq_error(cmdq, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
layout_list_add(wp->window);
|
||||
if (args_has(self->args, 'x')) {
|
||||
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "width %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
|
||||
}
|
||||
if (args_has(self->args, 'y')) {
|
||||
y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "height %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'L'))
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||
else if (args_has(self->args, 'R'))
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* Respawn a pane (restart the command). Kill existing if -k given.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
"respawn-pane", "respawnp",
|
||||
@@ -36,12 +36,11 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
"[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_respawn_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -53,14 +52,14 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
char *cause;
|
||||
u_int idx;
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
||||
if (window_pane_index(wp, &idx) != 0)
|
||||
fatalx("index not found");
|
||||
ctx->error(ctx, "pane still active: %s:%u.%u",
|
||||
cmdq_error(cmdq, "pane still active: %s:%u.%u",
|
||||
s->name, wl->idx, idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -78,8 +77,8 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd = args->argv[0];
|
||||
else
|
||||
cmd = NULL;
|
||||
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||
ctx->error(ctx, "respawn pane failed: %s", cause);
|
||||
if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn pane failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(&env);
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Respawn a window (restart the command). Kill existing if -k given.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_respawn_window_entry = {
|
||||
"respawn-window", "respawnw",
|
||||
@@ -35,12 +35,11 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_respawn_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -51,7 +50,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
const char *cmd;
|
||||
char *cause;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
@@ -59,7 +58,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
ctx->error(ctx,
|
||||
cmdq_error(cmdq,
|
||||
"window still active: %s:%d", s->name, wl->idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -80,14 +79,14 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd = args->argv[0];
|
||||
else
|
||||
cmd = NULL;
|
||||
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||
if (window_pane_spawn(wp, cmd, NULL, -1, &env, s->tio, &cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn window failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(&env);
|
||||
server_destroy_pane(wp);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
layout_init(w);
|
||||
layout_init(w, wp);
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
void cmd_rotate_window_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_rotate_window_entry = {
|
||||
"rotate-window", "rotatew",
|
||||
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
"[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_rotate_window_key_binding,
|
||||
NULL,
|
||||
cmd_rotate_window_exec
|
||||
};
|
||||
|
||||
@@ -46,7 +45,7 @@ cmd_rotate_window_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -55,7 +54,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct layout_cell *lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
|
||||
113
cmd-run-shell.c
113
cmd-run-shell.c
@@ -29,65 +29,114 @@
|
||||
* Runs a command without a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
|
||||
void cmd_run_shell_callback(struct job *);
|
||||
void cmd_run_shell_free(void *);
|
||||
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_run_shell_callback(struct job *);
|
||||
void cmd_run_shell_free(void *);
|
||||
void cmd_run_shell_print(struct job *, const char *);
|
||||
|
||||
const struct cmd_entry cmd_run_shell_entry = {
|
||||
"run-shell", "run",
|
||||
"", 1, 1,
|
||||
"command",
|
||||
"bt:", 1, 1,
|
||||
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_run_shell_exec
|
||||
};
|
||||
|
||||
struct cmd_run_shell_data {
|
||||
char *cmd;
|
||||
struct cmd_ctx ctx;
|
||||
struct cmd_q *cmdq;
|
||||
int bflag;
|
||||
int wp_id;
|
||||
};
|
||||
|
||||
void
|
||||
cmd_run_shell_print(struct job *job, const char *msg)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct window_pane *wp = NULL;
|
||||
|
||||
if (cdata->wp_id != -1)
|
||||
wp = window_pane_find_by_id(cdata->wp_id);
|
||||
if (wp == NULL) {
|
||||
cmdq_print(cdata->cmdq, "%s", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) == 0)
|
||||
window_copy_init_for_output(wp);
|
||||
if (wp->mode == &window_copy_mode)
|
||||
window_copy_add(wp, "%s", msg);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_run_shell_data *cdata;
|
||||
const char *shellcmd = args->argv[0];
|
||||
char *shellcmd;
|
||||
struct client *c;
|
||||
struct session *s = NULL;
|
||||
struct winlink *wl = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
struct format_tree *ft;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
|
||||
else {
|
||||
c = cmd_find_client(cmdq, NULL, 1);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
s = c->session;
|
||||
wl = s->curw;
|
||||
wp = wl->window->active;
|
||||
}
|
||||
}
|
||||
|
||||
ft = format_create();
|
||||
if (s != NULL)
|
||||
format_session(ft, s);
|
||||
if (s != NULL && wl != NULL)
|
||||
format_winlink(ft, s, wl);
|
||||
if (wp != NULL)
|
||||
format_window_pane(ft, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(args->argv[0]);
|
||||
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
|
||||
cdata->cmd = shellcmd;
|
||||
cdata->bflag = args_has(args, 'b');
|
||||
cdata->wp_id = wp != NULL ? (int) wp->id : -1;
|
||||
|
||||
if (ctx->cmdclient != NULL)
|
||||
ctx->cmdclient->references++;
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references++;
|
||||
cdata->cmdq = cmdq;
|
||||
cmdq->references++;
|
||||
|
||||
job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||
job_run(shellcmd, s, cmd_run_shell_callback, cmd_run_shell_free, cdata);
|
||||
|
||||
return (CMD_RETURN_YIELD); /* don't let client exit */
|
||||
if (cdata->bflag)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_run_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
char *cmd, *msg, *line;
|
||||
size_t size;
|
||||
int retcode;
|
||||
u_int lines;
|
||||
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
|
||||
return;
|
||||
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
|
||||
if (cmdq->dead)
|
||||
return;
|
||||
cmd = cdata->cmd;
|
||||
|
||||
lines = 0;
|
||||
do {
|
||||
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmd_run_shell_print(job, line);
|
||||
free(line);
|
||||
lines++;
|
||||
}
|
||||
} while (line != NULL);
|
||||
@@ -98,14 +147,12 @@ cmd_run_shell_callback(struct job *job)
|
||||
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||
line[size] = '\0';
|
||||
|
||||
ctx->print(ctx, "%s", line);
|
||||
cmd_run_shell_print(job, line);
|
||||
lines++;
|
||||
|
||||
free(line);
|
||||
}
|
||||
|
||||
cmd = cdata->cmd;
|
||||
|
||||
msg = NULL;
|
||||
if (WIFEXITED(job->status)) {
|
||||
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||
@@ -115,10 +162,10 @@ cmd_run_shell_callback(struct job *job)
|
||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||
}
|
||||
if (msg != NULL) {
|
||||
if (lines != 0)
|
||||
ctx->print(ctx, "%s", msg);
|
||||
if (lines == 0)
|
||||
cmdq_info(cmdq, "%s", msg);
|
||||
else
|
||||
ctx->info(ctx, "%s", msg);
|
||||
cmd_run_shell_print(job, msg);
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
@@ -127,14 +174,10 @@ void
|
||||
cmd_run_shell_free(void *data)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = data;
|
||||
struct cmd_ctx *ctx = &cdata->ctx;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
|
||||
if (ctx->cmdclient != NULL) {
|
||||
ctx->cmdclient->references--;
|
||||
ctx->cmdclient->flags |= CLIENT_EXIT;
|
||||
}
|
||||
if (ctx->curclient != NULL)
|
||||
ctx->curclient->references--;
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -29,7 +31,7 @@
|
||||
* Saves a paste buffer to a file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_save_buffer_entry = {
|
||||
"save-buffer", "saveb",
|
||||
@@ -37,83 +39,128 @@ const struct cmd_entry cmd_save_buffer_entry = {
|
||||
"[-a] " CMD_BUFFER_USAGE " path",
|
||||
0,
|
||||
NULL,
|
||||
cmd_save_buffer_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_show_buffer_entry = {
|
||||
"show-buffer", "showb",
|
||||
"b:", 0, 0,
|
||||
CMD_BUFFER_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
cmd_save_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = ctx->cmdclient;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
const char *path, *newpath, *wd;
|
||||
char *cause;
|
||||
int buffer;
|
||||
mode_t mask;
|
||||
const char *path;
|
||||
char *cause, *start, *end, *msg;
|
||||
size_t size, used, msglen;
|
||||
int cwd, fd, buffer;
|
||||
FILE *f;
|
||||
|
||||
if (!args_has(args, 'b')) {
|
||||
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||
ctx->error(ctx, "no buffers");
|
||||
cmdq_error(cmdq, "no buffers");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
pb = paste_get_index(&global_buffers, buffer);
|
||||
if (pb == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
path = args->argv[0];
|
||||
if (self->entry == &cmd_show_buffer_entry)
|
||||
path = "-";
|
||||
else
|
||||
path = args->argv[0];
|
||||
if (strcmp(path, "-") == 0) {
|
||||
if (c == NULL) {
|
||||
ctx->error(ctx, "%s: can't write to stdout", path);
|
||||
cmdq_error(cmdq, "can't write to stdout");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
evbuffer_add(c->stdout_data, pb->data, pb->size);
|
||||
server_push_stdout(c);
|
||||
} else {
|
||||
if (c != NULL)
|
||||
wd = c->cwd;
|
||||
else if ((s = cmd_current_session(ctx, 0)) != NULL) {
|
||||
wd = options_get_string(&s->options, "default-path");
|
||||
if (*wd == '\0')
|
||||
wd = s->cwd;
|
||||
} else
|
||||
wd = NULL;
|
||||
if (wd != NULL && *wd != '\0') {
|
||||
newpath = get_full_path(wd, path);
|
||||
if (newpath != NULL)
|
||||
path = newpath;
|
||||
}
|
||||
|
||||
mask = umask(S_IRWXG | S_IRWXO);
|
||||
if (args_has(self->args, 'a'))
|
||||
f = fopen(path, "ab");
|
||||
else
|
||||
f = fopen(path, "wb");
|
||||
umask(mask);
|
||||
if (f == NULL) {
|
||||
ctx->error(ctx, "%s: %s", path, strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||
ctx->error(ctx, "%s: fwrite error", path);
|
||||
fclose(f);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
fclose(f);
|
||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
||||
goto do_stdout;
|
||||
goto do_print;
|
||||
}
|
||||
|
||||
if (c != NULL && c->session == NULL)
|
||||
cwd = c->cwd;
|
||||
else if ((s = cmd_current_session(cmdq, 0)) != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = AT_FDCWD;
|
||||
|
||||
f = NULL;
|
||||
if (args_has(self->args, 'a')) {
|
||||
fd = openat(cwd, path, O_CREAT|O_RDWR|O_APPEND, 0600);
|
||||
if (fd != -1)
|
||||
f = fdopen(fd, "ab");
|
||||
} else {
|
||||
fd = openat(cwd, path, O_CREAT|O_RDWR, 0600);
|
||||
if (fd != -1)
|
||||
f = fdopen(fd, "wb");
|
||||
}
|
||||
if (f == NULL) {
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
|
||||
cmdq_error(cmdq, "%s: fwrite error", path);
|
||||
fclose(f);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
do_stdout:
|
||||
evbuffer_add(c->stdout_data, pb->data, pb->size);
|
||||
server_push_stdout(c);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
do_print:
|
||||
if (pb->size > (INT_MAX / 4) - 1) {
|
||||
cmdq_error(cmdq, "buffer too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
msg = NULL;
|
||||
msglen = 0;
|
||||
|
||||
used = 0;
|
||||
while (used != pb->size) {
|
||||
start = pb->data + used;
|
||||
end = memchr(start, '\n', pb->size - used);
|
||||
if (end != NULL)
|
||||
size = end - start;
|
||||
else
|
||||
size = pb->size - used;
|
||||
|
||||
msglen = size * 4 + 1;
|
||||
msg = xrealloc(msg, 1, msglen);
|
||||
|
||||
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
|
||||
cmdq_print(cmdq, "%s", msg);
|
||||
|
||||
used += size + (end != NULL);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -25,15 +25,14 @@
|
||||
*/
|
||||
|
||||
void cmd_select_layout_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_select_layout_entry = {
|
||||
"select-layout", "selectl",
|
||||
"nprut:", 0, 1,
|
||||
"[-npUu] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||
"npt:", 0, 1,
|
||||
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||
0,
|
||||
cmd_select_layout_key_binding,
|
||||
NULL,
|
||||
cmd_select_layout_exec
|
||||
};
|
||||
|
||||
@@ -43,7 +42,6 @@ const struct cmd_entry cmd_next_layout_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_select_layout_exec
|
||||
};
|
||||
|
||||
@@ -53,7 +51,6 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_select_layout_exec
|
||||
};
|
||||
|
||||
@@ -76,14 +73,6 @@ cmd_select_layout_key_binding(struct cmd *self, int key)
|
||||
case '5' | KEYC_ESCAPE:
|
||||
self->args = args_create(1, "tiled");
|
||||
break;
|
||||
case 'u':
|
||||
self->args = args_create(0);
|
||||
args_set(self->args, 'u', NULL);
|
||||
break;
|
||||
case 'U':
|
||||
self->args = args_create(0);
|
||||
args_set(self->args, 'U', NULL);
|
||||
break;
|
||||
default:
|
||||
self->args = args_create(0);
|
||||
break;
|
||||
@@ -91,17 +80,16 @@ cmd_select_layout_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
const char *layoutname;
|
||||
int next, previous, layout;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
next = self->entry == &cmd_next_layout_entry;
|
||||
if (args_has(self->args, 'n'))
|
||||
@@ -110,28 +98,13 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'p'))
|
||||
previous = 1;
|
||||
|
||||
layout_list_add(w);
|
||||
if (args_has(self->args, 'U')) {
|
||||
if ((layoutname = layout_list_redo(w)) == NULL) {
|
||||
ctx->info(ctx, "no more layout history");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
goto set_layout;
|
||||
} else if (args_has(self->args, 'u')) {
|
||||
if ((layoutname = layout_list_undo(w)) == NULL) {
|
||||
ctx->info(ctx, "no more layout history");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
goto set_layout;
|
||||
}
|
||||
|
||||
if (next || previous) {
|
||||
if (next)
|
||||
layout = layout_set_next(wl->window);
|
||||
else
|
||||
layout = layout_set_previous(wl->window);
|
||||
server_redraw_window(wl->window);
|
||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -142,20 +115,18 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (layout != -1) {
|
||||
layout = layout_set_select(wl->window, layout);
|
||||
server_redraw_window(wl->window);
|
||||
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
|
||||
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args->argc == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
layoutname = args->argv[0];
|
||||
|
||||
set_layout:
|
||||
if (layout_parse(wl->window, layoutname) == -1) {
|
||||
ctx->error(ctx, "can't set layout: %s", layoutname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (args->argc != 0) {
|
||||
layoutname = args->argv[0];
|
||||
if (layout_parse(wl->window, layoutname) == -1) {
|
||||
cmdq_error(cmdq, "can't set layout: %s", layoutname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
cmdq_info(cmdq, "arranging in: %s", layoutname);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
ctx->info(ctx, "arranging in: %s", layoutname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
void cmd_select_pane_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_select_pane_entry = {
|
||||
"select-pane", "selectp",
|
||||
@@ -33,7 +33,6 @@ const struct cmd_entry cmd_select_pane_entry = {
|
||||
"[-lDLRU] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
cmd_select_pane_key_binding,
|
||||
NULL,
|
||||
cmd_select_pane_exec
|
||||
};
|
||||
|
||||
@@ -43,7 +42,6 @@ const struct cmd_entry cmd_last_pane_entry = {
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_select_pane_exec
|
||||
};
|
||||
|
||||
@@ -64,22 +62,23 @@ cmd_select_pane_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (wl->window->last == NULL) {
|
||||
ctx->error(ctx, "no last pane");
|
||||
cmdq_error(cmdq, "no last pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
server_unzoom_window(wl->window);
|
||||
window_set_active_pane(wl->window, wl->window->last);
|
||||
server_status_window(wl->window);
|
||||
server_redraw_window_borders(wl->window);
|
||||
@@ -87,11 +86,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
server_unzoom_window(wp->window);
|
||||
if (!window_pane_visible(wp)) {
|
||||
ctx->error(ctx, "pane not visible");
|
||||
cmdq_error(cmdq, "pane not visible");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else if (args_has(self->args, 'D'))
|
||||
wp = window_pane_find_down(wp);
|
||||
if (wp == NULL) {
|
||||
ctx->error(ctx, "pane not found");
|
||||
cmdq_error(cmdq, "pane not found");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,15 +27,14 @@
|
||||
*/
|
||||
|
||||
void cmd_select_window_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_select_window_entry = {
|
||||
"select-window", "selectw",
|
||||
"lnpt:", 0, 0,
|
||||
"[-lnp] " CMD_TARGET_WINDOW_USAGE,
|
||||
"lnpTt:", 0, 0,
|
||||
"[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
cmd_select_window_key_binding,
|
||||
NULL,
|
||||
cmd_select_window_exec
|
||||
};
|
||||
|
||||
@@ -45,7 +44,6 @@ const struct cmd_entry cmd_next_window_entry = {
|
||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
cmd_select_window_key_binding,
|
||||
NULL,
|
||||
cmd_select_window_exec
|
||||
};
|
||||
|
||||
@@ -55,7 +53,6 @@ const struct cmd_entry cmd_previous_window_entry = {
|
||||
"[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
cmd_select_window_key_binding,
|
||||
NULL,
|
||||
cmd_select_window_exec
|
||||
};
|
||||
|
||||
@@ -65,7 +62,6 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_select_window_exec
|
||||
};
|
||||
|
||||
@@ -84,7 +80,7 @@ cmd_select_window_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -102,35 +98,45 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
last = 1;
|
||||
|
||||
if (next || previous || last) {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
activity = args_has(self->args, 'a');
|
||||
if (next) {
|
||||
if (session_next(s, activity) != 0) {
|
||||
ctx->error(ctx, "no next window");
|
||||
cmdq_error(cmdq, "no next window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (previous) {
|
||||
if (session_previous(s, activity) != 0) {
|
||||
ctx->error(ctx, "no previous window");
|
||||
cmdq_error(cmdq, "no previous window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (session_last(s) != 0) {
|
||||
ctx->error(ctx, "no last window");
|
||||
cmdq_error(cmdq, "no last window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
server_redraw_session(s);
|
||||
} else {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (session_select(s, wl->idx) == 0)
|
||||
/*
|
||||
* If -T and select-window is invoked on same window as
|
||||
* current, switch to previous window.
|
||||
*/
|
||||
if (args_has(self->args, 'T') && wl == s->curw) {
|
||||
if (session_last(s) != 0) {
|
||||
cmdq_error(cmdq, "no last window");
|
||||
return (-1);
|
||||
}
|
||||
server_redraw_session(s);
|
||||
} else if (session_select(s, wl->idx) == 0)
|
||||
server_redraw_session(s);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
@@ -27,31 +27,48 @@
|
||||
* Send keys to client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_send_keys_entry = {
|
||||
"send-keys", "send",
|
||||
"lRt:", 0, -1,
|
||||
"[-lR] [-t target-pane] key ...",
|
||||
"[-lR] " CMD_TARGET_PANE_USAGE " key ...",
|
||||
0,
|
||||
NULL,
|
||||
cmd_send_keys_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_send_prefix_entry = {
|
||||
"send-prefix", NULL,
|
||||
"2t:", 0, 0,
|
||||
"[-2] " CMD_TARGET_PANE_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
cmd_send_keys_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
struct session *s;
|
||||
struct input_ctx *ictx;
|
||||
const char *str;
|
||||
const u_char *str;
|
||||
int i, key;
|
||||
|
||||
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
|
||||
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (self->entry == &cmd_send_prefix_entry) {
|
||||
if (args_has(args, '2'))
|
||||
key = options_get_number(&s->options, "prefix2");
|
||||
else
|
||||
key = options_get_number(&s->options, "prefix");
|
||||
window_pane_key(wp, s, key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'R')) {
|
||||
ictx = &wp->ictx;
|
||||
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* 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 <sys/utsname.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Show various information about server.
|
||||
*/
|
||||
|
||||
enum cmd_retval 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
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct tty_term *term;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct tty_code *code;
|
||||
const 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;
|
||||
time_t t;
|
||||
u_int lines, ulines;
|
||||
size_t size, usize;
|
||||
|
||||
tim = ctime(&start_time);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
ctx->print(ctx,
|
||||
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
|
||||
ctx->print(
|
||||
ctx, "socket path %s, debug level %d", socket_path, debug_level);
|
||||
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)
|
||||
ctx->print(ctx, "configuration file is %s", cfg_file);
|
||||
else
|
||||
ctx->print(ctx, "configuration file not specified");
|
||||
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Clients:");
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
continue;
|
||||
|
||||
ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
|
||||
"xterm=%u] [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->tty.tio.c_cc[VERASE], c->tty.xterm_version,
|
||||
c->flags, c->tty.flags, c->references);
|
||||
}
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Sessions: [%zu/%zu]",
|
||||
sizeof (struct grid_cell), sizeof (struct grid_utf8));
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
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]", s->idx, s->name,
|
||||
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
|
||||
"references=%u, last layout=%d]", wl->idx, w->name,
|
||||
w->sx, w->sy, w->flags, w->references,
|
||||
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++) {
|
||||
gl = &gd->linedata[k];
|
||||
if (gl->celldata != NULL) {
|
||||
lines++;
|
||||
size += gl->cellsize *
|
||||
sizeof *gl->celldata;
|
||||
}
|
||||
if (gl->utf8data != NULL) {
|
||||
ulines++;
|
||||
usize += gl->utf8size *
|
||||
sizeof *gl->utf8data;
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "%6u: %s %lu %d %u/%u, %zu "
|
||||
"bytes; UTF-8 %u/%u, %zu bytes", j,
|
||||
wp->tty, (u_long) wp->pid, wp->fd, lines,
|
||||
gd->hsize + gd->sy, size, ulines,
|
||||
gd->hsize + gd->sy, usize);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Terminals:");
|
||||
LIST_FOREACH(term, &tty_terms, entry) {
|
||||
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
|
||||
term->name, term->references, term->flags);
|
||||
for (i = 0; i < NTTYCODE; i++) {
|
||||
ent = &tty_term_codes[i];
|
||||
code = &term->codes[ent->code];
|
||||
switch (code->type) {
|
||||
case TTYCODE_NONE:
|
||||
ctx->print(ctx, "%2u: %s: [missing]",
|
||||
ent->code, ent->name);
|
||||
break;
|
||||
case TTYCODE_STRING:
|
||||
strnvis(out, code->value.string, sizeof out,
|
||||
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||
ctx->print(ctx, "%2u: %s: (string) %s",
|
||||
ent->code, ent->name, out);
|
||||
break;
|
||||
case TTYCODE_NUMBER:
|
||||
ctx->print(ctx, "%2u: %s: (number) %d",
|
||||
ent->code, ent->name, code->value.number);
|
||||
break;
|
||||
case TTYCODE_FLAG:
|
||||
ctx->print(ctx, "%2u: %s: (flag) %s",
|
||||
ent->code, ent->name,
|
||||
code->value.flag ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx->print(ctx, "%s", "");
|
||||
|
||||
ctx->print(ctx, "Jobs:");
|
||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
|
||||
job->cmd, job->fd, job->pid, job->status);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
* Add or set a paste buffer.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_set_buffer_entry = {
|
||||
"set-buffer", "setb",
|
||||
@@ -35,12 +35,11 @@ const struct cmd_entry cmd_set_buffer_entry = {
|
||||
CMD_BUFFER_USAGE " data",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_set_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
u_int limit;
|
||||
@@ -60,14 +59,14 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
cmdq_error(cmdq, "buffer %s", cause);
|
||||
free(cause);
|
||||
free(pdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
cmdq_error(cmdq, "no buffer %d", buffer);
|
||||
free(pdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Set an environment variable.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_set_environment_entry = {
|
||||
"set-environment", "setenv",
|
||||
@@ -35,12 +35,11 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_set_environment_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -49,15 +48,15 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
|
||||
name = args->argv[0];
|
||||
if (*name == '\0') {
|
||||
ctx->error(ctx, "empty variable name");
|
||||
cmdq_error(cmdq, "empty variable name");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (strchr(name, '=') != NULL) {
|
||||
ctx->error(ctx, "variable name contains =");
|
||||
cmdq_error(cmdq, "variable name contains =");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args->argc < 1)
|
||||
if (args->argc < 2)
|
||||
value = NULL;
|
||||
else
|
||||
value = args->argv[1];
|
||||
@@ -65,26 +64,26 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = &global_environ;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
env = &s->environ;
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'u')) {
|
||||
if (value != NULL) {
|
||||
ctx->error(ctx, "can't specify a value with -u");
|
||||
cmdq_error(cmdq, "can't specify a value with -u");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_unset(env, name);
|
||||
} else if (args_has(self->args, 'r')) {
|
||||
if (value != NULL) {
|
||||
ctx->error(ctx, "can't specify a value with -r");
|
||||
cmdq_error(cmdq, "can't specify a value with -r");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_set(env, name, NULL);
|
||||
} else {
|
||||
if (value == NULL) {
|
||||
ctx->error(ctx, "no value specified");
|
||||
cmdq_error(cmdq, "no value specified");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_set(env, name, value);
|
||||
|
||||
231
cmd-set-option.c
231
cmd-set-option.c
@@ -27,59 +27,63 @@
|
||||
* Set an option.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
||||
enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *,
|
||||
const char *, const char *);
|
||||
|
||||
int cmd_set_option_unset(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
int cmd_set_option_set(struct cmd *, struct cmd_ctx *,
|
||||
int cmd_set_option_set(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
|
||||
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *,
|
||||
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
|
||||
const struct cmd_entry cmd_set_option_entry = {
|
||||
"set-option", "set",
|
||||
"agqst:uw", 1, 2,
|
||||
"[-agsquw] [-t target-session|target-window] option [value]",
|
||||
"agoqst:uw", 1, 2,
|
||||
"[-agosquw] [-t target-session|target-window] option [value]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_set_option_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_set_window_option_entry = {
|
||||
"set-window-option", "setw",
|
||||
"agqt:u", 1, 2,
|
||||
"[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
"agoqt:u", 1, 2,
|
||||
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_set_option_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const struct options_table_entry *table, *oe;
|
||||
@@ -94,7 +98,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
/* Get the option name and value. */
|
||||
optstr = args->argv[0];
|
||||
if (*optstr == '\0') {
|
||||
ctx->error(ctx, "invalid option");
|
||||
cmdq_error(cmdq, "invalid option");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args->argc < 2)
|
||||
@@ -102,14 +106,18 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
else
|
||||
valstr = args->argv[1];
|
||||
|
||||
/* Is this a user option? */
|
||||
if (*optstr == '@')
|
||||
return (cmd_set_option_user(self, cmdq, optstr, valstr));
|
||||
|
||||
/* Find the option entry, try each table. */
|
||||
table = oe = NULL;
|
||||
if (options_table_find(optstr, &table, &oe) != 0) {
|
||||
ctx->error(ctx, "ambiguous option: %s", optstr);
|
||||
cmdq_error(cmdq, "ambiguous option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (oe == NULL) {
|
||||
ctx->error(ctx, "unknown option: %s", optstr);
|
||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -120,36 +128,51 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_w_options;
|
||||
else {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||
if (wl == NULL)
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
||||
if (wl == NULL) {
|
||||
cmdq_error(cmdq,
|
||||
"couldn't set '%s'%s", optstr,
|
||||
(!args_has(args, 't') && !args_has(args,
|
||||
'g')) ? " need target window or -g" : "");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
oo = &wl->window->options;
|
||||
}
|
||||
} else if (table == session_options_table) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_s_options;
|
||||
else {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL) {
|
||||
cmdq_error(cmdq,
|
||||
"couldn't set '%s'%s", optstr,
|
||||
(!args_has(args, 't') && !args_has(args,
|
||||
'g')) ? " need target session or -g" : "");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
oo = &s->options;
|
||||
}
|
||||
} else {
|
||||
ctx->error(ctx, "unknown table");
|
||||
cmdq_error(cmdq, "unknown table");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Unset or set the option. */
|
||||
if (args_has(args, 'u')) {
|
||||
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
||||
if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0)
|
||||
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
|
||||
if (!args_has(args, 'q'))
|
||||
cmdq_print(cmdq, "already set: %s", optstr);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Start or stop timers when automatic-rename changed. */
|
||||
if (strcmp (oe->name, "automatic-rename") == 0) {
|
||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
||||
continue;
|
||||
@@ -171,31 +194,95 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Set user option. */
|
||||
enum cmd_retval
|
||||
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr,
|
||||
const char *valstr)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct options *oo;
|
||||
|
||||
if (args_has(args, 's'))
|
||||
oo = &global_options;
|
||||
else if (args_has(self->args, 'w') ||
|
||||
self->entry == &cmd_set_window_option_entry) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_w_options;
|
||||
else {
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
oo = &wl->window->options;
|
||||
}
|
||||
} else {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_s_options;
|
||||
else {
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
oo = &s->options;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
if (options_find1(oo, optstr) == NULL) {
|
||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (valstr != NULL) {
|
||||
cmdq_error(cmdq, "value passed to unset option: %s",
|
||||
optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
options_remove(oo, optstr);
|
||||
} else {
|
||||
if (valstr == NULL) {
|
||||
cmdq_error(cmdq, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
|
||||
if (!args_has(args, 'q'))
|
||||
cmdq_print(cmdq, "already set: %s", optstr);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
options_set_string(oo, optstr, "%s", valstr);
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_info(cmdq, "set option: %s -> %s", optstr,
|
||||
valstr);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
/* Unset an option. */
|
||||
int
|
||||
cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
if (args_has(args, 'g')) {
|
||||
ctx->error(ctx, "can't unset global option: %s", oe->name);
|
||||
cmdq_error(cmdq, "can't unset global option: %s", oe->name);
|
||||
return (-1);
|
||||
}
|
||||
if (value != NULL) {
|
||||
ctx->error(ctx, "value passed to unset option: %s", oe->name);
|
||||
cmdq_error(cmdq, "value passed to unset option: %s", oe->name);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
options_remove(oo, oe->name);
|
||||
if (!args_has(args, 'q'))
|
||||
ctx->info(ctx, "unset option: %s", oe->name);
|
||||
cmdq_info(cmdq, "unset option: %s", oe->name);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set an option. */
|
||||
int
|
||||
cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
@@ -203,46 +290,53 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
|
||||
const char *s;
|
||||
|
||||
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
|
||||
ctx->error(ctx, "empty value");
|
||||
cmdq_error(cmdq, "empty value");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
o = NULL;
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_STRING:
|
||||
o = cmd_set_option_string(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_string(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
case OPTIONS_TABLE_NUMBER:
|
||||
o = cmd_set_option_number(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_number(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
case OPTIONS_TABLE_KEY:
|
||||
o = cmd_set_option_key(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_key(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
case OPTIONS_TABLE_COLOUR:
|
||||
o = cmd_set_option_colour(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_colour(self, cmdq, oe, oo, value);
|
||||
if (o != NULL)
|
||||
style_update_new(oo, o->name, oe->style);
|
||||
break;
|
||||
case OPTIONS_TABLE_ATTRIBUTES:
|
||||
o = cmd_set_option_attributes(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_attributes(self, cmdq, oe, oo, value);
|
||||
if (o != NULL)
|
||||
style_update_new(oo, o->name, oe->style);
|
||||
break;
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
o = cmd_set_option_flag(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_flag(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
case OPTIONS_TABLE_CHOICE:
|
||||
o = cmd_set_option_choice(self, ctx, oe, oo, value);
|
||||
o = cmd_set_option_choice(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
o = cmd_set_option_style(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
}
|
||||
if (o == NULL)
|
||||
return (-1);
|
||||
|
||||
s = options_table_print_entry(oe, o);
|
||||
s = options_table_print_entry(oe, o, 0);
|
||||
if (!args_has(args, 'q'))
|
||||
ctx->info(ctx, "set option: %s -> %s", oe->name, s);
|
||||
cmdq_info(cmdq, "set option: %s -> %s", oe->name, s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set a string option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
|
||||
cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
@@ -263,7 +357,7 @@ cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
|
||||
|
||||
/* Set a number option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_number(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
long long ll;
|
||||
@@ -271,7 +365,7 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "value is %s: %s", errstr, value);
|
||||
cmdq_error(cmdq, "value is %s: %s", errstr, value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -280,13 +374,13 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
/* Set a key option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
int key;
|
||||
|
||||
if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
|
||||
ctx->error(ctx, "bad key: %s", value);
|
||||
cmdq_error(cmdq, "bad key: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -295,13 +389,13 @@ cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
/* Set a colour option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
int colour;
|
||||
|
||||
if ((colour = colour_fromstring(value)) == -1) {
|
||||
ctx->error(ctx, "bad colour: %s", value);
|
||||
cmdq_error(cmdq, "bad colour: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -310,13 +404,13 @@ cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
/* Set an attributes option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_attributes(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
int attr;
|
||||
|
||||
if ((attr = attributes_fromstring(value)) == -1) {
|
||||
ctx->error(ctx, "bad attributes: %s", value);
|
||||
cmdq_error(cmdq, "bad attributes: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -325,7 +419,7 @@ cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
/* Set a flag option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
cmd_set_option_flag(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
{
|
||||
int flag;
|
||||
@@ -342,7 +436,7 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
strcasecmp(value, "no") == 0)
|
||||
flag = 0;
|
||||
else {
|
||||
ctx->error(ctx, "bad value: %s", value);
|
||||
cmdq_error(cmdq, "bad value: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
@@ -352,8 +446,9 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
|
||||
/* Set a choice option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
const struct options_table_entry *oe, struct options *oo, const char *value)
|
||||
cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
const char **choicep;
|
||||
int n, choice = -1;
|
||||
@@ -365,15 +460,35 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
|
||||
continue;
|
||||
|
||||
if (choice != -1) {
|
||||
ctx->error(ctx, "ambiguous value: %s", value);
|
||||
cmdq_error(cmdq, "ambiguous value: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
choice = n - 1;
|
||||
}
|
||||
if (choice == -1) {
|
||||
ctx->error(ctx, "unknown value: %s", value);
|
||||
cmdq_error(cmdq, "unknown value: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, choice));
|
||||
}
|
||||
|
||||
/* Set a style option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct options_entry *o;
|
||||
int append;
|
||||
|
||||
append = args_has(args, 'a');
|
||||
if ((o = options_set_style(oo, oe->name, value, append)) == NULL) {
|
||||
cmdq_error(cmdq, "bad style: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
style_update_old(oo, oe->name, &o->style);
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* 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 "tmux.h"
|
||||
|
||||
/*
|
||||
* Show a paste buffer.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_show_buffer_entry = {
|
||||
"show-buffer", "showb",
|
||||
"b:", 0, 0,
|
||||
CMD_BUFFER_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_show_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
int buffer;
|
||||
char *in, *buf, *ptr, *cause;
|
||||
size_t size, len;
|
||||
u_int width;
|
||||
|
||||
if ((s = cmd_find_session(ctx, NULL, 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (!args_has(args, 'b')) {
|
||||
if ((pb = paste_get_top(&global_buffers)) == NULL) {
|
||||
ctx->error(ctx, "no buffers");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
ctx->error(ctx, "buffer %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
pb = paste_get_index(&global_buffers, buffer);
|
||||
if (pb == NULL) {
|
||||
ctx->error(ctx, "no buffer %d", buffer);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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';
|
||||
|
||||
ctx->print(ctx, "%s", buf);
|
||||
len = 0;
|
||||
}
|
||||
} while (*ptr != '\0');
|
||||
|
||||
if (len != 0) {
|
||||
buf[len] = '\0';
|
||||
ctx->print(ctx, "%s", buf);
|
||||
}
|
||||
free(buf);
|
||||
|
||||
free(in);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
* Show environment.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_show_environment_entry = {
|
||||
"show-environment", "showenv",
|
||||
@@ -35,12 +35,11 @@ const struct cmd_entry cmd_show_environment_entry = {
|
||||
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_show_environment_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -50,7 +49,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = &global_environ;
|
||||
else {
|
||||
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
|
||||
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
env = &s->environ;
|
||||
}
|
||||
@@ -58,21 +57,21 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args->argc != 0) {
|
||||
envent = environ_find(env, args->argv[0]);
|
||||
if (envent == NULL) {
|
||||
ctx->error(ctx, "unknown variable: %s", args->argv[0]);
|
||||
cmdq_error(cmdq, "unknown variable: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (envent->value != NULL)
|
||||
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
|
||||
else
|
||||
ctx->print(ctx, "-%s", envent->name);
|
||||
cmdq_print(cmdq, "-%s", envent->name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
RB_FOREACH(envent, environ, env) {
|
||||
if (envent->value != NULL)
|
||||
ctx->print(ctx, "%s=%s", envent->name, envent->value);
|
||||
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
|
||||
else
|
||||
ctx->print(ctx, "-%s", envent->name);
|
||||
cmdq_print(cmdq, "-%s", envent->name);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -27,28 +28,133 @@
|
||||
* Show client message log.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_show_messages_entry = {
|
||||
"show-messages", "showmsgs",
|
||||
"t:", 0, 0,
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
"IJTt:", 0, 0,
|
||||
"[-IJT] " CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_show_messages_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_server_info_entry = {
|
||||
"server-info", "info",
|
||||
"", 0, 0,
|
||||
"",
|
||||
0,
|
||||
NULL,
|
||||
cmd_show_messages_exec
|
||||
};
|
||||
|
||||
void cmd_show_messages_server(struct cmd_q *);
|
||||
void cmd_show_messages_terminals(struct cmd_q *);
|
||||
void cmd_show_messages_jobs(struct cmd_q *);
|
||||
|
||||
void
|
||||
cmd_show_messages_server(struct cmd_q *cmdq)
|
||||
{
|
||||
char *tim;
|
||||
|
||||
tim = ctime(&start_time);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
cmdq_print(cmdq, "started %s", tim);
|
||||
cmdq_print(cmdq, "socket path %s", socket_path);
|
||||
cmdq_print(cmdq, "debug level %d", debug_level);
|
||||
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_show_messages_terminals(struct cmd_q *cmdq)
|
||||
{
|
||||
struct tty_term *term;
|
||||
const struct tty_term_code_entry *ent;
|
||||
struct tty_code *code;
|
||||
u_int i, n;
|
||||
char out[80];
|
||||
|
||||
n = 0;
|
||||
LIST_FOREACH(term, &tty_terms, entry) {
|
||||
cmdq_print(cmdq,
|
||||
"Terminal %u: %s [references=%u, flags=0x%x]:",
|
||||
n, term->name, term->references, term->flags);
|
||||
n++;
|
||||
for (i = 0; i < NTTYCODE; i++) {
|
||||
ent = &tty_term_codes[i];
|
||||
code = &term->codes[ent->code];
|
||||
switch (code->type) {
|
||||
case TTYCODE_NONE:
|
||||
cmdq_print(cmdq, "%4u: %s: [missing]",
|
||||
ent->code, ent->name);
|
||||
break;
|
||||
case TTYCODE_STRING:
|
||||
strnvis(out, code->value.string, sizeof out,
|
||||
VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||
cmdq_print(cmdq, "%4u: %s: (string) %s",
|
||||
ent->code, ent->name, out);
|
||||
break;
|
||||
case TTYCODE_NUMBER:
|
||||
cmdq_print(cmdq, "%4u: %s: (number) %d",
|
||||
ent->code, ent->name, code->value.number);
|
||||
break;
|
||||
case TTYCODE_FLAG:
|
||||
cmdq_print(cmdq, "%4u: %s: (flag) %s",
|
||||
ent->code, ent->name,
|
||||
code->value.flag ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cmd_show_messages_jobs(struct cmd_q *cmdq)
|
||||
{
|
||||
struct job *job;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||
cmdq_print(cmdq,
|
||||
"Job %u: %s [fd=%d, pid=%d, status=%d]",
|
||||
n, job->cmd, job->fd, job->pid, job->status);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct message_entry *msg;
|
||||
char *tim;
|
||||
u_int i;
|
||||
int done;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
done = 0;
|
||||
if (args_has(args, 'I') || self->entry == &cmd_server_info_entry) {
|
||||
cmd_show_messages_server(cmdq);
|
||||
done = 1;
|
||||
}
|
||||
if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
|
||||
if (done)
|
||||
cmdq_print(cmdq, "%s", "");
|
||||
cmd_show_messages_terminals(cmdq);
|
||||
done = 1;
|
||||
}
|
||||
if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
|
||||
if (done)
|
||||
cmdq_print(cmdq, "%s", "");
|
||||
cmd_show_messages_jobs(cmdq);
|
||||
done = 1;
|
||||
}
|
||||
if (done)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
|
||||
@@ -57,7 +163,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
tim = ctime(&msg->msg_time);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
ctx->print(ctx, "%s %s", tim, msg->msg);
|
||||
cmdq_print(cmdq, "%s %s", tim, msg->msg);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -27,38 +27,40 @@
|
||||
* Show options.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
|
||||
struct options *, int);
|
||||
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
|
||||
const struct options_table_entry *, struct options *);
|
||||
|
||||
const struct cmd_entry cmd_show_options_entry = {
|
||||
"show-options", "show",
|
||||
"gst:w", 0, 1,
|
||||
"[-gsw] [-t target-session|target-window] [option]",
|
||||
"gqst:vw", 0, 1,
|
||||
"[-gqsvw] [-t target-session|target-window] [option]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_show_options_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_show_window_options_entry = {
|
||||
"show-window-options", "showw",
|
||||
"gt:", 0, 1,
|
||||
"[-g] " CMD_TARGET_WINDOW_USAGE " [option]",
|
||||
"gvt:", 0, 1,
|
||||
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_show_options_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const struct options_table_entry *table, *oe;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
const struct options_table_entry *table;
|
||||
struct options *oo;
|
||||
struct options_entry *o;
|
||||
const char *optval;
|
||||
int quiet;
|
||||
|
||||
if (args_has(self->args, 's')) {
|
||||
oo = &global_options;
|
||||
@@ -69,7 +71,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_w_options;
|
||||
else {
|
||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
oo = &wl->window->options;
|
||||
@@ -79,34 +81,90 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = &global_s_options;
|
||||
else {
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
oo = &s->options;
|
||||
}
|
||||
}
|
||||
|
||||
if (args->argc != 0) {
|
||||
table = oe = NULL;
|
||||
if (options_table_find(args->argv[0], &table, &oe) != 0) {
|
||||
ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
|
||||
quiet = args_has(self->args, 'q');
|
||||
if (args->argc == 0)
|
||||
return (cmd_show_options_all(self, cmdq, table, oo));
|
||||
else
|
||||
return (cmd_show_options_one(self, cmdq, oo, quiet));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
|
||||
struct options *oo, int quiet)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const struct options_table_entry *table, *oe;
|
||||
struct options_entry *o;
|
||||
const char *optval;
|
||||
|
||||
if (*args->argv[0] == '@') {
|
||||
if ((o = options_find1(oo, args->argv[0])) == NULL) {
|
||||
if (quiet)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (oe == NULL) {
|
||||
ctx->error(ctx, "unknown option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(cmdq, "%s", o->str);
|
||||
else
|
||||
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
table = oe = NULL;
|
||||
if (options_table_find(args->argv[0], &table, &oe) != 0) {
|
||||
cmdq_error(cmdq, "ambiguous option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (oe == NULL) {
|
||||
if (quiet)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(cmdq, "%s", optval);
|
||||
else
|
||||
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *table, struct options *oo)
|
||||
{
|
||||
const struct options_table_entry *oe;
|
||||
struct options_entry *o;
|
||||
const char *optval;
|
||||
|
||||
RB_FOREACH(o, options_tree, &oo->tree) {
|
||||
if (*o->name == '@') {
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(cmdq, "%s", o->str);
|
||||
else
|
||||
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
||||
}
|
||||
}
|
||||
|
||||
for (oe = table; oe->name != NULL; oe++) {
|
||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
optval = options_table_print_entry(oe, o);
|
||||
ctx->print(ctx, "%s %s", oe->name, optval);
|
||||
} else {
|
||||
for (oe = table; oe->name != NULL; oe++) {
|
||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||
continue;
|
||||
optval = options_table_print_entry(oe, o);
|
||||
ctx->print(ctx, "%s %s", oe->name, optval);
|
||||
}
|
||||
continue;
|
||||
optval = options_table_print_entry(oe, o,
|
||||
args_has(self->args, 'v'));
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(cmdq, "%s", optval);
|
||||
else
|
||||
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -26,7 +26,10 @@
|
||||
* Sources a configuration file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
void cmd_source_file_show(struct cmd_q *);
|
||||
void cmd_source_file_done(struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_source_file_entry = {
|
||||
"source-file", "source",
|
||||
@@ -34,43 +37,75 @@ const struct cmd_entry cmd_source_file_entry = {
|
||||
"path",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_source_file_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct causelist causes;
|
||||
char *cause;
|
||||
struct window_pane *wp;
|
||||
int retval;
|
||||
u_int i;
|
||||
struct args *args = self->args;
|
||||
struct cmd_q *cmdq1;
|
||||
char *cause;
|
||||
|
||||
ARRAY_INIT(&causes);
|
||||
cmdq1 = cmdq_new(NULL);
|
||||
cmdq1->client = cmdq->client;
|
||||
cmdq1->emptyfn = cmd_source_file_done;
|
||||
cmdq1->data = cmdq;
|
||||
|
||||
retval = load_cfg(args->argv[0], ctx, &causes);
|
||||
if (ARRAY_EMPTY(&causes))
|
||||
return (retval);
|
||||
|
||||
if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
|
||||
wp = RB_MIN(sessions, &sessions)->curw->window->active;
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
window_copy_init_for_output(wp);
|
||||
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||
cause = ARRAY_ITEM(&causes, i);
|
||||
window_copy_add(wp, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
|
||||
cause = ARRAY_ITEM(&causes, i);
|
||||
ctx->print(ctx, "%s", cause);
|
||||
switch (load_cfg(args->argv[0], cmdq1, &cause)) {
|
||||
case -1:
|
||||
if (cfg_references == 0) {
|
||||
cmdq_free(cmdq1);
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
ARRAY_ADD(&cfg_causes, cause);
|
||||
/* FALLTHROUGH */
|
||||
case 0:
|
||||
if (cfg_references == 0)
|
||||
cmd_source_file_show(cmdq);
|
||||
cmdq_free(cmdq1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
ARRAY_FREE(&causes);
|
||||
|
||||
return (retval);
|
||||
cmdq->references++;
|
||||
cfg_references++;
|
||||
|
||||
cmdq_continue(cmdq1);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_show(struct cmd_q *cmdq)
|
||||
{
|
||||
u_int i;
|
||||
char *cause;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
|
||||
cause = ARRAY_ITEM(&cfg_causes, i);
|
||||
cmdq_print(cmdq, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
ARRAY_FREE(&cfg_causes);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_done(struct cmd_q *cmdq1)
|
||||
{
|
||||
struct cmd_q *cmdq = cmdq1->data;
|
||||
|
||||
if (cmdq1->client_exit >= 0)
|
||||
cmdq->client_exit = cmdq1->client_exit;
|
||||
|
||||
cmdq_free(cmdq1);
|
||||
|
||||
cfg_references--;
|
||||
|
||||
if (cmdq_free(cmdq))
|
||||
return;
|
||||
|
||||
if (cfg_references == 0)
|
||||
cmd_source_file_show(cmdq);
|
||||
cmdq_continue(cmdq);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
@@ -28,16 +31,15 @@
|
||||
*/
|
||||
|
||||
void cmd_split_window_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_split_window_entry = {
|
||||
"split-window", "splitw",
|
||||
"c:dF:l:hp:Pt:v", 0, 1,
|
||||
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
|
||||
"[-t target-pane] [command]",
|
||||
CMD_TARGET_PANE_USAGE " [command]",
|
||||
0,
|
||||
cmd_split_window_key_binding,
|
||||
NULL,
|
||||
cmd_split_window_exec
|
||||
};
|
||||
|
||||
@@ -50,7 +52,7 @@ cmd_split_window_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -58,20 +60,19 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct window *w;
|
||||
struct window_pane *wp, *new_wp = NULL;
|
||||
struct environ env;
|
||||
const char *cmd, *cwd, *shell;
|
||||
char *cause, *new_cause;
|
||||
const char *cmd, *shell, *template;
|
||||
char *cause, *new_cause, *cp;
|
||||
u_int hlimit;
|
||||
int size, percentage;
|
||||
int size, percentage, cwd, fd = -1;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
const char *template;
|
||||
struct client *c;
|
||||
struct format_tree *ft;
|
||||
char *cp;
|
||||
|
||||
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
server_unzoom_window(w);
|
||||
|
||||
environ_init(&env);
|
||||
environ_copy(&global_environ, &env);
|
||||
@@ -82,7 +83,32 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd = options_get_string(&s->options, "default-command");
|
||||
else
|
||||
cmd = args->argv[0];
|
||||
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
|
||||
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, s->curw);
|
||||
format_window_pane(ft, s->curw->window->active);
|
||||
cp = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
|
||||
if (cp != NULL && *cp != '\0') {
|
||||
fd = open(cp, O_RDONLY|O_DIRECTORY);
|
||||
free(cp);
|
||||
if (fd == -1) {
|
||||
cmdq_error(cmdq, "bad working directory: %s",
|
||||
strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (cp != NULL)
|
||||
free(cp);
|
||||
cwd = fd;
|
||||
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
else
|
||||
cwd = s->cwd;
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'h'))
|
||||
@@ -142,26 +168,31 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
template = SPLIT_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create();
|
||||
if ((c = cmd_find_client(ctx, NULL)) != NULL)
|
||||
format_client(ft, c);
|
||||
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
|
||||
format_client(ft, c);
|
||||
format_session(ft, s);
|
||||
format_winlink(ft, s, wl);
|
||||
format_window_pane(ft, new_wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
ctx->print(ctx, "%s", cp);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
notify_window_layout_changed(w);
|
||||
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
environ_free(&env);
|
||||
if (new_wp != NULL)
|
||||
window_remove_pane(w, new_wp);
|
||||
ctx->error(ctx, "create pane failed: %s", cause);
|
||||
cmdq_error(cmdq, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
87
cmd-string.c
87
cmd-string.c
@@ -31,11 +31,12 @@
|
||||
* Parse a command from a string.
|
||||
*/
|
||||
|
||||
int cmd_string_getc(const char *, size_t *);
|
||||
void cmd_string_ungetc(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 *, size_t *);
|
||||
void cmd_string_ungetc(size_t *);
|
||||
void cmd_string_copy(char **, 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)
|
||||
@@ -58,7 +59,8 @@ cmd_string_ungetc(size_t *p)
|
||||
* string, or NULL for empty command.
|
||||
*/
|
||||
int
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
|
||||
u_int line, char **cause)
|
||||
{
|
||||
size_t p;
|
||||
int ch, i, argc, rval;
|
||||
@@ -84,26 +86,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
case '\'':
|
||||
if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
free(t);
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '"':
|
||||
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
free(t);
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '$':
|
||||
if ((t = cmd_string_variable(s, &p)) == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
free(t);
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '#':
|
||||
/* Comment: discard rest of line. */
|
||||
@@ -139,7 +132,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
*cmdlist = cmd_list_parse(argc, argv, cause);
|
||||
*cmdlist = cmd_list_parse(argc, argv, file, line, cause);
|
||||
if (*cmdlist == NULL)
|
||||
goto out;
|
||||
|
||||
@@ -147,12 +140,10 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
||||
goto out;
|
||||
case '~':
|
||||
if (buf == NULL) {
|
||||
if ((t = cmd_string_expand_tilde(s, &p)) == NULL)
|
||||
t = cmd_string_expand_tilde(s, &p);
|
||||
if (t == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
free(t);
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
@@ -181,6 +172,20 @@ out:
|
||||
return (rval);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_string_copy(char **dst, char *src, size_t *len)
|
||||
{
|
||||
size_t srclen;
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
*dst = xrealloc(*dst, 1, *len + srclen + 1);
|
||||
strlcpy(*dst + *len, src, srclen + 1);
|
||||
|
||||
*len += srclen;
|
||||
free(src);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
{
|
||||
@@ -220,10 +225,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
break;
|
||||
if ((t = cmd_string_variable(s, p)) == NULL)
|
||||
goto error;
|
||||
buf = xrealloc(buf, 1, len + strlen(t) + 1);
|
||||
strlcpy(buf + len, t, strlen(t) + 1);
|
||||
len += strlen(t);
|
||||
free(t);
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -316,10 +318,13 @@ cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct environ_entry *envent;
|
||||
char *home, *path, *username;
|
||||
char *home, *path, *user, *cp;
|
||||
int last;
|
||||
|
||||
home = NULL;
|
||||
if (cmd_string_getc(s, p) == '/') {
|
||||
|
||||
last = cmd_string_getc(s, p);
|
||||
if (last == EOF || last == '/' || last == ' '|| last == '\t') {
|
||||
envent = environ_find(&global_environ, "HOME");
|
||||
if (envent != NULL && *envent->value != '\0')
|
||||
home = envent->value;
|
||||
@@ -327,15 +332,27 @@ cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
home = pw->pw_dir;
|
||||
} else {
|
||||
cmd_string_ungetc(p);
|
||||
if ((username = cmd_string_string(s, p, '/', 0)) == NULL)
|
||||
return (NULL);
|
||||
if ((pw = getpwnam(username)) != NULL)
|
||||
|
||||
cp = user = xmalloc(strlen(s));
|
||||
for (;;) {
|
||||
last = cmd_string_getc(s, p);
|
||||
if (last == EOF || last == '/' || last == ' '|| last == '\t')
|
||||
break;
|
||||
*cp++ = last;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ((pw = getpwnam(user)) != NULL)
|
||||
home = pw->pw_dir;
|
||||
free(username);
|
||||
free(user);
|
||||
}
|
||||
|
||||
if (home == NULL)
|
||||
return (NULL);
|
||||
|
||||
xasprintf(&path, "%s/", home);
|
||||
if (last != EOF)
|
||||
xasprintf(&path, "%s%c", home, last);
|
||||
else
|
||||
xasprintf(&path, "%s", home);
|
||||
return (path);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Suspend client with SIGTSTP.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_suspend_client_entry = {
|
||||
"suspend-client", "suspendc",
|
||||
@@ -35,17 +35,16 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
||||
CMD_TARGET_CLIENT_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_suspend_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
tty_stop_tty(&c->tty);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
void cmd_swap_pane_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_swap_pane_entry = {
|
||||
"swap-pane", "swapp",
|
||||
@@ -35,7 +35,6 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
||||
"[-dDU] " CMD_SRCDST_PANE_USAGE,
|
||||
0,
|
||||
cmd_swap_pane_key_binding,
|
||||
NULL,
|
||||
cmd_swap_pane_exec
|
||||
};
|
||||
|
||||
@@ -50,7 +49,7 @@ cmd_swap_pane_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *src_wl, *dst_wl;
|
||||
@@ -59,10 +58,11 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct layout_cell *src_lc, *dst_lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &dst_wp);
|
||||
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &dst_wp);
|
||||
if (dst_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
dst_w = dst_wl->window;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
if (!args_has(args, 's')) {
|
||||
src_w = dst_w;
|
||||
@@ -74,14 +74,19 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
|
||||
if (src_wp == NULL)
|
||||
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
|
||||
} else
|
||||
return (CMD_RETURN_NORMAL);
|
||||
} else {
|
||||
src_wl = cmd_find_pane(cmdq, NULL, NULL, &src_wp);
|
||||
if (src_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src_w = src_wl->window;
|
||||
}
|
||||
} else {
|
||||
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
|
||||
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
|
||||
if (src_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src_w = src_wl->window;
|
||||
}
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (src_wp == dst_wp)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Swap one window with another.
|
||||
*/
|
||||
|
||||
int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_swap_window_entry = {
|
||||
"swap-window", "swapw",
|
||||
@@ -34,12 +34,11 @@ const struct cmd_entry cmd_swap_window_entry = {
|
||||
"[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_swap_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *target_src, *target_dst;
|
||||
@@ -49,17 +48,17 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct window *w;
|
||||
|
||||
target_src = args_get(args, 's');
|
||||
if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL)
|
||||
if ((wl_src = cmd_find_window(cmdq, target_src, &src)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
target_dst = args_get(args, 't');
|
||||
if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL)
|
||||
if ((wl_dst = cmd_find_window(cmdq, target_dst, &dst)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
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");
|
||||
cmdq_error(cmdq, "can't move window, sessions are grouped");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
void cmd_switch_client_key_binding(struct cmd *, int);
|
||||
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_switch_client_entry = {
|
||||
"switch-client", "switchc",
|
||||
@@ -36,7 +36,6 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
"[-lnpr] [-c target-client] [-t target-session]",
|
||||
CMD_READONLY,
|
||||
cmd_switch_client_key_binding,
|
||||
NULL,
|
||||
cmd_switch_client_exec
|
||||
};
|
||||
|
||||
@@ -58,47 +57,74 @@ cmd_switch_client_key_binding(struct cmd *self, int key)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct session *s = NULL;
|
||||
struct winlink *wl = NULL;
|
||||
struct window *w = NULL;
|
||||
struct window_pane *wp = NULL;
|
||||
const char *tflag;
|
||||
|
||||
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
|
||||
if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
if (c->flags & CLIENT_READONLY) {
|
||||
c->flags &= ~CLIENT_READONLY;
|
||||
ctx->info(ctx, "made client writable");
|
||||
cmdq_info(cmdq, "made client writable");
|
||||
} else {
|
||||
c->flags |= CLIENT_READONLY;
|
||||
ctx->info(ctx, "made client read-only");
|
||||
cmdq_info(cmdq, "made client read-only");
|
||||
}
|
||||
}
|
||||
|
||||
s = NULL;
|
||||
tflag = args_get(args, 't');
|
||||
if (args_has(args, 'n')) {
|
||||
if ((s = session_next_session(c->session)) == NULL) {
|
||||
ctx->error(ctx, "can't find next session");
|
||||
cmdq_error(cmdq, "can't find next session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
if ((s = session_previous_session(c->session)) == NULL) {
|
||||
ctx->error(ctx, "can't find previous session");
|
||||
cmdq_error(cmdq, "can't find previous session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'l')) {
|
||||
if (c->last_session != NULL && session_alive(c->last_session))
|
||||
s = c->last_session;
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "can't find last session");
|
||||
cmdq_error(cmdq, "can't find last session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
s = cmd_find_session(ctx, args_get(args, 't'), 0);
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if (tflag == NULL) {
|
||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else if (tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = cmd_lookup_windowid(tflag);
|
||||
if (w == NULL &&
|
||||
(wp = cmd_lookup_paneid(tflag)) != NULL)
|
||||
w = wp->window;
|
||||
if (w != NULL)
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
}
|
||||
|
||||
if (cmdq->client == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
session_set_current(s, wl);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
|
||||
@@ -26,9 +26,8 @@
|
||||
* Unbind key from command.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_unbind_key_check(struct args *);
|
||||
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int);
|
||||
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *);
|
||||
enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_q *, int);
|
||||
|
||||
const struct cmd_entry cmd_unbind_key_entry = {
|
||||
"unbind-key", "unbind",
|
||||
@@ -36,38 +35,36 @@ const struct cmd_entry cmd_unbind_key_entry = {
|
||||
"[-acn] [-t key-table] key",
|
||||
0,
|
||||
NULL,
|
||||
cmd_unbind_key_check,
|
||||
cmd_unbind_key_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unbind_key_check(struct args *args)
|
||||
{
|
||||
if (args_has(args, 'a') && args->argc != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (!args_has(args, 'a') && args->argc != 1)
|
||||
return (CMD_RETURN_ERROR);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct key_binding *bd;
|
||||
int key;
|
||||
|
||||
if (!args_has(args, 'a')) {
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
if (key == KEYC_NONE) {
|
||||
ctx->error(ctx, "unknown key: %s", args->argv[0]);
|
||||
if (args->argc != 1) {
|
||||
cmdq_error(cmdq, "missing key");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
if (key == KEYC_NONE) {
|
||||
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (args->argc != 0) {
|
||||
cmdq_error(cmdq, "key given with -a");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
key = KEYC_NONE;
|
||||
}
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_unbind_key_table(self, ctx, key));
|
||||
return (cmd_unbind_key_table(self, cmdq, key));
|
||||
|
||||
if (key == KEYC_NONE) {
|
||||
while (!RB_EMPTY(&key_bindings)) {
|
||||
@@ -84,7 +81,7 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||
cmd_unbind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename;
|
||||
@@ -93,7 +90,7 @@ cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
ctx->error(ctx, "unknown key table: %s", tablename);
|
||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Unlink a window, unless it would be destroyed by doing so (only one link).
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_unlink_window_entry = {
|
||||
"unlink-window", "unlinkw",
|
||||
@@ -32,12 +32,11 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
||||
"[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_unlink_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cmd_unlink_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -46,7 +45,7 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct session_group *sg;
|
||||
u_int references;
|
||||
|
||||
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
@@ -59,7 +58,7 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
references = 1;
|
||||
|
||||
if (!args_has(self->args, 'k') && w->references == references) {
|
||||
ctx->error(ctx, "window is only linked to one session");
|
||||
cmdq_error(cmdq, "window is only linked to one session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
196
cmd-wait-for.c
Normal file
196
cmd-wait-for.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
* Copyright (c) 2013 Thiago de Arruda <tpadilha84@gmail.com>
|
||||
*
|
||||
* 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"
|
||||
|
||||
/*
|
||||
* Block or wake a client on a named wait channel.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_wait_for_entry = {
|
||||
"wait-for", "wait",
|
||||
"LSU", 1, 1,
|
||||
"[-L|-S|-U] channel",
|
||||
0,
|
||||
NULL,
|
||||
cmd_wait_for_exec
|
||||
};
|
||||
|
||||
struct wait_channel {
|
||||
const char *name;
|
||||
int locked;
|
||||
|
||||
TAILQ_HEAD(, cmd_q) waiters;
|
||||
TAILQ_HEAD(, cmd_q) lockers;
|
||||
|
||||
RB_ENTRY(wait_channel) entry;
|
||||
};
|
||||
RB_HEAD(wait_channels, wait_channel);
|
||||
struct wait_channels wait_channels = RB_INITIALIZER(wait_channels);
|
||||
|
||||
int wait_channel_cmp(struct wait_channel *, struct wait_channel *);
|
||||
RB_PROTOTYPE(wait_channels, wait_channel, entry, wait_channel_cmp);
|
||||
RB_GENERATE(wait_channels, wait_channel, entry, wait_channel_cmp);
|
||||
|
||||
int
|
||||
wait_channel_cmp(struct wait_channel *wc1, struct wait_channel *wc2)
|
||||
{
|
||||
return (strcmp(wc1->name, wc2->name));
|
||||
}
|
||||
|
||||
enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *,
|
||||
struct wait_channel *);
|
||||
enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *,
|
||||
struct wait_channel *);
|
||||
enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *,
|
||||
struct wait_channel *);
|
||||
enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *,
|
||||
struct wait_channel *);
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *name = args->argv[0];
|
||||
struct wait_channel *wc, wc0;
|
||||
|
||||
wc0.name = name;
|
||||
wc = RB_FIND(wait_channels, &wait_channels, &wc0);
|
||||
|
||||
if (args_has(args, 'S'))
|
||||
return (cmd_wait_for_signal(cmdq, name, wc));
|
||||
if (args_has(args, 'L'))
|
||||
return (cmd_wait_for_lock(cmdq, name, wc));
|
||||
if (args_has(args, 'U'))
|
||||
return (cmd_wait_for_unlock(cmdq, name, wc));
|
||||
return (cmd_wait_for_wait(cmdq, name, wc));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_signal(struct cmd_q *cmdq, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
struct cmd_q *wq, *wq1;
|
||||
|
||||
if (wc == NULL || TAILQ_EMPTY(&wc->waiters)) {
|
||||
cmdq_error(cmdq, "no waiting clients on %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
TAILQ_FOREACH_SAFE(wq, &wc->waiters, waitentry, wq1) {
|
||||
TAILQ_REMOVE(&wc->waiters, wq, waitentry);
|
||||
if (!cmdq_free(wq))
|
||||
cmdq_continue(wq);
|
||||
}
|
||||
|
||||
if (!wc->locked) {
|
||||
RB_REMOVE(wait_channels, &wait_channels, wc);
|
||||
free((void*) wc->name);
|
||||
free(wc);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_wait(struct cmd_q *cmdq, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
if (cmdq->client == NULL || cmdq->client->session != NULL) {
|
||||
cmdq_error(cmdq, "not able to wait");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (wc == NULL) {
|
||||
wc = xmalloc(sizeof *wc);
|
||||
wc->name = xstrdup(name);
|
||||
wc->locked = 0;
|
||||
TAILQ_INIT(&wc->waiters);
|
||||
TAILQ_INIT(&wc->lockers);
|
||||
RB_INSERT(wait_channels, &wait_channels, wc);
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&wc->waiters, cmdq, waitentry);
|
||||
cmdq->references++;
|
||||
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_lock(struct cmd_q *cmdq, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
if (cmdq->client == NULL || cmdq->client->session != NULL) {
|
||||
cmdq_error(cmdq, "not able to lock");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (wc == NULL) {
|
||||
wc = xmalloc(sizeof *wc);
|
||||
wc->name = xstrdup(name);
|
||||
wc->locked = 0;
|
||||
TAILQ_INIT(&wc->waiters);
|
||||
TAILQ_INIT(&wc->lockers);
|
||||
RB_INSERT(wait_channels, &wait_channels, wc);
|
||||
}
|
||||
|
||||
if (wc->locked) {
|
||||
TAILQ_INSERT_TAIL(&wc->lockers, cmdq, waitentry);
|
||||
cmdq->references++;
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
wc->locked = 1;
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
struct cmd_q *wq;
|
||||
|
||||
if (wc == NULL || !wc->locked) {
|
||||
cmdq_error(cmdq, "channel %s not locked", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((wq = TAILQ_FIRST(&wc->lockers)) != NULL) {
|
||||
TAILQ_REMOVE(&wc->lockers, wq, waitentry);
|
||||
if (!cmdq_free(wq))
|
||||
cmdq_continue(wq);
|
||||
} else {
|
||||
wc->locked = 0;
|
||||
if (TAILQ_EMPTY(&wc->waiters)) {
|
||||
RB_REMOVE(wait_channels, &wait_channels, wc);
|
||||
free((void*) wc->name);
|
||||
free(wc);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
306
cmd.c
306
cmd.c
@@ -112,21 +112,22 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_switch_client_entry,
|
||||
&cmd_unbind_key_entry,
|
||||
&cmd_unlink_window_entry,
|
||||
&cmd_wait_for_entry,
|
||||
NULL
|
||||
};
|
||||
|
||||
int cmd_session_better(struct session *, struct session *, int);
|
||||
struct session *cmd_choose_session_list(struct sessionslist *);
|
||||
struct session *cmd_choose_session(int);
|
||||
struct client *cmd_choose_client(struct clients *);
|
||||
struct client *cmd_lookup_client(const char *);
|
||||
struct session *cmd_lookup_session(const char *, int *);
|
||||
struct session *cmd_lookup_session_id(const char *);
|
||||
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
|
||||
int cmd_lookup_index(struct session *, const char *, int *);
|
||||
struct window_pane *cmd_lookup_paneid(const char *);
|
||||
struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *);
|
||||
struct window *cmd_lookup_windowid(const char *);
|
||||
struct session *cmd_window_session(struct cmd_ctx *,
|
||||
struct window *, struct winlink **);
|
||||
struct session *cmd_window_session(struct cmd_q *, struct window *,
|
||||
struct winlink **);
|
||||
struct winlink *cmd_find_window_offset(const char *, struct session *, int *);
|
||||
int cmd_find_index_offset(const char *, struct session *, int *);
|
||||
struct window_pane *cmd_find_pane_offset(const char *, struct winlink *);
|
||||
@@ -204,7 +205,7 @@ cmd_free_argv(int argc, char **argv)
|
||||
}
|
||||
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, char **cause)
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
{
|
||||
const struct cmd_entry **entryp, *entry;
|
||||
struct cmd *cmd;
|
||||
@@ -251,12 +252,15 @@ cmd_parse(int argc, char **argv, char **cause)
|
||||
goto usage;
|
||||
if (entry->args_upper != -1 && args->argc > entry->args_upper)
|
||||
goto usage;
|
||||
if (entry->check != NULL && entry->check(args) != 0)
|
||||
goto usage;
|
||||
|
||||
cmd = xmalloc(sizeof *cmd);
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->entry = entry;
|
||||
cmd->args = args;
|
||||
|
||||
if (file != NULL)
|
||||
cmd->file = xstrdup(file);
|
||||
cmd->line = line;
|
||||
|
||||
return (cmd);
|
||||
|
||||
ambiguous:
|
||||
@@ -280,27 +284,14 @@ usage:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
|
||||
{
|
||||
return (cmd->entry->exec(cmd, ctx));
|
||||
}
|
||||
|
||||
void
|
||||
cmd_free(struct cmd *cmd)
|
||||
{
|
||||
args_free(cmd->args);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
size_t
|
||||
cmd_print(struct cmd *cmd, char *buf, size_t len)
|
||||
{
|
||||
size_t off, used;
|
||||
|
||||
off = xsnprintf(buf, len, "%s ", cmd->entry->name);
|
||||
if (off < len) {
|
||||
used = args_print(cmd->args, buf + off, len - off);
|
||||
if (off + 1 < len) {
|
||||
used = args_print(cmd->args, buf + off, len - off - 1);
|
||||
if (used == 0)
|
||||
off--;
|
||||
else
|
||||
@@ -318,31 +309,32 @@ cmd_print(struct cmd *cmd, char *buf, size_t len)
|
||||
* session from all sessions.
|
||||
*/
|
||||
struct session *
|
||||
cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
|
||||
cmd_current_session(struct cmd_q *cmdq, int prefer_unattached)
|
||||
{
|
||||
struct msg_command_data *data = ctx->msgdata;
|
||||
struct client *c = ctx->cmdclient;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s;
|
||||
struct sessionslist ss;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
const char *path;
|
||||
int found;
|
||||
|
||||
if (ctx->curclient != NULL && ctx->curclient->session != NULL)
|
||||
return (ctx->curclient->session);
|
||||
if (c != NULL && c->session != NULL)
|
||||
return (c->session);
|
||||
|
||||
/*
|
||||
* If the name of the calling client's pty is know, build a list of the
|
||||
* sessions that contain it and if any choose either the first or the
|
||||
* newest.
|
||||
* If the name of the calling client's pty is known, build a list of
|
||||
* the sessions that contain it and if any choose either the first or
|
||||
* the newest.
|
||||
*/
|
||||
if (c != NULL && c->tty.path != NULL) {
|
||||
path = c == NULL ? NULL : c->tty.path;
|
||||
if (path != NULL) {
|
||||
ARRAY_INIT(&ss);
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
found = 0;
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
if (strcmp(wp->tty, c->tty.path) == 0) {
|
||||
if (strcmp(wp->tty, path) == 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
@@ -360,16 +352,27 @@ cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* Use the session from the TMUX environment variable. */
|
||||
if (data != NULL && data->pid == getpid() && data->idx != -1) {
|
||||
s = session_find_by_index(data->idx);
|
||||
if (s != NULL)
|
||||
return (s);
|
||||
}
|
||||
|
||||
return (cmd_choose_session(prefer_unattached));
|
||||
}
|
||||
|
||||
/* Is this session better? */
|
||||
int
|
||||
cmd_session_better(struct session *s, struct session *best,
|
||||
int prefer_unattached)
|
||||
{
|
||||
if (best == NULL)
|
||||
return (1);
|
||||
if (prefer_unattached) {
|
||||
if (!(best->flags & SESSION_UNATTACHED) &&
|
||||
(s->flags & SESSION_UNATTACHED))
|
||||
return (1);
|
||||
else if ((best->flags & SESSION_UNATTACHED) &&
|
||||
!(s->flags & SESSION_UNATTACHED))
|
||||
return (0);
|
||||
}
|
||||
return (timercmp(&s->activity_time, &best->activity_time, >));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the most recently used session, preferring unattached if the flag is
|
||||
* set.
|
||||
@@ -377,21 +380,14 @@ cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
|
||||
struct session *
|
||||
cmd_choose_session(int prefer_unattached)
|
||||
{
|
||||
struct session *s, *sbest;
|
||||
struct timeval *tv = NULL;
|
||||
struct session *s, *best;
|
||||
|
||||
sbest = NULL;
|
||||
best = NULL;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
if (tv == NULL || timercmp(&s->activity_time, tv, >) ||
|
||||
(prefer_unattached &&
|
||||
!(sbest->flags & SESSION_UNATTACHED) &&
|
||||
(s->flags & SESSION_UNATTACHED))) {
|
||||
sbest = s;
|
||||
tv = &s->activity_time;
|
||||
}
|
||||
if (cmd_session_better(s, best, prefer_unattached))
|
||||
best = s;
|
||||
}
|
||||
|
||||
return (sbest);
|
||||
return (best);
|
||||
}
|
||||
|
||||
/* Find the most recently used session from a list. */
|
||||
@@ -422,21 +418,21 @@ cmd_choose_session_list(struct sessionslist *ss)
|
||||
* then of all clients.
|
||||
*/
|
||||
struct client *
|
||||
cmd_current_client(struct cmd_ctx *ctx)
|
||||
cmd_current_client(struct cmd_q *cmdq)
|
||||
{
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
struct clients cc;
|
||||
u_int i;
|
||||
|
||||
if (ctx->curclient != NULL)
|
||||
return (ctx->curclient);
|
||||
if (cmdq->client != NULL && cmdq->client->session != NULL)
|
||||
return (cmdq->client);
|
||||
|
||||
/*
|
||||
* No current client set. Find the current session and return the
|
||||
* newest of its clients.
|
||||
*/
|
||||
s = cmd_current_session(ctx, 0);
|
||||
s = cmd_current_session(cmdq, 0);
|
||||
if (s != NULL && !(s->flags & SESSION_UNATTACHED)) {
|
||||
ARRAY_INIT(&cc);
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
@@ -481,15 +477,19 @@ cmd_choose_client(struct clients *cc)
|
||||
|
||||
/* Find the target client or report an error and return NULL. */
|
||||
struct client *
|
||||
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
|
||||
cmd_find_client(struct cmd_q *cmdq, const char *arg, int quiet)
|
||||
{
|
||||
struct client *c;
|
||||
char *tmparg;
|
||||
size_t arglen;
|
||||
|
||||
/* A NULL argument means the current client. */
|
||||
if (arg == NULL)
|
||||
return (cmd_current_client(ctx));
|
||||
if (arg == NULL) {
|
||||
c = cmd_current_client(cmdq);
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(cmdq, "no clients");
|
||||
return (c);
|
||||
}
|
||||
tmparg = xstrdup(arg);
|
||||
|
||||
/* Trim a single trailing colon if any. */
|
||||
@@ -501,8 +501,8 @@ cmd_find_client(struct cmd_ctx *ctx, const char *arg)
|
||||
c = cmd_lookup_client(tmparg);
|
||||
|
||||
/* If no client found, report an error. */
|
||||
if (c == NULL)
|
||||
ctx->error(ctx, "client not found: %s", tmparg);
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(cmdq, "client not found: %s", tmparg);
|
||||
|
||||
free(tmparg);
|
||||
return (c);
|
||||
@@ -521,7 +521,7 @@ cmd_lookup_client(const char *name)
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c == NULL || c->session == NULL)
|
||||
if (c == NULL || c->session == NULL || c->tty.path == NULL)
|
||||
continue;
|
||||
path = c->tty.path;
|
||||
|
||||
@@ -539,6 +539,21 @@ cmd_lookup_client(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Find the target session or report an error and return NULL. */
|
||||
struct session *
|
||||
cmd_lookup_session_id(const char *arg)
|
||||
{
|
||||
char *endptr;
|
||||
long id;
|
||||
|
||||
if (arg[0] != '$')
|
||||
return (NULL);
|
||||
id = strtol(arg + 1, &endptr, 10);
|
||||
if (arg[1] != '\0' && *endptr == '\0')
|
||||
return (session_find_by_id(id));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Lookup a session by name. If no session is found, NULL is returned. */
|
||||
struct session *
|
||||
cmd_lookup_session(const char *name, int *ambiguous)
|
||||
@@ -547,6 +562,10 @@ cmd_lookup_session(const char *name, int *ambiguous)
|
||||
|
||||
*ambiguous = 0;
|
||||
|
||||
/* Look for $id first. */
|
||||
if ((s = cmd_lookup_session_id(name)) != NULL)
|
||||
return (s);
|
||||
|
||||
/*
|
||||
* Look for matches. First look for exact matches - session names must
|
||||
* be unique so an exact match can't be ambigious and can just be
|
||||
@@ -704,14 +723,14 @@ cmd_lookup_windowid(const char *arg)
|
||||
|
||||
/* Find session and winlink for window. */
|
||||
struct session *
|
||||
cmd_window_session(struct cmd_ctx *ctx, struct window *w, struct winlink **wlp)
|
||||
cmd_window_session(struct cmd_q *cmdq, struct window *w, struct winlink **wlp)
|
||||
{
|
||||
struct session *s;
|
||||
struct sessionslist ss;
|
||||
struct winlink *wl;
|
||||
|
||||
/* If this window is in the current session, return that winlink. */
|
||||
s = cmd_current_session(ctx, 0);
|
||||
s = cmd_current_session(cmdq, 0);
|
||||
if (s != NULL) {
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
if (wl != NULL) {
|
||||
@@ -736,7 +755,7 @@ cmd_window_session(struct cmd_ctx *ctx, struct window *w, struct winlink **wlp)
|
||||
|
||||
/* Find the target session or report an error and return NULL. */
|
||||
struct session *
|
||||
cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
||||
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
|
||||
{
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
@@ -748,13 +767,13 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
||||
|
||||
/* A NULL argument means the current session. */
|
||||
if (arg == NULL)
|
||||
return (cmd_current_session(ctx, prefer_unattached));
|
||||
return (cmd_current_session(cmdq, prefer_unattached));
|
||||
|
||||
/* Lookup as pane id or window id. */
|
||||
if ((wp = cmd_lookup_paneid(arg)) != NULL)
|
||||
return (cmd_window_session(ctx, wp->window, NULL));
|
||||
return (cmd_window_session(cmdq, wp->window, NULL));
|
||||
if ((w = cmd_lookup_windowid(arg)) != NULL)
|
||||
return (cmd_window_session(ctx, w, NULL));
|
||||
return (cmd_window_session(cmdq, w, NULL));
|
||||
|
||||
/* Trim a single trailing colon if any. */
|
||||
tmparg = xstrdup(arg);
|
||||
@@ -765,7 +784,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
||||
/* An empty session name is the current session. */
|
||||
if (*tmparg == '\0') {
|
||||
free(tmparg);
|
||||
return (cmd_current_session(ctx, prefer_unattached));
|
||||
return (cmd_current_session(cmdq, prefer_unattached));
|
||||
}
|
||||
|
||||
/* Find the session, if any. */
|
||||
@@ -778,9 +797,9 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
||||
/* If no session found, report an error. */
|
||||
if (s == NULL) {
|
||||
if (ambiguous)
|
||||
ctx->error(ctx, "more than one session: %s", tmparg);
|
||||
cmdq_error(cmdq, "more than one session: %s", tmparg);
|
||||
else
|
||||
ctx->error(ctx, "session not found: %s", tmparg);
|
||||
cmdq_error(cmdq, "session not found: %s", tmparg);
|
||||
}
|
||||
|
||||
free(tmparg);
|
||||
@@ -789,7 +808,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
|
||||
|
||||
/* Find the target session and window or report an error and return NULL. */
|
||||
struct winlink *
|
||||
cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
|
||||
{
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
@@ -802,8 +821,8 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
* Find the current session. There must always be a current session, if
|
||||
* it can't be found, report an error.
|
||||
*/
|
||||
if ((s = cmd_current_session(ctx, 0)) == NULL) {
|
||||
ctx->error(ctx, "can't establish current session");
|
||||
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
|
||||
cmdq_error(cmdq, "can't establish current session");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -816,7 +835,7 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
|
||||
/* Lookup as pane id. */
|
||||
if ((wp = cmd_lookup_paneid(arg)) != NULL) {
|
||||
s = cmd_window_session(ctx, wp->window, &wl);
|
||||
s = cmd_window_session(cmdq, wp->window, &wl);
|
||||
if (sp != NULL)
|
||||
*sp = s;
|
||||
return (wl);
|
||||
@@ -850,6 +869,10 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
wl = s->curw;
|
||||
else if (winptr[0] == '!' && winptr[1] == '\0')
|
||||
wl = TAILQ_FIRST(&s->lastw);
|
||||
else if (winptr[0] == '^' && winptr[1] == '\0')
|
||||
wl = RB_MIN(winlinks, &s->windows);
|
||||
else if (winptr[0] == '$' && winptr[1] == '\0')
|
||||
wl = RB_MAX(winlinks, &s->windows);
|
||||
else if (winptr[0] == '+' || winptr[0] == '-')
|
||||
wl = cmd_find_window_offset(winptr, s, &ambiguous);
|
||||
else
|
||||
@@ -893,17 +916,17 @@ lookup_session:
|
||||
|
||||
no_session:
|
||||
if (ambiguous)
|
||||
ctx->error(ctx, "multiple sessions: %s", arg);
|
||||
cmdq_error(cmdq, "multiple sessions: %s", arg);
|
||||
else
|
||||
ctx->error(ctx, "session not found: %s", arg);
|
||||
cmdq_error(cmdq, "session not found: %s", arg);
|
||||
free(sessptr);
|
||||
return (NULL);
|
||||
|
||||
not_found:
|
||||
if (ambiguous)
|
||||
ctx->error(ctx, "multiple windows: %s", arg);
|
||||
cmdq_error(cmdq, "multiple windows: %s", arg);
|
||||
else
|
||||
ctx->error(ctx, "window not found: %s", arg);
|
||||
cmdq_error(cmdq, "window not found: %s", arg);
|
||||
free(sessptr);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -935,7 +958,7 @@ cmd_find_window_offset(const char *winptr, struct session *s, int *ambiguous)
|
||||
* example if it is going to be created).
|
||||
*/
|
||||
int
|
||||
cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
cmd_find_index(struct cmd_q *cmdq, const char *arg, struct session **sp)
|
||||
{
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
@@ -947,8 +970,8 @@ cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp)
|
||||
* Find the current session. There must always be a current session, if
|
||||
* it can't be found, report an error.
|
||||
*/
|
||||
if ((s = cmd_current_session(ctx, 0)) == NULL) {
|
||||
ctx->error(ctx, "can't establish current session");
|
||||
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
|
||||
cmdq_error(cmdq, "can't establish current session");
|
||||
return (-2);
|
||||
}
|
||||
|
||||
@@ -1031,25 +1054,25 @@ lookup_session:
|
||||
|
||||
no_session:
|
||||
if (ambiguous)
|
||||
ctx->error(ctx, "multiple sessions: %s", arg);
|
||||
cmdq_error(cmdq, "multiple sessions: %s", arg);
|
||||
else
|
||||
ctx->error(ctx, "session not found: %s", arg);
|
||||
cmdq_error(cmdq, "session not found: %s", arg);
|
||||
free(sessptr);
|
||||
return (-2);
|
||||
|
||||
invalid_index:
|
||||
if (ambiguous)
|
||||
goto not_found;
|
||||
ctx->error(ctx, "invalid index: %s", arg);
|
||||
cmdq_error(cmdq, "invalid index: %s", arg);
|
||||
|
||||
free(sessptr);
|
||||
return (-2);
|
||||
|
||||
not_found:
|
||||
if (ambiguous)
|
||||
ctx->error(ctx, "multiple windows: %s", arg);
|
||||
cmdq_error(cmdq, "multiple windows: %s", arg);
|
||||
else
|
||||
ctx->error(ctx, "window not found: %s", arg);
|
||||
cmdq_error(cmdq, "window not found: %s", arg);
|
||||
free(sessptr);
|
||||
return (-2);
|
||||
}
|
||||
@@ -1086,7 +1109,7 @@ cmd_find_index_offset(const char *winptr, struct session *s, int *ambiguous)
|
||||
* such as mysession:mywindow.0.
|
||||
*/
|
||||
struct winlink *
|
||||
cmd_find_pane(struct cmd_ctx *ctx,
|
||||
cmd_find_pane(struct cmd_q *cmdq,
|
||||
const char *arg, struct session **sp, struct window_pane **wpp)
|
||||
{
|
||||
struct session *s;
|
||||
@@ -1096,8 +1119,8 @@ cmd_find_pane(struct cmd_ctx *ctx,
|
||||
u_int idx;
|
||||
|
||||
/* Get the current session. */
|
||||
if ((s = cmd_current_session(ctx, 0)) == NULL) {
|
||||
ctx->error(ctx, "can't establish current session");
|
||||
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
|
||||
cmdq_error(cmdq, "can't establish current session");
|
||||
return (NULL);
|
||||
}
|
||||
if (sp != NULL)
|
||||
@@ -1111,7 +1134,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
|
||||
|
||||
/* Lookup as pane id. */
|
||||
if ((*wpp = cmd_lookup_paneid(arg)) != NULL) {
|
||||
s = cmd_window_session(ctx, (*wpp)->window, &wl);
|
||||
s = cmd_window_session(cmdq, (*wpp)->window, &wl);
|
||||
if (sp != NULL)
|
||||
*sp = s;
|
||||
return (wl);
|
||||
@@ -1126,7 +1149,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
|
||||
winptr[period - arg] = '\0';
|
||||
if (*winptr == '\0')
|
||||
wl = s->curw;
|
||||
else if ((wl = cmd_find_window(ctx, winptr, sp)) == NULL)
|
||||
else if ((wl = cmd_find_window(cmdq, winptr, sp)) == NULL)
|
||||
goto error;
|
||||
|
||||
/* Find the pane section and look it up. */
|
||||
@@ -1150,7 +1173,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
|
||||
lookup_string:
|
||||
/* Try pane string description. */
|
||||
if ((*wpp = window_find_string(wl->window, paneptr)) == NULL) {
|
||||
ctx->error(ctx, "can't find pane: %s", paneptr);
|
||||
cmdq_error(cmdq, "can't find pane: %s", paneptr);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -1175,7 +1198,7 @@ lookup_window:
|
||||
return (s->curw);
|
||||
|
||||
/* Try as a window and use the active pane. */
|
||||
if ((wl = cmd_find_window(ctx, arg, sp)) != NULL)
|
||||
if ((wl = cmd_find_window(cmdq, arg, sp)) != NULL)
|
||||
*wpp = wl->window->active;
|
||||
return (wl);
|
||||
|
||||
@@ -1205,14 +1228,14 @@ cmd_find_pane_offset(const char *paneptr, struct winlink *wl)
|
||||
|
||||
/* Replace the first %% or %idx in template by s. */
|
||||
char *
|
||||
cmd_template_replace(char *template, const char *s, int idx)
|
||||
cmd_template_replace(const char *template, const char *s, int idx)
|
||||
{
|
||||
char ch;
|
||||
char *buf, *ptr;
|
||||
int replaced;
|
||||
size_t len;
|
||||
char ch, *buf;
|
||||
const char *ptr;
|
||||
int replaced;
|
||||
size_t len;
|
||||
|
||||
if (strstr(template, "%") == NULL)
|
||||
if (strchr(template, '%') == NULL)
|
||||
return (xstrdup(template));
|
||||
|
||||
buf = xmalloc(1);
|
||||
@@ -1243,86 +1266,3 @@ cmd_template_replace(char *template, const char *s, int idx)
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the default path for a new pane, using the given path or the
|
||||
* default-path option if it is NULL. Several special values are accepted: the
|
||||
* empty string or relative path for the current pane's working directory, ~
|
||||
* for the user's home, - for the session working directory, . for the tmux
|
||||
* server's working directory. The default on failure is the session's working
|
||||
* directory.
|
||||
*/
|
||||
const char *
|
||||
cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd)
|
||||
{
|
||||
struct session *s;
|
||||
struct environ_entry *envent;
|
||||
const char *root;
|
||||
char tmp[MAXPATHLEN];
|
||||
struct passwd *pw;
|
||||
int n;
|
||||
size_t skip;
|
||||
static char path[MAXPATHLEN];
|
||||
|
||||
if ((s = cmd_current_session(ctx, 0)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (cwd == NULL)
|
||||
cwd = options_get_string(&s->options, "default-path");
|
||||
|
||||
skip = 1;
|
||||
if (strcmp(cwd, "$HOME") == 0 || strncmp(cwd, "$HOME/", 6) == 0) {
|
||||
/* User's home directory - $HOME. */
|
||||
skip = 5;
|
||||
goto find_home;
|
||||
} else if (cwd[0] == '~' && (cwd[1] == '\0' || cwd[1] == '/')) {
|
||||
/* User's home directory - ~. */
|
||||
goto find_home;
|
||||
} else if (cwd[0] == '-' && (cwd[1] == '\0' || cwd[1] == '/')) {
|
||||
/* Session working directory. */
|
||||
root = s->cwd;
|
||||
goto complete_path;
|
||||
} else if (cwd[0] == '.' && (cwd[1] == '\0' || cwd[1] == '/')) {
|
||||
/* Server working directory. */
|
||||
if (getcwd(tmp, sizeof tmp) != NULL) {
|
||||
root = tmp;
|
||||
goto complete_path;
|
||||
}
|
||||
return (s->cwd);
|
||||
} else if (*cwd == '/') {
|
||||
/* Absolute path. */
|
||||
return (cwd);
|
||||
} else {
|
||||
/* Empty or relative path. */
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
|
||||
root = ctx->cmdclient->cwd;
|
||||
else if (ctx->curclient != NULL && s->curw != NULL)
|
||||
root = osdep_get_cwd(s->curw->window->active->fd);
|
||||
else
|
||||
return (s->cwd);
|
||||
skip = 0;
|
||||
if (root != NULL)
|
||||
goto complete_path;
|
||||
}
|
||||
|
||||
return (s->cwd);
|
||||
|
||||
find_home:
|
||||
envent = environ_find(&global_environ, "HOME");
|
||||
if (envent != NULL && *envent->value != '\0')
|
||||
root = envent->value;
|
||||
else if ((pw = getpwuid(getuid())) != NULL)
|
||||
root = pw->pw_dir;
|
||||
else
|
||||
return (s->cwd);
|
||||
|
||||
complete_path:
|
||||
if (root[skip] == '\0') {
|
||||
strlcpy(path, root, sizeof path);
|
||||
return (path);
|
||||
}
|
||||
n = snprintf(path, sizeof path, "%s/%s", root, cwd + skip);
|
||||
if (n > 0 && (size_t)n < sizeof path)
|
||||
return (path);
|
||||
return (s->cwd);
|
||||
}
|
||||
|
||||
26
colour.c
26
colour.c
@@ -287,29 +287,3 @@ colour_256to16(u_char c)
|
||||
|
||||
return (table[c]);
|
||||
}
|
||||
|
||||
/* Convert 256 colour palette to 88. */
|
||||
u_char
|
||||
colour_256to88(u_char c)
|
||||
{
|
||||
static const u_char table[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 17, 18, 18, 19, 20, 21, 21, 22, 22, 23, 20, 21, 21, 22,
|
||||
22, 23, 24, 25, 25, 26, 26, 27, 24, 25, 25, 26, 26, 27, 28, 29,
|
||||
29, 30, 30, 31, 32, 33, 33, 34, 34, 35, 36, 37, 37, 38, 38, 39,
|
||||
36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43, 40, 41, 41, 42,
|
||||
42, 43, 44, 45, 45, 46, 46, 47, 32, 33, 33, 34, 34, 35, 36, 37,
|
||||
37, 38, 38, 39, 36, 37, 37, 38, 38, 39, 40, 41, 41, 42, 42, 43,
|
||||
40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 46, 47, 48, 49, 49, 50,
|
||||
50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54, 54, 55, 56, 57,
|
||||
57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61, 61, 62, 62, 63,
|
||||
48, 49, 49, 50, 50, 51, 52, 53, 53, 54, 54, 55, 52, 53, 53, 54,
|
||||
54, 55, 56, 57, 57, 58, 58, 59, 56, 57, 57, 58, 58, 59, 60, 61,
|
||||
61, 62, 62, 63, 64, 65, 65, 66, 66, 67, 68, 69, 69, 70, 70, 71,
|
||||
68, 69, 69, 70, 70, 71, 72, 73, 73, 74, 74, 75, 72, 73, 73, 74,
|
||||
74, 75, 76, 77, 77, 78, 78, 79, 0, 0, 80, 80, 80, 81, 81, 81,
|
||||
82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87
|
||||
};
|
||||
|
||||
return (table[c]);
|
||||
}
|
||||
|
||||
32
compat.h
32
compat.h
@@ -30,6 +30,10 @@
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#endif
|
||||
|
||||
#ifndef ECHOPRT
|
||||
#define ECHOPRT 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BSD_TYPES
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
@@ -121,6 +125,10 @@ typedef uint64_t u_int64_t;
|
||||
#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
|
||||
#endif
|
||||
|
||||
#ifndef O_DIRECTORY
|
||||
#define O_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
#ifndef INFTIM
|
||||
#define INFTIM -1
|
||||
#endif
|
||||
@@ -152,6 +160,18 @@ typedef uint64_t u_int64_t;
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef timersub
|
||||
#define timersub(tvp, uvp, vvp) \
|
||||
do { \
|
||||
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
|
||||
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
|
||||
if ((vvp)->tv_usec < 0) { \
|
||||
(vvp)->tv_sec--; \
|
||||
(vvp)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef TTY_NAME_MAX
|
||||
#define TTY_NAME_MAX 32
|
||||
#endif
|
||||
@@ -198,6 +218,7 @@ int daemon(int, int);
|
||||
|
||||
#ifndef HAVE_B64_NTOP
|
||||
/* b64_ntop.c */
|
||||
#undef b64_ntop /* for Cygwin */
|
||||
int b64_ntop(const char *, size_t, char *, size_t);
|
||||
#endif
|
||||
|
||||
@@ -224,6 +245,17 @@ int setenv(const char *, const char *, int);
|
||||
int unsetenv(const char *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
/* cfmakeraw.c */
|
||||
void cfmakeraw(struct termios *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_OPENAT
|
||||
/* openat.c */
|
||||
#define AT_FDCWD -100
|
||||
int openat(int, const char *, int, ...);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETOPT
|
||||
#include <getopt.h>
|
||||
#else
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
* Copyright (c) 2013 Dagobert Michelsen
|
||||
* Copyright (c) 2013 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
|
||||
@@ -16,29 +17,16 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Start the server and do nothing else.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_start_server_entry = {
|
||||
"start-server", "start",
|
||||
"", 0, 0,
|
||||
"",
|
||||
CMD_STARTSERVER,
|
||||
NULL,
|
||||
NULL,
|
||||
cmd_start_server_exec
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
enum cmd_retval
|
||||
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
|
||||
void
|
||||
cfmakeraw(struct termios *tio)
|
||||
{
|
||||
return (CMD_RETURN_NORMAL);
|
||||
tio->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
||||
tio->c_oflag &= ~OPOST;
|
||||
tio->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||
tio->c_cflag &= ~(CSIZE|PARENB);
|
||||
tio->c_cflag |= CS8;
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <stropts.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ BSDgetopt(int nargc, char *const *nargv, const char *ostr)
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
if (place[1])
|
||||
return (BADCH);
|
||||
++BSDoptind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
63
compat/openat.c
Normal file
63
compat/openat.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 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 <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
int
|
||||
openat(int fd, const char *path, int flags, ...)
|
||||
{
|
||||
mode_t mode;
|
||||
va_list ap;
|
||||
int dotfd, retval, saved_errno;
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
} else
|
||||
mode = 0;
|
||||
|
||||
dotfd = -1;
|
||||
if (fd != AT_FDCWD) {
|
||||
dotfd = open(".", O_RDONLY);
|
||||
if (dotfd == -1)
|
||||
return (-1);
|
||||
if (fchdir(fd) != 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
retval = open(path, flags, mode);
|
||||
|
||||
if (dotfd != -1) {
|
||||
if (fchdir(dotfd) != 0) {
|
||||
saved_errno = errno;
|
||||
close(retval);
|
||||
close(dotfd);
|
||||
errno = saved_errno;
|
||||
return (-1);
|
||||
}
|
||||
close(dotfd);
|
||||
}
|
||||
|
||||
return (retval);
|
||||
}
|
||||
45
configure.ac
45
configure.ac
@@ -1,10 +1,10 @@
|
||||
# $Id$
|
||||
|
||||
# Miscellaneous autofoo bullshit.
|
||||
AC_INIT(tmux, 1.7)
|
||||
AC_INIT(tmux, 1.9)
|
||||
|
||||
AC_CONFIG_AUX_DIR(etc)
|
||||
AM_INIT_AUTOMAKE([foreign])
|
||||
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
@@ -16,8 +16,12 @@ AC_CANONICAL_HOST
|
||||
# Set up the compiler in two different ways and say yes we may want to install.
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_MKDIR_P
|
||||
AC_PROG_INSTALL
|
||||
|
||||
# Default tmux.conf goes in /etc not ${prefix}/etc.
|
||||
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
||||
|
||||
# Check for various headers. Alternatives included from compat.h.
|
||||
AC_CHECK_HEADERS(
|
||||
[ \
|
||||
@@ -53,8 +57,11 @@ AM_CONDITIONAL(IS_DEBUG, test "x$found_debug" = xyes)
|
||||
AC_ARG_ENABLE(
|
||||
static,
|
||||
AC_HELP_STRING(--enable-static, create a static build),
|
||||
[LDFLAGS="$LDFLAGS -static"]
|
||||
found_static=$enable_static
|
||||
)
|
||||
if test "x$found_static" = xyes; then
|
||||
LDFLAGS="$LDFLAGS -static"
|
||||
fi
|
||||
|
||||
# Is this gcc?
|
||||
AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes)
|
||||
@@ -129,7 +136,7 @@ fi
|
||||
# Look for curses.
|
||||
AC_SEARCH_LIBS(
|
||||
setupterm,
|
||||
[terminfo curses ncurses],
|
||||
[terminfo curses ncurses tinfo],
|
||||
found_curses=yes,
|
||||
found_curses=no
|
||||
)
|
||||
@@ -305,11 +312,35 @@ AM_CONDITIONAL(NO_STRTONUM, [test "x$found_strtonum" = xno])
|
||||
|
||||
# Look for strnvis, compat/{vis,unvis}.c used if missing.
|
||||
AC_CHECK_FUNC(strnvis, found_strnvis=yes, found_strnvis=no)
|
||||
if test "x$found_strnvis" = xyes; then
|
||||
AC_MSG_CHECKING(if strnvis is broken)
|
||||
AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)],
|
||||
vis.h,
|
||||
AC_MSG_RESULT(no),
|
||||
[found_strnvis=no])
|
||||
if test "x$found_strnvis" = xno; then
|
||||
AC_MSG_RESULT(yes)
|
||||
fi
|
||||
fi
|
||||
if test "x$found_strnvis" = xyes; then
|
||||
AC_DEFINE(HAVE_VIS)
|
||||
fi
|
||||
AM_CONDITIONAL(NO_VIS, [test "x$found_strnvis" = xno])
|
||||
|
||||
# Look for cfmakeraw, compat/cfmakeraw.c used if missing.
|
||||
AC_CHECK_FUNC(cfmakeraw, found_cfmakeraw=yes, found_cfmakeraw=no)
|
||||
if test "x$found_cfmakeraw" = xyes; then
|
||||
AC_DEFINE(HAVE_CFMAKERAW)
|
||||
fi
|
||||
AM_CONDITIONAL(NO_CFMAKERAW, [test "x$found_cfmakeraw" = xno])
|
||||
|
||||
# Look for openat, compat/openat.c used if missing.
|
||||
AC_CHECK_FUNC(openat, found_openat=yes, found_openat=no)
|
||||
if test "x$found_openat" = xyes; then
|
||||
AC_DEFINE(HAVE_OPENAT)
|
||||
fi
|
||||
AM_CONDITIONAL(NO_OPENAT, [test "x$found_openat" = xno])
|
||||
|
||||
# Look for getopt. glibc's getopt does not enforce argument order and the ways
|
||||
# of making it do so are stupid, so just use our own instead.
|
||||
AC_CHECK_FUNC(getopt, found_getopt=yes, found_getopt=no)
|
||||
@@ -342,6 +373,7 @@ AC_CHECK_FUNCS(
|
||||
dirfd \
|
||||
setproctitle \
|
||||
sysconf \
|
||||
cfmakeraw \
|
||||
]
|
||||
)
|
||||
|
||||
@@ -413,6 +445,10 @@ else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Man page defaults to mdoc.
|
||||
MANFORMAT=mdoc
|
||||
AC_SUBST(MANFORMAT)
|
||||
|
||||
# Figure out the platform for osdep-*.c and forkpty-*.c.
|
||||
AC_MSG_CHECKING(platform)
|
||||
case "$host_os" in
|
||||
@@ -452,6 +488,7 @@ case "$host_os" in
|
||||
*solaris*)
|
||||
AC_MSG_RESULT(sunos)
|
||||
PLATFORM=sunos
|
||||
MANFORMAT=man
|
||||
;;
|
||||
*hpux*)
|
||||
AC_MSG_RESULT(hpux)
|
||||
|
||||
@@ -46,8 +46,12 @@ control_notify_input(struct client *c, struct window_pane *wp,
|
||||
if (winlink_find_by_window(&c->session->windows, wp->window) != NULL) {
|
||||
message = evbuffer_new();
|
||||
evbuffer_add_printf(message, "%%output %%%u ", wp->id);
|
||||
for (i = 0; i < len; i++)
|
||||
evbuffer_add_printf(message, "%02hhx", buf[i]);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (buf[i] < ' ' || buf[i] == '\\')
|
||||
evbuffer_add_printf(message, "\\%03o", buf[i]);
|
||||
else
|
||||
evbuffer_add_printf(message, "%c", buf[i]);
|
||||
}
|
||||
control_write_buffer(c, message);
|
||||
evbuffer_free(message);
|
||||
}
|
||||
@@ -95,19 +99,14 @@ void
|
||||
control_notify_window_unlinked(unused struct session *s, struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *cs;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
continue;
|
||||
cs = c->session;
|
||||
|
||||
if (winlink_find_by_window_id(&cs->windows, w->id) != NULL)
|
||||
control_write(c, "%%window-close %u", w->id);
|
||||
else
|
||||
control_write(c, "%%unlinked-window-close %u", w->id);
|
||||
control_write(c, "%%window-close @%u", w->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +124,9 @@ control_notify_window_linked(unused struct session *s, struct window *w)
|
||||
cs = c->session;
|
||||
|
||||
if (winlink_find_by_window_id(&cs->windows, w->id) != NULL)
|
||||
control_write(c, "%%window-add %u", w->id);
|
||||
control_write(c, "%%window-add @%u", w->id);
|
||||
else
|
||||
control_write(c, "%%unlinked-window-add %u", w->id);
|
||||
control_write(c, "%%unlinked-window-add @%u", w->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,22 +134,14 @@ void
|
||||
control_notify_window_renamed(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
continue;
|
||||
s = c->session;
|
||||
|
||||
if (winlink_find_by_window_id(&s->windows, w->id) != NULL) {
|
||||
control_write(c, "%%window-renamed %u %s",
|
||||
w->id, w->name);
|
||||
} else {
|
||||
control_write(c, "%%unlinked-window-renamed %u %s",
|
||||
w->id, w->name);
|
||||
}
|
||||
control_write(c, "%%window-renamed @%u %s", w->id, w->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +154,7 @@ control_notify_attached_session_changed(struct client *c)
|
||||
return;
|
||||
s = c->session;
|
||||
|
||||
control_write(c, "%%session-changed %d %s", s->idx, s->name);
|
||||
control_write(c, "%%session-changed $%u %s", s->id, s->name);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -174,10 +165,10 @@ control_notify_session_renamed(struct session *s)
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session != s)
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%session-renamed %s", s->name);
|
||||
control_write(c, "%%session-renamed $%u %s", s->id, s->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +180,7 @@ control_notify_session_created(unused struct session *s)
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%sessions-changed");
|
||||
@@ -204,7 +195,7 @@ control_notify_session_close(unused struct session *s)
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%sessions-changed");
|
||||
|
||||
62
control.c
62
control.c
@@ -22,49 +22,10 @@
|
||||
#include <event.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void printflike2 control_msg_error(struct cmd_ctx *, const char *, ...);
|
||||
void printflike2 control_msg_print(struct cmd_ctx *, const char *, ...);
|
||||
void printflike2 control_msg_info(struct cmd_ctx *, const char *, ...);
|
||||
|
||||
/* Command error callback. */
|
||||
void printflike2
|
||||
control_msg_error(struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = ctx->curclient;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_push_stdout(c);
|
||||
}
|
||||
|
||||
/* Command print callback. */
|
||||
void printflike2
|
||||
control_msg_print(struct cmd_ctx *ctx, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = ctx->curclient;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_push_stdout(c);
|
||||
}
|
||||
|
||||
/* Command info callback. */
|
||||
void printflike2
|
||||
control_msg_info(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
|
||||
{
|
||||
}
|
||||
|
||||
/* Write a line. */
|
||||
void printflike2
|
||||
control_write(struct client *c, const char *fmt, ...)
|
||||
@@ -93,8 +54,8 @@ void
|
||||
control_callback(struct client *c, int closed, unused void *data)
|
||||
{
|
||||
char *line, *cause;
|
||||
struct cmd_ctx ctx;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
|
||||
if (closed)
|
||||
c->flags |= CLIENT_EXIT;
|
||||
@@ -108,20 +69,19 @@ control_callback(struct client *c, int closed, unused void *data)
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.msgdata = NULL;
|
||||
ctx.cmdclient = NULL;
|
||||
ctx.curclient = c;
|
||||
if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
c->cmdq->time = time(NULL);
|
||||
c->cmdq->number++;
|
||||
|
||||
ctx.error = control_msg_error;
|
||||
ctx.print = control_msg_print;
|
||||
ctx.info = control_msg_info;
|
||||
cmdq_guard(c->cmdq, "begin", 1);
|
||||
control_write(c, "parse error: %s", cause);
|
||||
cmdq_guard(c->cmdq, "error", 1);
|
||||
|
||||
if (cmd_string_parse(line, &cmdlist, &cause) != 0) {
|
||||
control_write(c, "%%error in line \"%s\": %s", line,
|
||||
cause);
|
||||
free(cause);
|
||||
} else {
|
||||
cmd_list_exec(cmdlist, &ctx);
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry)
|
||||
cmd->flags |= CMD_CONTROL;
|
||||
cmdq_run(c->cmdq, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2012 Juan Ignacio Pumarino, jipumarino@gmail.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# Instructions
|
||||
# ------------
|
||||
#
|
||||
# 1. Install this script and give it execute permission somewhere in your PATH.
|
||||
# For example:
|
||||
#
|
||||
# $ mkdir -p ~/bin
|
||||
# $ wget https://raw.github.com/jipumarino/tmux-zoom/master/tmux-zoom.sh -O ~/bin/tmux-zoom.sh
|
||||
# $ chmod +x ~/bin/tmux-zoom.sh
|
||||
#
|
||||
# 2. Add a shortcut in your ~/.tmux.conf file:
|
||||
#
|
||||
# bind C-k run "tmux-zoom.sh"
|
||||
#
|
||||
# 3. When using this shortcut, the current tmux pane will open in a new window by itself.
|
||||
# Running it again in the zoomed window will return it to its original pane. You can have
|
||||
# as many zoomed windows as you want.
|
||||
|
||||
current=$(tmux display-message -p '#W-#I-#P')
|
||||
list=$(tmux list-window)
|
||||
|
||||
[[ "$current" =~ ^(.*)-([0-9]+)-([0-9]+) ]]
|
||||
current_window=${BASH_REMATCH[1]}
|
||||
current_pane=${BASH_REMATCH[2]}-${BASH_REMATCH[3]}
|
||||
new_zoom_window=ZOOM-$current_pane
|
||||
|
||||
if [[ $current_window =~ ZOOM-([0-9]+)-([0-9+]) ]]; then
|
||||
old_zoom_window=ZOOM-${BASH_REMATCH[1]}-${BASH_REMATCH[2]}
|
||||
tmux select-window -t ${BASH_REMATCH[1]} \; select-pane -t ${BASH_REMATCH[2]} \; swap-pane -s $old_zoom_window.1 \; kill-window -t $old_zoom_window
|
||||
elif [[ $list =~ $new_zoom_window ]]; then
|
||||
tmux select-window -t $new_zoom_window
|
||||
else
|
||||
tmux new-window -d -n $new_zoom_window \; swap-pane -s $new_zoom_window.1 \; select-window -t $new_zoom_window
|
||||
fi
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user