mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
504 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f21cb71fbe | ||
|
|
990218739a | ||
|
|
e7c2f53f2a | ||
|
|
9b2f02efbd | ||
|
|
b087483538 | ||
|
|
b946bf43f5 | ||
|
|
d64a815e8d | ||
|
|
a54309147d | ||
|
|
fb3c5efa50 | ||
|
|
aace1ead1e | ||
|
|
0aa959d7a3 | ||
|
|
83ff1e9bd3 | ||
|
|
28833efb48 | ||
|
|
175d1854d4 | ||
|
|
7461c165b5 | ||
|
|
d912687be7 | ||
|
|
d566c780e5 | ||
|
|
54bcaab70e | ||
|
|
9583878a7b | ||
|
|
d720a1487b | ||
|
|
5f662d91db | ||
|
|
94b71bcb64 | ||
|
|
36882ec789 | ||
|
|
9b28200578 | ||
|
|
ab4a4b2ad0 | ||
|
|
05c97d7fe9 | ||
|
|
b9a4beb6e7 | ||
|
|
2d84ee9001 | ||
|
|
2e5664d2df | ||
|
|
1384525dc1 | ||
|
|
591b26e46f | ||
|
|
e87d808594 | ||
|
|
1cb8145dc5 | ||
|
|
c57039bc3d | ||
|
|
9c0520f2c5 | ||
|
|
c3dbbdaadf | ||
|
|
843e605b89 | ||
|
|
643813c6ed | ||
|
|
223ed4a989 | ||
|
|
080080fa23 | ||
|
|
df3ab87964 | ||
|
|
3cc2486106 | ||
|
|
57cb6ef3a2 | ||
|
|
02ddd4ce70 | ||
|
|
b008a07ebb | ||
|
|
04e17a7e11 | ||
|
|
cd7550cdf1 | ||
|
|
c2b53598ad | ||
|
|
57b4d3d593 | ||
|
|
cdaa758340 | ||
|
|
c916feaf29 | ||
|
|
31ae09efa0 | ||
|
|
066575fd5a | ||
|
|
792455ce87 | ||
|
|
4eec3270ec | ||
|
|
640666fb36 | ||
|
|
67d2335130 | ||
|
|
481e48d119 | ||
|
|
1ea19245b3 | ||
|
|
b69efbdd30 | ||
|
|
0dd694f5fd | ||
|
|
2a9d697771 | ||
|
|
4e809a3130 | ||
|
|
3c3c08b6d9 | ||
|
|
cc6c6edb6f | ||
|
|
8e9b10062b | ||
|
|
12c6c723a9 | ||
|
|
fd65210139 | ||
|
|
266e662fae | ||
|
|
d455da45eb | ||
|
|
0fe3b739a1 | ||
|
|
392253f032 | ||
|
|
385a361bf8 | ||
|
|
a24cf4a5e1 | ||
|
|
55e73e3612 | ||
|
|
c5bdae466e | ||
|
|
bce1dee034 | ||
|
|
dbfee6a468 | ||
|
|
fd96ccfd80 | ||
|
|
b79df1dc29 | ||
|
|
180ebf0208 | ||
|
|
514a723f74 | ||
|
|
92434b0afd | ||
|
|
e8f2609ca4 | ||
|
|
41a01fc629 | ||
|
|
41b31fe240 | ||
|
|
78ca1b0265 | ||
|
|
3ea36830f3 | ||
|
|
6b2009ad72 | ||
|
|
5d3296c53b | ||
|
|
1e6e606f54 | ||
|
|
daac28febb | ||
|
|
69257bc0aa | ||
|
|
8684e60f51 | ||
|
|
fa27cbd035 | ||
|
|
dc8fefe902 | ||
|
|
fba9ebcc0c | ||
|
|
48a3dba6b9 | ||
|
|
2fa16eee53 | ||
|
|
e741a0bcd7 | ||
|
|
14dc2acc25 | ||
|
|
0414b1fc78 | ||
|
|
4b112c19f1 | ||
|
|
8a0b279c31 | ||
|
|
6b45464120 | ||
|
|
27ee34e7fa | ||
|
|
e9819eef3c | ||
|
|
9e4c5133c8 | ||
|
|
11e7915195 | ||
|
|
0ad2beae7e | ||
|
|
55e76edd3c | ||
|
|
f27e1d07fc | ||
|
|
203d604bf7 | ||
|
|
ee7acde149 | ||
|
|
82db1fa9e5 | ||
|
|
c948c6b697 | ||
|
|
c889e11375 | ||
|
|
f734d81074 | ||
|
|
8b8d0963da | ||
|
|
c9f2dc5ee5 | ||
|
|
dd25a6cdc2 | ||
|
|
47bc867ab9 | ||
|
|
b9b7daf3b2 | ||
|
|
631a89954f | ||
|
|
36734afdd8 | ||
|
|
640d9e54b7 | ||
|
|
2b4c144f96 | ||
|
|
ba3c1534e0 | ||
|
|
e340df2034 | ||
|
|
02e04477de | ||
|
|
4c2a78029d | ||
|
|
921880e00b | ||
|
|
d22c15107b | ||
|
|
c6a3446398 | ||
|
|
8de4c15dfa | ||
|
|
c75cced07d | ||
|
|
96ad1d7779 | ||
|
|
b1fa3e25e4 | ||
|
|
cb50a51127 | ||
|
|
b7ddfb39f3 | ||
|
|
ddb3750c8b | ||
|
|
79409dc1cc | ||
|
|
fd6e46596d | ||
|
|
743f772bef | ||
|
|
be033b1ed0 | ||
|
|
1811dc5271 | ||
|
|
2f854969ff | ||
|
|
130b77edc7 | ||
|
|
05802a6fe3 | ||
|
|
e100d465da | ||
|
|
13a0b6bb3f | ||
|
|
d4b006b9fa | ||
|
|
e09625e38b | ||
|
|
7475165cd8 | ||
|
|
ac1f294bb9 | ||
|
|
96b66f8fc3 | ||
|
|
713f3b05f3 | ||
|
|
9af5f3ff81 | ||
|
|
a9a0039be4 | ||
|
|
cb80901d33 | ||
|
|
9cc02d1498 | ||
|
|
acb4bd9e56 | ||
|
|
35a0606de1 | ||
|
|
5aaf640629 | ||
|
|
c0a34821c1 | ||
|
|
20f5e377fb | ||
|
|
178289fb4c | ||
|
|
6ea36afc4b | ||
|
|
97fd291079 | ||
|
|
9491a5c1cf | ||
|
|
8872a0da8e | ||
|
|
0f5a2c86da | ||
|
|
9f66fb4fd7 | ||
|
|
d60e585d9e | ||
|
|
dfdc23d86c | ||
|
|
7417e391d5 | ||
|
|
68e04907de | ||
|
|
10e14ae504 | ||
|
|
1199f8fc59 | ||
|
|
e67548dc36 | ||
|
|
446177a832 | ||
|
|
4eabd7ec90 | ||
|
|
d150d9b384 | ||
|
|
3fd34e70e5 | ||
|
|
50f25a8f05 | ||
|
|
c7c1018e9b | ||
|
|
7bccc82284 | ||
|
|
d091253a5d | ||
|
|
e1c283325e | ||
|
|
5e6a8177e5 | ||
|
|
75adf8368a | ||
|
|
6c333cc486 | ||
|
|
7d23d019c0 | ||
|
|
9b1f620aa0 | ||
|
|
dd0c814779 | ||
|
|
9b9a5a292d | ||
|
|
c54a5d9fb3 | ||
|
|
d8da761d54 | ||
|
|
3408595f77 | ||
|
|
9094f01c6b | ||
|
|
b6099f31ea | ||
|
|
4b482c95c3 | ||
|
|
54309cc25d | ||
|
|
503af3df54 | ||
|
|
b2e909b252 | ||
|
|
a4367b44fb | ||
|
|
78c0b96004 | ||
|
|
776ce8a9d5 | ||
|
|
ea70e68a51 | ||
|
|
0f9354eec2 | ||
|
|
21d8f77a0d | ||
|
|
163732e89f | ||
|
|
0a63ab4f0f | ||
|
|
3e495b4001 | ||
|
|
418ab1a553 | ||
|
|
ffc28a7765 | ||
|
|
4b2821ff98 | ||
|
|
b77dd75b57 | ||
|
|
16e43d6a42 | ||
|
|
f38a6bbd81 | ||
|
|
126d364abe | ||
|
|
85338bb75f | ||
|
|
61fce272ea | ||
|
|
f1282a683d | ||
|
|
c68ea386d1 | ||
|
|
3d74e89a39 | ||
|
|
a3d5bfcece | ||
|
|
1ebe79dd62 | ||
|
|
b3a724f30c | ||
|
|
98e7fbb2ac | ||
|
|
d2eab39ffa | ||
|
|
aa70f28069 | ||
|
|
acf331f7f1 | ||
|
|
4ede35c48c | ||
|
|
c17b0a202a | ||
|
|
46572ba904 | ||
|
|
61af9d7cc2 | ||
|
|
b98b4e23a3 | ||
|
|
7e4908f751 | ||
|
|
787f9de5d8 | ||
|
|
044999ce6d | ||
|
|
faa0570309 | ||
|
|
6d37984f4f | ||
|
|
4bb5a1d6a7 | ||
|
|
649c0d8e91 | ||
|
|
373541104b | ||
|
|
64c486ae81 | ||
|
|
6b6b0e91d0 | ||
|
|
c0346701df | ||
|
|
7e110b9d99 | ||
|
|
f20e3ee62c | ||
|
|
ef15b4195f | ||
|
|
68db958477 | ||
|
|
997b11741c | ||
|
|
7b60645732 | ||
|
|
c9fcb76651 | ||
|
|
52847a9518 | ||
|
|
3054846143 | ||
|
|
2b0bc9f1c5 | ||
|
|
404214b0ac | ||
|
|
a3cf995017 | ||
|
|
4f077fe62c | ||
|
|
e06efab9da | ||
|
|
780dd7ac82 | ||
|
|
2311bbd28a | ||
|
|
08d21936e4 | ||
|
|
22a528905d | ||
|
|
95950bf668 | ||
|
|
d4cb178249 | ||
|
|
24cba5907b | ||
|
|
1eb9500644 | ||
|
|
dad3090d32 | ||
|
|
4a76861925 | ||
|
|
9b6aeacdc0 | ||
|
|
0752fdaf6a | ||
|
|
9e786030df | ||
|
|
33ebb9ec39 | ||
|
|
74c40d04ea | ||
|
|
3bb14001b9 | ||
|
|
d87ab0cadf | ||
|
|
bf6a5c056d | ||
|
|
7497ecd979 | ||
|
|
0d19d78fff | ||
|
|
458b6eb600 | ||
|
|
8f79b079cd | ||
|
|
db8dff6814 | ||
|
|
5526627558 | ||
|
|
ba35e8f292 | ||
|
|
2283f19876 | ||
|
|
152bfa02f0 | ||
|
|
a5c89a1802 | ||
|
|
aa4de2d4b2 | ||
|
|
570943beb7 | ||
|
|
1e12e1d843 | ||
|
|
5ea7a00eba | ||
|
|
e78142232f | ||
|
|
628f3ad9f4 | ||
|
|
40fddfbdd6 | ||
|
|
2c862b04af | ||
|
|
36619607ba | ||
|
|
d2d984647e | ||
|
|
844f2eacf4 | ||
|
|
95f5d406e5 | ||
|
|
561b5c6fdb | ||
|
|
5330a2a85d | ||
|
|
d90fa2ec13 | ||
|
|
325c85a5c1 | ||
|
|
29e64a8c64 | ||
|
|
c05002b0f2 | ||
|
|
314e933914 | ||
|
|
a3428487a7 | ||
|
|
cae0fbbe8c | ||
|
|
461217d0f0 | ||
|
|
58642011df | ||
|
|
9a56671a75 | ||
|
|
45dbbb78b0 | ||
|
|
43e8f60bc6 | ||
|
|
f5c5847788 | ||
|
|
1015b124d5 | ||
|
|
d3328a3b1e | ||
|
|
70ba3c147f | ||
|
|
af56e50f74 | ||
|
|
00445ebadd | ||
|
|
e36f932f62 | ||
|
|
dda701d95f | ||
|
|
b851c628f4 | ||
|
|
a64b7cfe5d | ||
|
|
bee95bf378 | ||
|
|
75135ded09 | ||
|
|
2a7b4bb017 | ||
|
|
d3ede11212 | ||
|
|
5819d2a9d7 | ||
|
|
b9fa8f12d7 | ||
|
|
5ea143f521 | ||
|
|
a8f3ad4487 | ||
|
|
6749a30a6e | ||
|
|
1a6156d8fd | ||
|
|
1fccfd7be5 | ||
|
|
6b46c62bb4 | ||
|
|
d7837cca52 | ||
|
|
9fc925ac51 | ||
|
|
2864a31311 | ||
|
|
6f8cedb1bc | ||
|
|
a02d95a313 | ||
|
|
84319aa8f0 | ||
|
|
0d1be2e328 | ||
|
|
7e6c2cb238 | ||
|
|
8a8001350d | ||
|
|
6de466cf8b | ||
|
|
24916f2f6e | ||
|
|
442e49f51c | ||
|
|
3cf19d6dd0 | ||
|
|
759953cb8d | ||
|
|
ddf7ac5ae4 | ||
|
|
06fd3b00ff | ||
|
|
a8e2d851fe | ||
|
|
81f1d625af | ||
|
|
0f5b7814b5 | ||
|
|
5636d38a9d | ||
|
|
12c49fa3bd | ||
|
|
e88b74350f | ||
|
|
1afe9e98de | ||
|
|
c34a79b152 | ||
|
|
d81a5c630f | ||
|
|
0ace779cde | ||
|
|
fe7d9af331 | ||
|
|
9fe43d6acb | ||
|
|
9908681ba8 | ||
|
|
afbf0d42a7 | ||
|
|
7177eeaa42 | ||
|
|
db2412e2ac | ||
|
|
b7398a4918 | ||
|
|
afdef6d122 | ||
|
|
36f8fa316d | ||
|
|
13f1a922e1 | ||
|
|
f947d25c9d | ||
|
|
1de107c405 | ||
|
|
353439acee | ||
|
|
a44024a795 | ||
|
|
15b6774f9b | ||
|
|
382e09bed1 | ||
|
|
5da94182ae | ||
|
|
c83feeb6f8 | ||
|
|
178894b0fe | ||
|
|
4dbbcff72b | ||
|
|
4aa5dd0ee0 | ||
|
|
b6f00a3945 | ||
|
|
abea17afd9 | ||
|
|
f523fddf6a | ||
|
|
99946aaaaf | ||
|
|
5f9ba2f223 | ||
|
|
8084a2c9e6 | ||
|
|
b951f0621c | ||
|
|
28a31201d3 | ||
|
|
99c262b7d0 | ||
|
|
899e629bf0 | ||
|
|
4c6eb6cc2f | ||
|
|
bc27451e15 | ||
|
|
1fbb7f1a41 | ||
|
|
3742f66abb | ||
|
|
3a6beea064 | ||
|
|
e0e9a54a32 | ||
|
|
ec47907772 | ||
|
|
bd1dc89a5d | ||
|
|
fb109ae97d | ||
|
|
66d637be3d | ||
|
|
ba9f47c544 | ||
|
|
9b991a7301 | ||
|
|
0041e40ca8 | ||
|
|
a0998e42b7 | ||
|
|
cf7289662f | ||
|
|
8576ecaf32 | ||
|
|
b3ab39c4d9 | ||
|
|
2e5c49a1fd | ||
|
|
8763bced76 | ||
|
|
c2f88373e7 | ||
|
|
7d5fd5fcd0 | ||
|
|
f6c49cecc1 | ||
|
|
7ba845297f | ||
|
|
733185d0a9 | ||
|
|
d54e990c4f | ||
|
|
fe106842c8 | ||
|
|
41e633acf5 | ||
|
|
1a6e696b08 | ||
|
|
d401340c51 | ||
|
|
d15d54c2c8 | ||
|
|
3f35b5299f | ||
|
|
026ad08b56 | ||
|
|
b342bd0b46 | ||
|
|
c67b702588 | ||
|
|
ddc4512d2e | ||
|
|
3d8efdf310 | ||
|
|
bfe14b5312 | ||
|
|
a15939b502 | ||
|
|
4fbf564292 | ||
|
|
59d1147469 | ||
|
|
e7990375cb | ||
|
|
623e54788e | ||
|
|
3f138dc40c | ||
|
|
63b2547a02 | ||
|
|
9b3ae84993 | ||
|
|
3d2686a236 | ||
|
|
ed971268be | ||
|
|
d413a945ac | ||
|
|
9d58febc8f | ||
|
|
33fbf82ac0 | ||
|
|
1721d1994e | ||
|
|
0ec18e537d | ||
|
|
117737c6ca | ||
|
|
a7ce19347a | ||
|
|
4289a1ebfa | ||
|
|
5d2288b22a | ||
|
|
7a1a01feef | ||
|
|
e6f7180af1 | ||
|
|
ad5a561adb | ||
|
|
4179b42424 | ||
|
|
f691d46a16 | ||
|
|
1bd08f903b | ||
|
|
6270392d04 | ||
|
|
4d9e6ea310 | ||
|
|
05dac2e42c | ||
|
|
6551f4bb3b | ||
|
|
e0add119ea | ||
|
|
e83ebf50de | ||
|
|
40253048ca | ||
|
|
c484c5a2a1 | ||
|
|
4160df4ca4 | ||
|
|
68bebe1fb7 | ||
|
|
76a9e6f27b | ||
|
|
22a8afee9e | ||
|
|
12efb40dc5 | ||
|
|
0f7d39c410 | ||
|
|
b9dc855016 | ||
|
|
5c49e1d0c1 | ||
|
|
e45401846f | ||
|
|
85d7afaefc | ||
|
|
76d6d3641f | ||
|
|
8b804fb589 | ||
|
|
a81685bfac | ||
|
|
c426e485e5 | ||
|
|
27126f8797 | ||
|
|
66b5477cc1 | ||
|
|
226b6a2192 | ||
|
|
7d4b416fe6 | ||
|
|
215d3f8c0d | ||
|
|
b8f2dd8237 | ||
|
|
526e860a7a | ||
|
|
1db6d6fea6 | ||
|
|
48dd250af1 | ||
|
|
44449b305b | ||
|
|
fb0b2cd37a | ||
|
|
30086e504c | ||
|
|
5b8f033e06 | ||
|
|
f55c991a1b | ||
|
|
4117a7ed19 | ||
|
|
b4f95c43fc | ||
|
|
4740ecbeae | ||
|
|
ddfed259f6 | ||
|
|
1b31d148c9 | ||
|
|
6943fbbb81 | ||
|
|
305c832a97 | ||
|
|
61dfbe702e | ||
|
|
23254f59da | ||
|
|
bb7cc8e8fd |
86
CHANGES
86
CHANGES
@@ -1,3 +1,83 @@
|
||||
CHANGES FROM 2.3 to 2.4 20 April 2017
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
|
||||
* Key tables have undergone major changes. Mode key tables are no longer
|
||||
separate from the main key tables. All mode key tables have been removed,
|
||||
together with the -t flag to bind-key and unbind-key.
|
||||
|
||||
The emacs-edit, vi-edit, emacs-choose and vi-choose tables have been replaced
|
||||
by fixed key bindings in the command prompt and choose modes. The mode-keys
|
||||
and status-keys options remain.
|
||||
|
||||
The emacs-copy and vi-copy tables have been replaced by the copy-mode and
|
||||
copy-mode-vi tables. Commands are sent using the -X and -N flags to
|
||||
send-keys. So the following:
|
||||
|
||||
bind -temacs-copy C-Up scroll-up
|
||||
bind -temacs-copy -R5 WheelUpPane scroll-up
|
||||
|
||||
Becomes:
|
||||
|
||||
bind -Tcopy-mode C-Up send -X scroll-up
|
||||
bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up
|
||||
|
||||
This changes allows the full command parser (including command sequences) and
|
||||
command set to be used - for example, the normal command prompt with editing
|
||||
and history is now used for searching, jumping, and so on instead of a custom
|
||||
one. The default C-r binding is now:
|
||||
|
||||
bind -Tcopy-mode C-r command-prompt -p'search up' "send -X search-backward '%%'"
|
||||
|
||||
There are also some new commmands available with send -X, such as
|
||||
copy-pipe-and-cancel.
|
||||
* set-remain-on-exit has gone -- can be achieved with hooks instead.
|
||||
* Hooks: before hooks have been removed and only a selection of commands now
|
||||
have after hooks (they are no longer automatic). Additional hooks have been
|
||||
added.
|
||||
* The xterm-keys option now defaults to on.
|
||||
|
||||
Normal Changes
|
||||
==============
|
||||
|
||||
* Support for mouse double and triple clicks.
|
||||
* BCE (Background Colour Erase) is now supported.
|
||||
* All occurrences of a search string in copy mode are now highlighted;
|
||||
additionally, the number of search results is displayed. The highlighting
|
||||
updates interactively with the default emacs key bindings (incremental
|
||||
search).
|
||||
* source-file now understands glob patterns.
|
||||
* Formats now have simple comparisons:
|
||||
|
||||
#{==:a,b}
|
||||
#{!=:a,b}
|
||||
|
||||
* There are the following new formats:
|
||||
|
||||
- #{version} -- the tmux server version;
|
||||
- #{client_termtype} -- the terminal type of the client;
|
||||
- #{client_name} -- the name of a client;
|
||||
- #{client_written} -- the number of bytes written to the client.
|
||||
|
||||
* The configuration file now accepts %if/%endif conditional blocks which are
|
||||
processed when it is parsed; the argument is a format string (useful with the
|
||||
new format comparison options).
|
||||
* detach-client now has -E to execute a command replacing the client instead of
|
||||
exiting.
|
||||
* Add support for custom command aliases, this is an array option which
|
||||
contains items of the form "alias=command". This is consulted when an
|
||||
unknown command is parsed.
|
||||
* break-pane now has -n to specify the new window name.
|
||||
* OSC 52 support has been added for programs inside tmux to set a tmux buffer.
|
||||
* The mouse "all event" mode (1003) is now supported.
|
||||
* Palette setting is now possible (OSC 4 and 104).
|
||||
* Strikethrough support (a recent terminfo is required).
|
||||
* Grouped sessions can now be named (new -t).
|
||||
* terminal-overrides and update-environment are now array options (the previous
|
||||
set -ag syntax should work without change).
|
||||
* There have been substantial performance improvements.
|
||||
|
||||
CHANGES FROM 2.2 to 2.3 29 September 2016
|
||||
|
||||
Incompatible Changes
|
||||
@@ -8,9 +88,9 @@ None.
|
||||
Normal Changes
|
||||
==============
|
||||
|
||||
* New option 'pane-border-status' to add text in the oane borders.
|
||||
* New option 'pane-border-status' to add text in the pane borders.
|
||||
* Support for hooks on commands: 'after' and 'before' hooks.
|
||||
* 'source-file' understands '-q' to supress errors for nonexistent files.
|
||||
* 'source-file' understands '-q' to suppress errors for nonexistent files.
|
||||
* Lots of UTF8 improvements, especially on MacOS.
|
||||
* 'window-status-separator' understands #[] expansions.
|
||||
* 'split-window' understands '-f' for performing a full-width split.
|
||||
@@ -31,7 +111,7 @@ Incompatible Changes
|
||||
can be used.
|
||||
|
||||
* Support for TMPDIR has been removed. Use TMUX_TMPDIR instead.
|
||||
* UTF8 detection how happens automatically if the client supports it, hence
|
||||
* UTF8 detection now happens automatically if the client supports it, hence
|
||||
the:
|
||||
|
||||
mouse-utf8
|
||||
|
||||
33
CONTRIBUTING
Normal file
33
CONTRIBUTING
Normal file
@@ -0,0 +1,33 @@
|
||||
When reporting issues:
|
||||
|
||||
YOU MUST INCLUDE THE TMUX VERSION
|
||||
|
||||
DO NOT OPEN AN ISSUE THAT DOES NOT MENTION THE TMUX VERSION
|
||||
|
||||
Please also include:
|
||||
|
||||
- your platform (Linux, OS X, or whatever);
|
||||
- a brief description of the problem with steps to reproduce;
|
||||
- a minimal tmux config, if you can't reproduce without a config;
|
||||
- your terminal, and $TERM inside and outside of tmux;
|
||||
- logs from tmux (see below);
|
||||
- at most one or two screenshots, if helpful.
|
||||
|
||||
This should include at least the output of:
|
||||
|
||||
$ uname -sp && tmux -V && echo $TERM
|
||||
|
||||
Please do not report bugs (crashes, incorrect behaviour) without reproducing on
|
||||
a tmux built from Git master.
|
||||
|
||||
Note that TERM inside tmux must be a variant of screen or tmux (for example:
|
||||
screen or screen-256color, tmux or tmux-256color). Please ensure this is the
|
||||
case before opening an issue.
|
||||
|
||||
To run tmux without a config and get logs, run:
|
||||
|
||||
tmux -Ltest kill-server
|
||||
tmux -vvvv -Ltest -f/dev/null new
|
||||
|
||||
Then reproduce the problem, exit tmux, and attach the tmux-server-*.log file
|
||||
from the current directory to the issue.
|
||||
12
FAQ
12
FAQ
@@ -434,10 +434,18 @@ 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:
|
||||
On OS X, look at the pbcopy(1) and pbpaste(1) commands.
|
||||
|
||||
* Why don't some commands work inside tmux on OS X?
|
||||
|
||||
Apple requires some undocumented, unsupported fiddling to allow commands that
|
||||
interact with the GUI to work. Neither tmux itself nor most shells do this, so
|
||||
an external program is required. This can be found here:
|
||||
|
||||
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
|
||||
|
||||
|
||||
Affected commands may include say(1), pbcopy(1), pbpaste(1) and ssh(1).
|
||||
|
||||
* 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
|
||||
|
||||
1
ISSUE_TEMPLATE
Normal file
1
ISSUE_TEMPLATE
Normal file
@@ -0,0 +1 @@
|
||||
Please read https://raw.githubusercontent.com/tmux/tmux/master/CONTRIBUTING
|
||||
134
Makefile.am
134
Makefile.am
@@ -7,60 +7,54 @@ CLEANFILES = tmux.1.mdoc tmux.1.man
|
||||
# Distribution tarball options.
|
||||
EXTRA_DIST = \
|
||||
CHANGES FAQ README TODO COPYING example_tmux.conf compat/*.[ch] \
|
||||
compat.h tmux.h osdep-*.c xmalloc.h mdoc2man.awk tmux.1
|
||||
osdep-*.c mdoc2man.awk tmux.1
|
||||
dist-hook:
|
||||
make clean
|
||||
grep "^#found_debug=" configure
|
||||
grep "^#enable_debug=" configure
|
||||
|
||||
# Preprocessor flags.
|
||||
CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
|
||||
AM_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.
|
||||
if IS_GLIBC
|
||||
CFLAGS += -D_GNU_SOURCE
|
||||
endif
|
||||
# Additional object files.
|
||||
LDADD = $(LIBOBJS)
|
||||
|
||||
# Set flags for gcc.
|
||||
if IS_GCC
|
||||
CFLAGS += -std=gnu99 -O2
|
||||
AM_CFLAGS += -std=gnu99 -O2
|
||||
if IS_DEBUG
|
||||
CFLAGS += -g
|
||||
CFLAGS += -Wno-long-long -Wall -W -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 -Wno-pointer-sign -Wno-attributes
|
||||
CPPFLAGS += -DDEBUG
|
||||
AM_CFLAGS += -g
|
||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2
|
||||
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
||||
AM_CFLAGS += -Wno-unused-result
|
||||
AM_CPPFLAGS += -DDEBUG
|
||||
endif
|
||||
if IS_COVERAGE
|
||||
CFLAGS += -g -O0 --coverage
|
||||
LDFLAGS += --coverage
|
||||
endif
|
||||
if IS_PROFILE
|
||||
CFLAGS += -g -O0 -pg
|
||||
LDFLAGS += -pg
|
||||
endif
|
||||
CPPFLAGS += -iquote.
|
||||
AM_CPPFLAGS += -iquote.
|
||||
endif
|
||||
|
||||
# Set flags for Solaris.
|
||||
if IS_SUNOS
|
||||
if IS_GCC
|
||||
CPPFLAGS += -D_XPG6 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
||||
AM_CPPFLAGS += -D_XPG6
|
||||
else
|
||||
CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
|
||||
AM_CPPFLAGS += -D_XPG4_2
|
||||
endif
|
||||
endif
|
||||
|
||||
# Set flags for Sun CC.
|
||||
if IS_SUNCC
|
||||
CFLAGS += -erroff=E_EMPTY_DECLARATION
|
||||
AM_CFLAGS += -erroff=E_EMPTY_DECLARATION
|
||||
endif
|
||||
|
||||
# Set _LINUX_SOURCE_COMPAT for AIX for malloc(0).
|
||||
if IS_AIX
|
||||
DEFS += -D_LINUX_SOURCE_COMPAT=1
|
||||
AM_CPPFLAGS += -D_LINUX_SOURCE_COMPAT=1
|
||||
endif
|
||||
|
||||
# Set flags for NetBSD.
|
||||
if IS_NETBSD
|
||||
AM_CPPFLAGS += -D_OPENBSD_SOURCE
|
||||
endif
|
||||
|
||||
# List of sources.
|
||||
@@ -77,15 +71,14 @@ dist_tmux_SOURCES = \
|
||||
cmd-choose-buffer.c \
|
||||
cmd-choose-client.c \
|
||||
cmd-choose-tree.c \
|
||||
cmd-clear-history.c \
|
||||
cmd-command-prompt.c \
|
||||
cmd-confirm-before.c \
|
||||
cmd-copy-mode.c \
|
||||
cmd-detach-client.c \
|
||||
cmd-display-message.c \
|
||||
cmd-display-panes.c \
|
||||
cmd-find.c \
|
||||
cmd-find-window.c \
|
||||
cmd-find.c \
|
||||
cmd-if-shell.c \
|
||||
cmd-join-pane.c \
|
||||
cmd-kill-pane.c \
|
||||
@@ -137,8 +130,9 @@ dist_tmux_SOURCES = \
|
||||
cmd-wait-for.c \
|
||||
cmd.c \
|
||||
colour.c \
|
||||
control.c \
|
||||
compat.h \
|
||||
control-notify.c \
|
||||
control.c \
|
||||
environ.c \
|
||||
format.c \
|
||||
grid-view.c \
|
||||
@@ -153,13 +147,13 @@ dist_tmux_SOURCES = \
|
||||
layout-set.c \
|
||||
layout.c \
|
||||
log.c \
|
||||
mode-key.c \
|
||||
names.c \
|
||||
notify.c \
|
||||
options-table.c \
|
||||
options.c \
|
||||
paste.c \
|
||||
proc.c \
|
||||
pty.c \
|
||||
resize.c \
|
||||
screen-redraw.c \
|
||||
screen-write.c \
|
||||
@@ -172,6 +166,7 @@ dist_tmux_SOURCES = \
|
||||
status.c \
|
||||
style.c \
|
||||
tmux.c \
|
||||
tmux.h \
|
||||
tty-acs.c \
|
||||
tty-keys.c \
|
||||
tty-term.c \
|
||||
@@ -182,79 +177,20 @@ dist_tmux_SOURCES = \
|
||||
window-copy.c \
|
||||
window.c \
|
||||
xmalloc.c \
|
||||
xmalloc.h \
|
||||
xterm-keys.c
|
||||
nodist_tmux_SOURCES = osdep-@PLATFORM@.c
|
||||
|
||||
# Add compat file for forkpty.
|
||||
if NEED_FORKPTY
|
||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
||||
endif
|
||||
|
||||
# Add compat file for utf8proc.
|
||||
if HAVE_UTF8PROC
|
||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
||||
endif
|
||||
|
||||
# Add compat for missing or broken functions.
|
||||
if NO_FORKPTY
|
||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
||||
endif
|
||||
if NO_IMSG
|
||||
nodist_tmux_SOURCES += compat/imsg.c compat/imsg-buffer.c
|
||||
endif
|
||||
if NO_CLOSEFROM
|
||||
nodist_tmux_SOURCES += compat/closefrom.c
|
||||
endif
|
||||
if NO_DAEMON
|
||||
nodist_tmux_SOURCES += compat/daemon.c
|
||||
endif
|
||||
if NO_GETPROGNAME
|
||||
nodist_tmux_SOURCES += compat/getprogname.c
|
||||
endif
|
||||
if NO_SETPROCTITLE
|
||||
nodist_tmux_SOURCES += compat/setproctitle.c
|
||||
endif
|
||||
if NO_SETENV
|
||||
nodist_tmux_SOURCES += compat/setenv.c
|
||||
endif
|
||||
if NO_STRLCAT
|
||||
nodist_tmux_SOURCES += compat/strlcat.c
|
||||
endif
|
||||
if NO_STRLCPY
|
||||
nodist_tmux_SOURCES += compat/strlcpy.c
|
||||
endif
|
||||
if NO_ASPRINTF
|
||||
nodist_tmux_SOURCES += compat/asprintf.c
|
||||
endif
|
||||
if NO_FGETLN
|
||||
nodist_tmux_SOURCES += compat/fgetln.c
|
||||
endif
|
||||
if NO_FPARSELN
|
||||
nodist_tmux_SOURCES += compat/fparseln.c
|
||||
endif
|
||||
if NO_GETOPT
|
||||
nodist_tmux_SOURCES += compat/getopt.c
|
||||
endif
|
||||
if NO_STRCASESTR
|
||||
nodist_tmux_SOURCES += compat/strcasestr.c
|
||||
endif
|
||||
if NO_STRSEP
|
||||
nodist_tmux_SOURCES += compat/strsep.c
|
||||
endif
|
||||
if NO_VIS
|
||||
nodist_tmux_SOURCES += compat/vis.c compat/unvis.c
|
||||
endif
|
||||
if NO_STRTONUM
|
||||
nodist_tmux_SOURCES += compat/strtonum.c
|
||||
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
|
||||
if NO_REALLOCARRAY
|
||||
nodist_tmux_SOURCES += compat/reallocarray.c
|
||||
endif
|
||||
|
||||
# Install tmux.1 in the right format.
|
||||
install-exec-hook:
|
||||
if test x@MANFORMAT@ = xmdoc; then \
|
||||
|
||||
14
README
14
README
@@ -10,13 +10,17 @@ tmux depends on libevent 2.x. Download it from:
|
||||
|
||||
http://libevent.org
|
||||
|
||||
To build tmux from a release tarball, do:
|
||||
It also depends on ncurses, available from:
|
||||
|
||||
http://invisible-island.net/ncurses/
|
||||
|
||||
To build and install tmux from a release tarball, use:
|
||||
|
||||
$ ./configure && make
|
||||
$ sudo make install
|
||||
|
||||
By default, tmux will use the utempter library to update utmp(5), if it is
|
||||
installed. Run configure with --disable-utempter to disable this.
|
||||
tmux can use the utempter library to update utmp(5), if it is installed - run
|
||||
configure with --enable-utempter to enable this.
|
||||
|
||||
To get and build the latest from version control:
|
||||
|
||||
@@ -38,8 +42,8 @@ TODO file and an example configuration in example_tmux.conf.
|
||||
|
||||
A vim(1) syntax file is available at:
|
||||
|
||||
https://github.com/keith/tmux.vim
|
||||
https://raw.githubusercontent.com/keith/tmux.vim/master/syntax/tmux.vim
|
||||
https://github.com/ericpruitt/tmux.vim
|
||||
https://raw.githubusercontent.com/ericpruitt/tmux.vim/master/vim/syntax/tmux.vim
|
||||
|
||||
And a bash(1) completion file at:
|
||||
|
||||
|
||||
4
SYNCING
4
SYNCING
@@ -140,7 +140,7 @@ to compat/ as and when appropriate.
|
||||
Release tmux for next version
|
||||
=============================
|
||||
|
||||
1. Comment the "found_debug=yes" line in configure.ac, since releases
|
||||
1. Comment the "enable_debug=yes" line in configure.ac, since releases
|
||||
don't have debugging enabled, otherwise make(1) aborts when
|
||||
preparing the distribution.
|
||||
|
||||
@@ -172,5 +172,5 @@ Release tmux for next version
|
||||
the Makefile. Commit it, and run 'make' to replace %%VERSION%%. Push
|
||||
the result out.
|
||||
|
||||
8. Bump version in tmux/tmux.git configure.ac and uncomment "found_debug=yes" to
|
||||
8. Bump version in tmux/tmux.git configure.ac and uncomment "enable_debug=yes" to
|
||||
create a debug build by default.
|
||||
|
||||
67
TODO
67
TODO
@@ -5,21 +5,19 @@
|
||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
||||
and command prompt
|
||||
* last-pane across sessions
|
||||
* list-keys should quote output so that bindings can just be used in
|
||||
config file as-is
|
||||
* resize-pane -p to match split-window -p
|
||||
* flag to wait-for to have a timeout and/or to stop waiting when the
|
||||
client gets a signal
|
||||
|
||||
- make command sequences more usable
|
||||
* don't require space after ;
|
||||
* options for error handling: && and ||?
|
||||
|
||||
- options bits and pieces:
|
||||
* set-remain-on-exit is a complete hack
|
||||
* way to set socket path from config file
|
||||
|
||||
- format improvements:
|
||||
* option to quote format (#{q:session_name})
|
||||
* formats need conditions for >0 (for #P)
|
||||
* some way to pad # stuff with spaces
|
||||
* formats to show if a window is linked into multiple sessions, into
|
||||
multiple attached sessions, and is the active window in multiple
|
||||
@@ -27,13 +25,11 @@
|
||||
|
||||
- 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)
|
||||
* choose modes should ditch the key bindings and just have fixed keys, and
|
||||
be more customized to their purpose (d to delete a buffer for choose-buffer,
|
||||
a preview of buffer contents, etc)
|
||||
be more customized to their purpose (d to delete a buffer for choose-buffer,
|
||||
a preview of buffer contents, etc)
|
||||
|
||||
- improve monitor-*:
|
||||
* straighten out rules for multiple clients
|
||||
@@ -48,33 +44,17 @@
|
||||
- warts on current naming:
|
||||
* display-time but message-fg/bg/attr
|
||||
* list-* vs show-*
|
||||
* split-window -> split-pane?
|
||||
|
||||
- better UTF-8 support:
|
||||
* message display
|
||||
* prompt input
|
||||
* searching in copy mode
|
||||
|
||||
- copy/paste improvements:
|
||||
* incremental searching
|
||||
* paste w/o trailing whitespace
|
||||
* command to toggle selection not to move it in copy-mode
|
||||
* regex searching
|
||||
* copy-pipe should have -x as well
|
||||
* copy mode key bindings should just be a standard key table, using
|
||||
something like "copy-mode start-selection"; it could use
|
||||
command-prompt for search, goto, etc:
|
||||
|
||||
bind -Temacs command-prompt -p'Search Up: ' 'copy-mode search-up %%'
|
||||
|
||||
it'd need a separate lookup, because modes are per-pane, perhaps a
|
||||
table() cb to give the table name ("vi" or "emacs"). anything in the
|
||||
table fires the command, anything not in the table is injected as a
|
||||
key
|
||||
* searching in copy mode should unwrap lines, so if you search for "foobar"
|
||||
then it should be found even if it is now "foo\nbar" (if the WRAP flag
|
||||
is set on the line)
|
||||
then it should be found even if it is now "foo\nbar" (if the WRAP flag
|
||||
is set on the line)
|
||||
* capture-pane option to preserve spaces but not join lines
|
||||
* improve word and line selection in copy mode (for example when dragging
|
||||
it should select by word. compare how xterm works. GitHub issue 682)
|
||||
|
||||
- layout stuff
|
||||
* way to tag a layout as a number/name
|
||||
@@ -89,19 +69,17 @@
|
||||
* panning over window (window larger than visible)
|
||||
* a mode where one application can cross two panes (ie x|y, width =
|
||||
COLUMNS/2 but height = ROWS * 2)
|
||||
* general key to space cells out evenly (horiz or vert) within their
|
||||
parent cell (could replace even-vert/even-horiz layouts)
|
||||
* separate active panes for different clients
|
||||
|
||||
- terminfo bits
|
||||
* use a better termcap internally instead of screen, perhaps xterm
|
||||
* use screen-256color when started on 256 colour terminal?
|
||||
|
||||
- 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
|
||||
window->session->global, and for session we look session->global.
|
||||
problem: what about windows in multiple sessions? there are contexts
|
||||
where we do not know which session, or where multiple choices makes
|
||||
no sense... could at least have one global list for all types of
|
||||
global options and keep separate window,session lists
|
||||
* 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(),
|
||||
@@ -120,12 +98,6 @@
|
||||
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
|
||||
* we do more work than we should if a single read() contains operations
|
||||
that cancel each other out: for example, writing twice to the same
|
||||
cell, or writing and then clearing a line; it would be nice to
|
||||
optimize these. would it mean processing the entire read() data first
|
||||
then applying changes? or an initial optimization step? or something
|
||||
else?
|
||||
|
||||
- miscellaneous
|
||||
* way to keep a job running just read its last line of output for #()
|
||||
@@ -137,7 +109,14 @@
|
||||
jobs and run-shell and lock command all start with slightly different
|
||||
environments
|
||||
* multiline status line? separate command prompt and status line?
|
||||
* customizable command aliases
|
||||
* automatic pane logging
|
||||
* BCE? We are halfway there (output side is done for pane backgrounds),
|
||||
just need to change how screen/grid handles erase
|
||||
* marks in history, automatically add (move?) one when pane is changed
|
||||
* this doesn't work, need pane reference count probably:
|
||||
bind -n DoubleClick3Status confirm-before -p "kill-window #I? (y/n)" kill-window
|
||||
|
||||
- hooks
|
||||
* more hooks for various things
|
||||
* finish after hooks for special commands
|
||||
* multiple hooks with the same name?
|
||||
* finish hooks for notifys
|
||||
* for session_closed, if no sessions at all, perhaps fake up a temporary one
|
||||
|
||||
286
alerts.c
286
alerts.c
@@ -19,24 +19,28 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <event.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
int alerts_fired;
|
||||
static int alerts_fired;
|
||||
|
||||
void alerts_timer(int, short, void *);
|
||||
int alerts_enabled(struct window *, int);
|
||||
void alerts_callback(int, short, void *);
|
||||
void alerts_reset(struct window *);
|
||||
static void alerts_timer(int, short, void *);
|
||||
static int alerts_enabled(struct window *, int);
|
||||
static void alerts_callback(int, short, void *);
|
||||
static void alerts_reset(struct window *);
|
||||
|
||||
void alerts_run_hook(struct session *, struct winlink *, int);
|
||||
int alerts_check_all(struct session *, struct winlink *);
|
||||
int alerts_check_bell(struct session *, struct winlink *);
|
||||
int alerts_check_activity(struct session *, struct winlink *);
|
||||
int alerts_check_silence(struct session *, struct winlink *);
|
||||
void alerts_ring_bell(struct session *);
|
||||
static int alerts_check_all(struct window *);
|
||||
static int alerts_check_bell(struct window *);
|
||||
static int alerts_check_activity(struct window *);
|
||||
static int alerts_check_silence(struct window *);
|
||||
static void printflike(2, 3) alerts_set_message(struct session *, const char *,
|
||||
...);
|
||||
static void alerts_ring_bell(struct session *);
|
||||
|
||||
void
|
||||
static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);
|
||||
|
||||
static void
|
||||
alerts_timer(__unused int fd, __unused short events, void *arg)
|
||||
{
|
||||
struct window *w = arg;
|
||||
@@ -46,61 +50,33 @@ alerts_timer(__unused int fd, __unused short events, void *arg)
|
||||
alerts_queue(w, WINDOW_SILENCE);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
alerts_callback(__unused int fd, __unused short events, __unused void *arg)
|
||||
{
|
||||
struct window *w;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
int flags, alerts;
|
||||
struct window *w, *w1;
|
||||
int alerts;
|
||||
|
||||
RB_FOREACH(w, windows, &windows) {
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
if (wl->window != w)
|
||||
continue;
|
||||
flags = w->flags;
|
||||
TAILQ_FOREACH_SAFE(w, &alerts_list, alerts_entry, w1) {
|
||||
alerts = alerts_check_all(w);
|
||||
log_debug("@%u alerts check, alerts %#x", w->id, alerts);
|
||||
|
||||
alerts = alerts_check_all(s, wl);
|
||||
w->alerts_queued = 0;
|
||||
TAILQ_REMOVE(&alerts_list, w, alerts_entry);
|
||||
|
||||
log_debug("%s:%d @%u alerts check, alerts %#x, "
|
||||
"flags %#x", s->name, wl->idx, w->id,
|
||||
alerts, flags);
|
||||
}
|
||||
}
|
||||
w->flags &= ~WINDOW_ALERTFLAGS;
|
||||
window_remove_ref(w);
|
||||
}
|
||||
alerts_fired = 0;
|
||||
}
|
||||
|
||||
void
|
||||
alerts_run_hook(struct session *s, struct winlink *wl, int flags)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (cmd_find_from_winlink(&fs, s, wl) != 0)
|
||||
return;
|
||||
|
||||
if (flags & WINDOW_BELL)
|
||||
hooks_run(s->hooks, NULL, &fs, "alert-bell");
|
||||
if (flags & WINDOW_SILENCE)
|
||||
hooks_run(s->hooks, NULL, &fs, "alert-silence");
|
||||
if (flags & WINDOW_ACTIVITY)
|
||||
hooks_run(s->hooks, NULL, &fs, "alert-activity");
|
||||
}
|
||||
|
||||
int
|
||||
alerts_check_all(struct session *s, struct winlink *wl)
|
||||
static int
|
||||
alerts_check_all(struct window *w)
|
||||
{
|
||||
int alerts;
|
||||
|
||||
alerts = alerts_check_bell(s, wl);
|
||||
alerts |= alerts_check_activity(s, wl);
|
||||
alerts |= alerts_check_silence(s, wl);
|
||||
if (alerts != 0) {
|
||||
alerts_run_hook(s, wl, alerts);
|
||||
server_status_session(s);
|
||||
}
|
||||
|
||||
alerts = alerts_check_bell(w);
|
||||
alerts |= alerts_check_activity(w);
|
||||
alerts |= alerts_check_silence(w);
|
||||
return (alerts);
|
||||
}
|
||||
|
||||
@@ -110,10 +86,10 @@ alerts_check_session(struct session *s)
|
||||
struct winlink *wl;
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows)
|
||||
alerts_check_all(s, wl);
|
||||
alerts_check_all(wl->window);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
alerts_enabled(struct window *w, int flags)
|
||||
{
|
||||
if (flags & WINDOW_BELL)
|
||||
@@ -138,7 +114,7 @@ alerts_reset_all(void)
|
||||
alerts_reset(w);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
alerts_reset(struct window *w)
|
||||
{
|
||||
struct timeval tv;
|
||||
@@ -168,6 +144,12 @@ alerts_queue(struct window *w, int flags)
|
||||
log_debug("@%u alerts flags added %#x", w->id, flags);
|
||||
}
|
||||
|
||||
if (!w->alerts_queued) {
|
||||
w->alerts_queued = 1;
|
||||
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
|
||||
w->references++;
|
||||
}
|
||||
|
||||
if (!alerts_fired && alerts_enabled(w, flags)) {
|
||||
log_debug("alerts check queued (by @%u)", w->id);
|
||||
event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
|
||||
@@ -175,114 +157,160 @@ alerts_queue(struct window *w, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
alerts_check_bell(struct session *s, struct winlink *wl)
|
||||
static int
|
||||
alerts_check_bell(struct window *w)
|
||||
{
|
||||
struct window *ws;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
struct window *w = wl->window;
|
||||
int action, visual;
|
||||
|
||||
if (!(w->flags & WINDOW_BELL))
|
||||
return (0);
|
||||
if (s->curw != wl) {
|
||||
wl->flags |= WINLINK_BELL;
|
||||
w->flags &= ~WINDOW_BELL;
|
||||
}
|
||||
if (s->curw->window == w)
|
||||
w->flags &= ~WINDOW_BELL;
|
||||
|
||||
action = options_get_number(s->options, "bell-action");
|
||||
if (action == BELL_NONE)
|
||||
if (~w->flags & WINDOW_BELL)
|
||||
return (0);
|
||||
|
||||
visual = options_get_number(s->options, "visual-bell");
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s || c->flags & CLIENT_CONTROL)
|
||||
continue;
|
||||
if (!visual) {
|
||||
if ((action == BELL_CURRENT &&
|
||||
c->session->curw->window == w) ||
|
||||
(action == BELL_OTHER &&
|
||||
c->session->curw->window != w) ||
|
||||
action == BELL_ANY)
|
||||
tty_putcode(&c->tty, TTYC_BEL);
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
||||
wl->session->flags &= ~SESSION_ALERTED;
|
||||
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
||||
if (wl->flags & WINLINK_BELL)
|
||||
continue;
|
||||
s = wl->session;
|
||||
if (s->curw != wl) {
|
||||
wl->flags |= WINLINK_BELL;
|
||||
notify_winlink("alert-bell", s, wl);
|
||||
}
|
||||
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
action = options_get_number(s->options, "bell-action");
|
||||
if (action == BELL_NONE)
|
||||
return (0);
|
||||
|
||||
visual = options_get_number(s->options, "visual-bell");
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s || c->flags & CLIENT_CONTROL)
|
||||
continue;
|
||||
ws = c->session->curw->window;
|
||||
|
||||
if (action == BELL_CURRENT && ws != w)
|
||||
action = BELL_NONE;
|
||||
if (action == BELL_OTHER && ws != w)
|
||||
action = BELL_NONE;
|
||||
|
||||
if (!visual) {
|
||||
if (action != BELL_NONE)
|
||||
tty_putcode(&c->tty, TTYC_BEL);
|
||||
continue;
|
||||
}
|
||||
if (action == BELL_CURRENT)
|
||||
status_message_set(c, "Bell in current window");
|
||||
else if (action != BELL_NONE) {
|
||||
status_message_set(c, "Bell in window %d",
|
||||
wl->idx);
|
||||
}
|
||||
}
|
||||
if (action == BELL_CURRENT && c->session->curw->window == w)
|
||||
status_message_set(c, "Bell in current window");
|
||||
else if (action == BELL_ANY || (action == BELL_OTHER &&
|
||||
c->session->curw->window != w))
|
||||
status_message_set(c, "Bell in window %d", wl->idx);
|
||||
}
|
||||
|
||||
return (WINDOW_BELL);
|
||||
}
|
||||
|
||||
int
|
||||
alerts_check_activity(struct session *s, struct winlink *wl)
|
||||
static int
|
||||
alerts_check_activity(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct window *w = wl->window;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
|
||||
if (s->curw->window == w)
|
||||
w->flags &= ~WINDOW_ACTIVITY;
|
||||
|
||||
if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
|
||||
if (~w->flags & WINDOW_ACTIVITY)
|
||||
return (0);
|
||||
if (s->curw == wl)
|
||||
return (0);
|
||||
|
||||
if (!options_get_number(w->options, "monitor-activity"))
|
||||
return (0);
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
wl->flags |= WINLINK_ACTIVITY;
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
||||
wl->session->flags &= ~SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "visual-activity")) {
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s)
|
||||
continue;
|
||||
status_message_set(c, "Activity in window %d", wl->idx);
|
||||
}
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
||||
if (wl->flags & WINLINK_ACTIVITY)
|
||||
continue;
|
||||
s = wl->session;
|
||||
if (s->curw == wl)
|
||||
continue;
|
||||
|
||||
wl->flags |= WINLINK_ACTIVITY;
|
||||
notify_winlink("alert-activity", s, wl);
|
||||
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
if (options_get_number(s->options, "visual-activity"))
|
||||
alerts_set_message(s, "Activity in window %d", wl->idx);
|
||||
}
|
||||
|
||||
return (WINDOW_ACTIVITY);
|
||||
}
|
||||
|
||||
int
|
||||
alerts_check_silence(struct session *s, struct winlink *wl)
|
||||
static int
|
||||
alerts_check_silence(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct window *w = wl->window;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
|
||||
if (s->curw->window == w)
|
||||
w->flags &= ~WINDOW_SILENCE;
|
||||
|
||||
if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
|
||||
if (~w->flags & WINDOW_SILENCE)
|
||||
return (0);
|
||||
if (s->curw == wl)
|
||||
if (!options_get_number(w->options, "monitor-silence"))
|
||||
return (0);
|
||||
|
||||
if (options_get_number(w->options, "monitor-silence") == 0)
|
||||
return (0);
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
||||
wl->session->flags &= ~SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
wl->flags |= WINLINK_SILENCE;
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
||||
if (wl->flags & WINLINK_SILENCE)
|
||||
continue;
|
||||
s = wl->session;
|
||||
if (s->curw == wl)
|
||||
continue;
|
||||
wl->flags |= WINLINK_SILENCE;
|
||||
notify_winlink("alert-silence", s, wl);
|
||||
|
||||
if (options_get_number(s->options, "visual-silence")) {
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s)
|
||||
continue;
|
||||
status_message_set(c, "Silence in window %d", wl->idx);
|
||||
}
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
|
||||
if (!options_get_number(s->options, "visual-silence"))
|
||||
alerts_set_message(s, "Silence in window %d", wl->idx);
|
||||
}
|
||||
|
||||
return (WINDOW_SILENCE);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
alerts_set_message(struct session *s, const char *fmt, ...)
|
||||
{
|
||||
struct client *c;
|
||||
va_list ap;
|
||||
char *message;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&message, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == s)
|
||||
status_message_set(c, "%s", message);
|
||||
}
|
||||
|
||||
free(message);
|
||||
}
|
||||
|
||||
static void
|
||||
alerts_ring_bell(struct session *s)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
65
arguments.c
65
arguments.c
@@ -34,43 +34,21 @@ struct args_entry {
|
||||
RB_ENTRY(args_entry) entry;
|
||||
};
|
||||
|
||||
struct args_entry *args_find(struct args *, u_char);
|
||||
static void args_set(struct args *, u_char, const char *);
|
||||
static struct args_entry *args_find(struct args *, u_char);
|
||||
|
||||
RB_GENERATE(args_tree, args_entry, entry, args_cmp);
|
||||
static int args_cmp(struct args_entry *, struct args_entry *);
|
||||
RB_GENERATE_STATIC(args_tree, args_entry, entry, args_cmp);
|
||||
|
||||
/* Arguments tree comparison function. */
|
||||
int
|
||||
static 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, ...)
|
||||
{
|
||||
struct args *args;
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
args = xcalloc(1, sizeof *args);
|
||||
|
||||
args->argc = argc;
|
||||
if (argc == 0)
|
||||
args->argv = NULL;
|
||||
else
|
||||
args->argv = xcalloc(argc, sizeof *args->argv);
|
||||
|
||||
va_start(ap, argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
args->argv[i] = xstrdup(va_arg(ap, char *));
|
||||
va_end(ap);
|
||||
|
||||
return (args);
|
||||
}
|
||||
|
||||
/* Find a flag in the arguments tree. */
|
||||
struct args_entry *
|
||||
static struct args_entry *
|
||||
args_find(struct args *args, u_char ch)
|
||||
{
|
||||
struct args_entry entry;
|
||||
@@ -151,9 +129,10 @@ char *
|
||||
args_print(struct args *args)
|
||||
{
|
||||
size_t len;
|
||||
char *buf;
|
||||
int i;
|
||||
char *buf, *escaped;
|
||||
int i, flags;
|
||||
struct args_entry *entry;
|
||||
static const char quoted[] = " #\"';$";
|
||||
|
||||
len = 1;
|
||||
buf = xcalloc(1, len);
|
||||
@@ -177,20 +156,32 @@ args_print(struct args *args)
|
||||
args_print_add(&buf, &len, " -%c ", entry->flag);
|
||||
else
|
||||
args_print_add(&buf, &len, "-%c ", entry->flag);
|
||||
if (strchr(entry->value, ' ') != NULL)
|
||||
args_print_add(&buf, &len, "\"%s\"", entry->value);
|
||||
|
||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
||||
if (entry->value[strcspn(entry->value, quoted)] != '\0')
|
||||
flags |= VIS_DQ;
|
||||
utf8_stravis(&escaped, entry->value, flags);
|
||||
if (flags & VIS_DQ)
|
||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
||||
else
|
||||
args_print_add(&buf, &len, "%s", entry->value);
|
||||
args_print_add(&buf, &len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
|
||||
/* And finally the argument vector. */
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
if (*buf != '\0')
|
||||
args_print_add(&buf, &len, " ");
|
||||
if (strchr(args->argv[i], ' ') != NULL)
|
||||
args_print_add(&buf, &len, "\"%s\"", args->argv[i]);
|
||||
|
||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
||||
if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
|
||||
flags |= VIS_DQ;
|
||||
utf8_stravis(&escaped, args->argv[i], flags);
|
||||
if (flags & VIS_DQ)
|
||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
||||
else
|
||||
args_print_add(&buf, &len, "%s", args->argv[i]);
|
||||
args_print_add(&buf, &len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
|
||||
return (buf);
|
||||
@@ -204,7 +195,7 @@ args_has(struct args *args, u_char ch)
|
||||
}
|
||||
|
||||
/* Set argument value in the arguments tree. */
|
||||
void
|
||||
static void
|
||||
args_set(struct args *args, u_char ch, const char *value)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
|
||||
23
attributes.c
23
attributes.c
@@ -23,7 +23,7 @@
|
||||
#include "tmux.h"
|
||||
|
||||
const char *
|
||||
attributes_tostring(u_char attr)
|
||||
attributes_tostring(int attr)
|
||||
{
|
||||
static char buf[128];
|
||||
size_t len;
|
||||
@@ -31,14 +31,15 @@ attributes_tostring(u_char attr)
|
||||
if (attr == 0)
|
||||
return ("none");
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s",
|
||||
attr & GRID_ATTR_BRIGHT ? "bright," : "",
|
||||
attr & GRID_ATTR_DIM ? "dim," : "",
|
||||
attr & GRID_ATTR_UNDERSCORE ? "underscore," : "",
|
||||
attr & GRID_ATTR_BLINK ? "blink," : "",
|
||||
attr & GRID_ATTR_REVERSE ? "reverse," : "",
|
||||
attr & GRID_ATTR_HIDDEN ? "hidden," : "",
|
||||
attr & GRID_ATTR_ITALICS ? "italics," : "");
|
||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s",
|
||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
||||
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "");
|
||||
if (len > 0)
|
||||
buf[len - 1] = '\0';
|
||||
|
||||
@@ -49,7 +50,7 @@ int
|
||||
attributes_fromstring(const char *str)
|
||||
{
|
||||
const char delimiters[] = " ,|";
|
||||
u_char attr;
|
||||
int attr;
|
||||
size_t end;
|
||||
|
||||
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||
@@ -78,6 +79,8 @@ attributes_fromstring(const char *str)
|
||||
attr |= GRID_ATTR_HIDDEN;
|
||||
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||
attr |= GRID_ATTR_ITALICS;
|
||||
else if (end == 13 && strncasecmp(str, "strikethrough", end) == 0)
|
||||
attr |= GRID_ATTR_STRIKETHROUGH;
|
||||
else
|
||||
return (-1);
|
||||
str += end + strspn(str + end, delimiters);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "x$(uname)" = "xOpenBSD" ]; then
|
||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10
|
||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65
|
||||
[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.15
|
||||
[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.69
|
||||
fi
|
||||
|
||||
die()
|
||||
|
||||
130
cfg.c
130
cfg.c
@@ -27,15 +27,26 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
char *cfg_file;
|
||||
struct cmd_q *cfg_cmd_q;
|
||||
static char *cfg_file;
|
||||
int cfg_finished;
|
||||
int cfg_references;
|
||||
char **cfg_causes;
|
||||
u_int cfg_ncauses;
|
||||
static char **cfg_causes;
|
||||
static u_int cfg_ncauses;
|
||||
struct client *cfg_client;
|
||||
|
||||
void cfg_default_done(struct cmd_q *);
|
||||
static enum cmd_retval
|
||||
cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
if (cfg_finished)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cfg_finished = 1;
|
||||
|
||||
if (!RB_EMPTY(&sessions))
|
||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
||||
|
||||
if (cfg_client != NULL)
|
||||
server_client_unref(cfg_client);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
set_cfg_file(const char *path)
|
||||
@@ -50,37 +61,34 @@ start_cfg(void)
|
||||
const char *home;
|
||||
int quiet = 0;
|
||||
|
||||
cfg_cmd_q = cmdq_new(NULL);
|
||||
cfg_cmd_q->emptyfn = cfg_default_done;
|
||||
|
||||
cfg_finished = 0;
|
||||
cfg_references = 1;
|
||||
|
||||
cfg_client = TAILQ_FIRST(&clients);
|
||||
if (cfg_client != NULL)
|
||||
cfg_client->references++;
|
||||
|
||||
load_cfg(TMUX_CONF, cfg_cmd_q, 1);
|
||||
load_cfg(TMUX_CONF, cfg_client, NULL, 1);
|
||||
|
||||
if (cfg_file == NULL && (home = find_home()) != NULL) {
|
||||
xasprintf(&cfg_file, "%s/.tmux.conf", home);
|
||||
quiet = 1;
|
||||
}
|
||||
if (cfg_file != NULL)
|
||||
load_cfg(cfg_file, cfg_cmd_q, quiet);
|
||||
load_cfg(cfg_file, cfg_client, NULL, quiet);
|
||||
|
||||
cmdq_continue(cfg_cmd_q);
|
||||
cmdq_append(cfg_client, cmdq_get_callback(cfg_done, NULL));
|
||||
}
|
||||
|
||||
int
|
||||
load_cfg(const char *path, struct cmd_q *cmdq, int quiet)
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
{
|
||||
FILE *f;
|
||||
char delim[3] = { '\\', '\\', '\0' };
|
||||
u_int found;
|
||||
size_t line = 0;
|
||||
char *buf, *cause1, *p;
|
||||
struct cmd_list *cmdlist;
|
||||
FILE *f;
|
||||
const char delim[3] = { '\\', '\\', '\0' };
|
||||
u_int found = 0;
|
||||
size_t line = 0;
|
||||
char *buf, *cause1, *p, *q, *s;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
int condition = 0;
|
||||
struct format_tree *ft;
|
||||
|
||||
log_debug("loading %s", path);
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
@@ -90,21 +98,50 @@ load_cfg(const char *path, struct cmd_q *cmdq, int quiet)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
found = 0;
|
||||
while ((buf = fparseln(f, NULL, &line, delim, 0)) != NULL) {
|
||||
log_debug("%s: %s", path, buf);
|
||||
|
||||
/* Skip empty lines. */
|
||||
p = buf;
|
||||
while (isspace((u_char) *p))
|
||||
while (isspace((u_char)*p))
|
||||
p++;
|
||||
if (*p == '\0') {
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
q = p + strlen(p) - 1;
|
||||
while (q != p && isspace((u_char)*q))
|
||||
*q-- = '\0';
|
||||
|
||||
/* Parse and run the command. */
|
||||
if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) {
|
||||
if (condition != 0 && strcmp(p, "%endif") == 0) {
|
||||
condition = 0;
|
||||
continue;
|
||||
}
|
||||
if (strncmp(p, "%if ", 4) == 0) {
|
||||
if (condition != 0) {
|
||||
cfg_add_cause("%s:%zu: nested %%if", path,
|
||||
line);
|
||||
continue;
|
||||
}
|
||||
ft = format_create(NULL, FORMAT_NONE, FORMAT_NOJOBS);
|
||||
|
||||
s = p + 3;
|
||||
while (isspace((u_char)*s))
|
||||
s++;
|
||||
s = format_expand(ft, s);
|
||||
if (*s != '\0' && (s[0] != '0' || s[1] != '\0'))
|
||||
condition = 1;
|
||||
else
|
||||
condition = -1;
|
||||
free(s);
|
||||
|
||||
format_free(ft);
|
||||
continue;
|
||||
}
|
||||
if (condition == -1)
|
||||
continue;
|
||||
|
||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
||||
if (cmdlist == NULL) {
|
||||
free(buf);
|
||||
if (cause1 == NULL)
|
||||
continue;
|
||||
@@ -116,8 +153,13 @@ load_cfg(const char *path, struct cmd_q *cmdq, int quiet)
|
||||
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
cmdq_append(cmdq, cmdlist, NULL);
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item);
|
||||
else
|
||||
cmdq_append(c, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
found++;
|
||||
}
|
||||
fclose(f);
|
||||
@@ -125,34 +167,6 @@ load_cfg(const char *path, struct cmd_q *cmdq, int quiet)
|
||||
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);
|
||||
server_client_unref(cfg_client);
|
||||
cfg_client = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cfg_add_cause(const char *fmt, ...)
|
||||
{
|
||||
@@ -169,12 +183,12 @@ cfg_add_cause(const char *fmt, ...)
|
||||
}
|
||||
|
||||
void
|
||||
cfg_print_causes(struct cmd_q *cmdq)
|
||||
cfg_print_causes(struct cmdq_item *item)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
cmdq_print(cmdq, "%s", cfg_causes[i]);
|
||||
cmdq_print(item, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
}
|
||||
|
||||
|
||||
108
client.c
108
client.c
@@ -33,11 +33,11 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct tmuxproc *client_proc;
|
||||
struct tmuxpeer *client_peer;
|
||||
int client_flags;
|
||||
struct event client_stdin;
|
||||
enum {
|
||||
static struct tmuxproc *client_proc;
|
||||
static struct tmuxpeer *client_peer;
|
||||
static int client_flags;
|
||||
static struct event client_stdin;
|
||||
static enum {
|
||||
CLIENT_EXIT_NONE,
|
||||
CLIENT_EXIT_DETACHED,
|
||||
CLIENT_EXIT_DETACHED_HUP,
|
||||
@@ -47,29 +47,31 @@ enum {
|
||||
CLIENT_EXIT_EXITED,
|
||||
CLIENT_EXIT_SERVER_EXITED,
|
||||
} client_exitreason = CLIENT_EXIT_NONE;
|
||||
int client_exitval;
|
||||
enum msgtype client_exittype;
|
||||
const char *client_exitsession;
|
||||
int client_attached;
|
||||
static int client_exitval;
|
||||
static enum msgtype client_exittype;
|
||||
static const char *client_exitsession;
|
||||
static const char *client_execshell;
|
||||
static const char *client_execcmd;
|
||||
static int client_attached;
|
||||
|
||||
__dead void client_exec(const char *,const char *);
|
||||
int client_get_lock(char *);
|
||||
int client_connect(struct event_base *, const char *, int);
|
||||
void client_send_identify(const char *, const char *);
|
||||
void client_stdin_callback(int, short, void *);
|
||||
void client_write(int, const char *, size_t);
|
||||
void client_signal(int);
|
||||
void client_dispatch(struct imsg *, void *);
|
||||
void client_dispatch_attached(struct imsg *);
|
||||
void client_dispatch_wait(struct imsg *, const char *);
|
||||
const char *client_exit_message(void);
|
||||
static __dead void client_exec(const char *,const char *);
|
||||
static int client_get_lock(char *);
|
||||
static int client_connect(struct event_base *, const char *, int);
|
||||
static void client_send_identify(const char *, const char *);
|
||||
static void client_stdin_callback(int, short, void *);
|
||||
static void client_write(int, const char *, size_t);
|
||||
static void client_signal(int);
|
||||
static void client_dispatch(struct imsg *, void *);
|
||||
static void client_dispatch_attached(struct imsg *);
|
||||
static void client_dispatch_wait(struct imsg *, const char *);
|
||||
static const char *client_exit_message(void);
|
||||
|
||||
/*
|
||||
* Get server create lock. If already held then server start is happening in
|
||||
* another client, so block until the lock is released and return -2 to
|
||||
* retry. Return -1 on failure to continue and start the server anyway.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
client_get_lock(char *lockfile)
|
||||
{
|
||||
int lockfd;
|
||||
@@ -96,7 +98,7 @@ client_get_lock(char *lockfile)
|
||||
}
|
||||
|
||||
/* Connect client to server. */
|
||||
int
|
||||
static int
|
||||
client_connect(struct event_base *base, const char *path, int start_server)
|
||||
{
|
||||
struct sockaddr_un sa;
|
||||
@@ -249,16 +251,13 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
* flag.
|
||||
*/
|
||||
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
fprintf(stderr, "%s\n", cause);
|
||||
return (1);
|
||||
if (cmdlist != NULL) {
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||
cmdflags |= CMD_STARTSERVER;
|
||||
}
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
cmdflags &= ~CMD_STARTSERVER;
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||
cmdflags |= CMD_STARTSERVER;
|
||||
}
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
/* Create client process structure (starts logging). */
|
||||
@@ -287,7 +286,6 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||
ttynam = "";
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
/*
|
||||
* Drop privileges for client. "proc exec" is needed for -c and for
|
||||
* locking (which uses system(3)).
|
||||
@@ -299,9 +297,10 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
*/
|
||||
if (pledge("stdio unix sendfd proc exec tty", NULL) != 0)
|
||||
fatal("pledge failed");
|
||||
#endif
|
||||
|
||||
/* Free stuff that is not used in the client. */
|
||||
if (ptm_fd != -1)
|
||||
close(ptm_fd);
|
||||
options_free(global_options);
|
||||
options_free(global_s_options);
|
||||
options_free(global_w_options);
|
||||
@@ -312,8 +311,11 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
||||
client_stdin_callback, NULL);
|
||||
if (client_flags & CLIENT_CONTROLCONTROL) {
|
||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
||||
fprintf(stderr, "tcgetattr failed: %s\n",
|
||||
strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
cfmakeraw(&tio);
|
||||
tio.c_iflag = ICRNL|IXANY;
|
||||
tio.c_oflag = OPOST|ONLCR;
|
||||
@@ -361,6 +363,14 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
/* Start main loop. */
|
||||
proc_loop(client_proc, NULL);
|
||||
|
||||
/* Run command if user requested exec, instead of exiting. */
|
||||
if (client_exittype == MSG_EXEC) {
|
||||
if (client_flags & CLIENT_CONTROLCONTROL)
|
||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||
clear_signals(0);
|
||||
client_exec(client_execshell, client_execcmd);
|
||||
}
|
||||
|
||||
/* Print the exit message, if any, and exit. */
|
||||
if (client_attached) {
|
||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
||||
@@ -383,7 +393,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
}
|
||||
|
||||
/* Send identify messages to server. */
|
||||
void
|
||||
static void
|
||||
client_send_identify(const char *ttynam, const char *cwd)
|
||||
{
|
||||
const char *s;
|
||||
@@ -420,7 +430,7 @@ client_send_identify(const char *ttynam, const char *cwd)
|
||||
}
|
||||
|
||||
/* Callback for client stdin read events. */
|
||||
void
|
||||
static void
|
||||
client_stdin_callback(__unused int fd, __unused short events,
|
||||
__unused void *arg)
|
||||
{
|
||||
@@ -436,7 +446,7 @@ client_stdin_callback(__unused int fd, __unused short events,
|
||||
}
|
||||
|
||||
/* Force write to file descriptor. */
|
||||
void
|
||||
static void
|
||||
client_write(int fd, const char *data, size_t size)
|
||||
{
|
||||
ssize_t used;
|
||||
@@ -454,7 +464,7 @@ client_write(int fd, const char *data, size_t size)
|
||||
}
|
||||
|
||||
/* Run command in shell; used for -c. */
|
||||
__dead void
|
||||
static __dead void
|
||||
client_exec(const char *shell, const char *shellcmd)
|
||||
{
|
||||
const char *name, *ptr;
|
||||
@@ -483,7 +493,7 @@ client_exec(const char *shell, const char *shellcmd)
|
||||
}
|
||||
|
||||
/* Callback to handle signals in the client. */
|
||||
void
|
||||
static void
|
||||
client_signal(int sig)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
@@ -523,7 +533,7 @@ client_signal(int sig)
|
||||
}
|
||||
|
||||
/* Callback for client read events. */
|
||||
void
|
||||
static void
|
||||
client_dispatch(struct imsg *imsg, void *arg)
|
||||
{
|
||||
if (imsg == NULL) {
|
||||
@@ -540,7 +550,7 @@ client_dispatch(struct imsg *imsg, void *arg)
|
||||
}
|
||||
|
||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||
void
|
||||
static void
|
||||
client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
{
|
||||
char *data;
|
||||
@@ -548,7 +558,6 @@ client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
struct msg_stdout_data stdoutdata;
|
||||
struct msg_stderr_data stderrdata;
|
||||
int retval;
|
||||
#ifdef __OpenBSD__
|
||||
static int pledge_applied;
|
||||
|
||||
/*
|
||||
@@ -562,7 +571,6 @@ client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
fatal("pledge failed");
|
||||
pledge_applied = 1;
|
||||
};
|
||||
#endif
|
||||
|
||||
data = imsg->data;
|
||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||
@@ -636,7 +644,7 @@ client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
}
|
||||
|
||||
/* Dispatch imsgs in attached state (after MSG_READY). */
|
||||
void
|
||||
static void
|
||||
client_dispatch_attached(struct imsg *imsg)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
@@ -660,6 +668,16 @@ client_dispatch_attached(struct imsg *imsg)
|
||||
client_exitreason = CLIENT_EXIT_DETACHED;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXEC:
|
||||
if (datalen == 0 || data[datalen - 1] != '\0' ||
|
||||
strlen(data) + 1 == (size_t)datalen)
|
||||
fatalx("bad MSG_EXEC string");
|
||||
client_execcmd = xstrdup(data);
|
||||
client_execshell = xstrdup(data + strlen(data) + 1);
|
||||
|
||||
client_exittype = imsg->hdr.type;
|
||||
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
|
||||
break;
|
||||
case MSG_EXIT:
|
||||
if (datalen != 0 && datalen != sizeof (int))
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
* Attach existing session to the current terminal.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_attach_session_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_attach_session_entry = {
|
||||
.name = "attach-session",
|
||||
@@ -46,26 +47,24 @@ const struct cmd_entry cmd_attach_session_entry = {
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
int Eflag)
|
||||
cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
const char *cflag, int Eflag)
|
||||
{
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct client *c = cmdq->client, *c_loop;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
const char *update;
|
||||
char *cause, *cwd;
|
||||
struct format_tree *ft;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct client *c = item->client, *c_loop;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
char *cause;
|
||||
|
||||
if (RB_EMPTY(&sessions)) {
|
||||
cmdq_error(cmdq, "no sessions");
|
||||
cmdq_error(item, "no sessions");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (server_client_check_nested(c)) {
|
||||
cmdq_error(cmdq, "sessions should be nested with care, "
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -77,13 +76,8 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
}
|
||||
|
||||
if (cflag != NULL) {
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cwd = format_expand(ft, cflag);
|
||||
format_free(ft);
|
||||
|
||||
free((void *)s->cwd);
|
||||
s->cwd = cwd;
|
||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
||||
}
|
||||
|
||||
if (c->session != NULL) {
|
||||
@@ -94,28 +88,24 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
server_client_detach(c_loop, MSG_DETACH);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Eflag) {
|
||||
update = options_get_string(s->options,
|
||||
"update-environment");
|
||||
environ_update(update, c->environ, s->environ);
|
||||
}
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
c->session = s;
|
||||
server_client_set_key_table(c, NULL);
|
||||
if (!item->repeat)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
} else {
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (rflag)
|
||||
c->flags |= CLIENT_READONLY;
|
||||
|
||||
@@ -126,17 +116,13 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
server_client_detach(c_loop, MSG_DETACH);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Eflag) {
|
||||
update = options_get_string(s->options,
|
||||
"update-environment");
|
||||
environ_update(update, c->environ, s->environ);
|
||||
}
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
c->session = s;
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
@@ -144,8 +130,8 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
|
||||
if (~c->flags & CLIENT_CONTROL)
|
||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||
hooks_run(c->session->hooks, c, NULL, "client-attached");
|
||||
cmdq->client_exit = 0;
|
||||
notify_client("client-attached", c);
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
}
|
||||
recalculate_sizes();
|
||||
alerts_check_session(s);
|
||||
@@ -154,11 +140,11 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag,
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
return (cmd_attach_session(cmdq, args_has(args, 'd'),
|
||||
return (cmd_attach_session(item, args_has(args, 'd'),
|
||||
args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E')));
|
||||
}
|
||||
|
||||
113
cmd-bind-key.c
113
cmd-bind-key.c
@@ -24,28 +24,25 @@
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Bind a key to a command, this recurses through cmd_*.
|
||||
* Bind a key to a command.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *,
|
||||
key_code);
|
||||
static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
.name = "bind-key",
|
||||
.alias = "bind",
|
||||
|
||||
.args = { "cnrR:t:T:", 1, -1 },
|
||||
.usage = "[-cnr] [-t mode-table] [-R repeat-count] [-T key-table] key "
|
||||
.args = { "cnrT:", 2, -1 },
|
||||
.usage = "[-cnr] [-T key-table] key "
|
||||
"command [arguments]",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_bind_key_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
char *cause;
|
||||
@@ -53,27 +50,12 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
key_code key;
|
||||
const char *tablename;
|
||||
|
||||
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 || key == KEYC_UNKNOWN) {
|
||||
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_bind_key_mode_table(self, cmdq, key));
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
tablename = args_get(args, 'T');
|
||||
else if (args_has(args, 'n'))
|
||||
@@ -84,7 +66,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
|
||||
&cause);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -92,80 +74,3 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
key_bindings_add(tablename, key, args_has(args, 'r'), cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename, *arg;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
enum mode_key_cmd cmd;
|
||||
char *cause;
|
||||
u_int repeat;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
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) {
|
||||
cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case MODEKEYCOPY_APPENDSELECTION:
|
||||
case MODEKEYCOPY_COPYSELECTION:
|
||||
case MODEKEYCOPY_STARTNAMEDBUFFER:
|
||||
if (args->argc == 2)
|
||||
arg = NULL;
|
||||
else {
|
||||
arg = args->argv[2];
|
||||
if (strcmp(arg, "-x") != 0) {
|
||||
cmdq_error(cmdq, "unknown argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MODEKEYCOPY_COPYPIPE:
|
||||
if (args->argc != 3) {
|
||||
cmdq_error(cmdq, "no argument given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
arg = args->argv[2];
|
||||
break;
|
||||
default:
|
||||
if (args->argc != 2) {
|
||||
cmdq_error(cmdq, "no argument allowed");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
arg = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
repeat = 1;
|
||||
if (args_has(args, 'R')) {
|
||||
repeat = args_strtonum(args, 'R', 1, SHRT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "repeat count %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
mtmp.key = key;
|
||||
mtmp.mode = !!args_has(args, 'c');
|
||||
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->repeat = repeat;
|
||||
mbind->cmd = cmd;
|
||||
mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@
|
||||
|
||||
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
||||
|
||||
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_break_pane_entry = {
|
||||
.name = "break-pane",
|
||||
.alias = "breakp",
|
||||
|
||||
.args = { "dPF:s:t:", 0, 0 },
|
||||
.usage = "[-dP] [-F format] [-s src-pane] [-t dst-window]",
|
||||
.args = { "dPF:n:s:t:", 0, 0 },
|
||||
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] [-t dst-window]",
|
||||
|
||||
.sflag = CMD_PANE,
|
||||
.tflag = CMD_WINDOW_INDEX,
|
||||
@@ -44,29 +44,28 @@ const struct cmd_entry cmd_break_pane_entry = {
|
||||
.exec = cmd_break_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.sflag.wl;
|
||||
struct session *src_s = cmdq->state.sflag.s;
|
||||
struct session *dst_s = cmdq->state.tflag.s;
|
||||
struct window_pane *wp = cmdq->state.sflag.wp;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.sflag.wl;
|
||||
struct session *src_s = item->state.sflag.s;
|
||||
struct session *dst_s = item->state.tflag.s;
|
||||
struct window_pane *wp = item->state.sflag.wp;
|
||||
struct window *w = wl->window;
|
||||
char *name;
|
||||
char *cause;
|
||||
int idx = cmdq->state.tflag.idx;
|
||||
struct format_tree *ft;
|
||||
char *name, *cause;
|
||||
int idx = item->state.tflag.idx;
|
||||
const char *template;
|
||||
char *cp;
|
||||
|
||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
||||
cmdq_error(cmdq, "index %d already in use", idx);
|
||||
cmdq_error(item, "index %d already in use", idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (window_count_panes(w) == 1) {
|
||||
cmdq_error(cmdq, "can't break with only one pane");
|
||||
cmdq_error(item, "can't break with only one pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
@@ -75,12 +74,19 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
window_lost_pane(w, wp);
|
||||
layout_close_pane(wp);
|
||||
|
||||
w = wp->window = window_create1(dst_s->sx, dst_s->sy);
|
||||
w = wp->window = window_create(dst_s->sx, dst_s->sy);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
name = default_window_name(w);
|
||||
window_set_name(w, name);
|
||||
free(name);
|
||||
|
||||
if (!args_has(args, 'n')) {
|
||||
name = default_window_name(w);
|
||||
window_set_name(w, name);
|
||||
free(name);
|
||||
} else {
|
||||
window_set_name(w, args_get(args, 'n'));
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
}
|
||||
|
||||
layout_init(w, wp);
|
||||
wp->flags |= PANE_CHANGED;
|
||||
|
||||
@@ -100,15 +106,9 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, cmdq->state.c, dst_s, wl, wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
cp = format_single(item, template, c, dst_s, wl, wp);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
* Write the entire contents of a pane to a buffer or stdout.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
||||
char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
||||
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
|
||||
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
|
||||
size_t *);
|
||||
char *cmd_capture_pane_history(struct args *, struct cmd_q *,
|
||||
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
|
||||
struct window_pane *, size_t *);
|
||||
|
||||
const struct cmd_entry cmd_capture_pane_entry = {
|
||||
@@ -45,11 +45,24 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
};
|
||||
|
||||
char *
|
||||
const struct cmd_entry cmd_clear_history_entry = {
|
||||
.name = "clear-history",
|
||||
.alias = "clearhist",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
};
|
||||
|
||||
static char *
|
||||
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
||||
{
|
||||
buf = xrealloc(buf, *len + linelen + 1);
|
||||
@@ -58,7 +71,7 @@ cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
||||
size_t *len)
|
||||
{
|
||||
@@ -77,7 +90,7 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
||||
buf = xstrdup("");
|
||||
if (args_has(args, 'C')) {
|
||||
for (i = 0; i < linelen; i++) {
|
||||
if (line[i] >= ' ') {
|
||||
if (line[i] >= ' ' && line[i] != '\\') {
|
||||
tmp[0] = line[i];
|
||||
tmp[1] = '\0';
|
||||
} else
|
||||
@@ -90,8 +103,8 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
|
||||
static char *
|
||||
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
struct window_pane *wp, size_t *len)
|
||||
{
|
||||
struct grid *gd;
|
||||
@@ -108,7 +121,7 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
|
||||
gd = wp->saved_grid;
|
||||
if (gd == NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "no alternate screen");
|
||||
cmdq_error(item, "no alternate screen");
|
||||
return (NULL);
|
||||
}
|
||||
return (xstrdup(""));
|
||||
@@ -175,29 +188,36 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
|
||||
return (buf);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
char *buf, *cause;
|
||||
const char *bufname;
|
||||
size_t len;
|
||||
|
||||
if (self->entry == &cmd_clear_history_entry) {
|
||||
if (wp->mode == &window_copy_mode)
|
||||
window_pane_reset_mode(wp);
|
||||
grid_clear_history(wp->base.grid);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
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);
|
||||
buf = cmd_capture_pane_history(args, item, wp, &len);
|
||||
if (buf == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'p')) {
|
||||
c = cmdq->client;
|
||||
c = item->client;
|
||||
if (c == NULL ||
|
||||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) {
|
||||
cmdq_error(cmdq, "can't write to stdout");
|
||||
cmdq_error(item, "can't write to stdout");
|
||||
free(buf);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -212,7 +232,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
bufname = args_get(args, 'b');
|
||||
|
||||
if (paste_set(buf, len, bufname, &cause) != 0) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
free(buf);
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
#define CHOOSE_BUFFER_TEMPLATE \
|
||||
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
|
||||
|
||||
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_choose_buffer_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.name = "choose-buffer",
|
||||
@@ -45,12 +46,12 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.exec = cmd_choose_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_choose_data *cdata;
|
||||
struct paste_buffer *pb;
|
||||
char *action, *action_data;
|
||||
@@ -58,7 +59,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
u_int idx;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,15 @@
|
||||
*/
|
||||
|
||||
#define CHOOSE_CLIENT_TEMPLATE \
|
||||
"#{client_tty}: #{session_name} " \
|
||||
"#{client_name}: #{session_name} " \
|
||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
||||
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
|
||||
"(last used #{t:client_activity})"
|
||||
|
||||
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_choose_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
void cmd_choose_client_callback(struct window_choose_data *);
|
||||
static void cmd_choose_client_callback(struct window_choose_data *);
|
||||
|
||||
const struct cmd_entry cmd_choose_client_entry = {
|
||||
.name = "choose-client",
|
||||
@@ -54,20 +55,20 @@ struct cmd_choose_client_data {
|
||||
struct client *client;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c1;
|
||||
struct window_choose_data *cdata;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
const char *template;
|
||||
char *action;
|
||||
u_int idx, cur;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -84,9 +85,9 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
cur = idx = 0;
|
||||
TAILQ_FOREACH(c1, &clients, entry) {
|
||||
if (c1->session == NULL || c1->tty.path == NULL)
|
||||
if (c1->session == NULL)
|
||||
continue;
|
||||
if (c1 == cmdq->client)
|
||||
if (c1 == item->client)
|
||||
cur = idx;
|
||||
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
@@ -96,7 +97,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
format_add(cdata->ft, "line", "%u", idx);
|
||||
format_defaults(cdata->ft, c1, NULL, NULL, NULL);
|
||||
|
||||
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
|
||||
cdata->command = cmd_template_replace(action, c1->name, 1);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
|
||||
@@ -110,7 +111,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_choose_client_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
"#{window_index}: #{window_name}#{window_flags} " \
|
||||
"\"#{pane_title}\""
|
||||
|
||||
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_choose_tree_entry = {
|
||||
.name = "choose-tree",
|
||||
@@ -83,13 +83,13 @@ const struct cmd_entry cmd_choose_window_entry = {
|
||||
.exec = cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct winlink *wl = cmdq->state.tflag.wl, *wm;
|
||||
struct session *s = cmdq->state.tflag.s, *s2;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.tflag.wl, *wm;
|
||||
struct session *s = item->state.tflag.s, *s2;
|
||||
struct window_choose_data *wcd = NULL;
|
||||
const char *ses_template, *win_template;
|
||||
char *final_win_action, *cur_win_template;
|
||||
@@ -103,7 +103,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
ses_action = win_action = NULL;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,18 @@
|
||||
* Prompt for command in client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
int cmd_command_prompt_callback(void *, const char *);
|
||||
void cmd_command_prompt_free(void *);
|
||||
static int cmd_command_prompt_callback(void *, const char *, int);
|
||||
static void cmd_command_prompt_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_command_prompt_entry = {
|
||||
.name = "command-prompt",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "I:p:t:", 0, 1 },
|
||||
.usage = "[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
||||
.args = { "1iI:Np:t:", 0, 1 },
|
||||
.usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
||||
"[template]",
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
@@ -50,35 +51,42 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
struct client *c;
|
||||
int flags;
|
||||
|
||||
char *inputs;
|
||||
char *next_input;
|
||||
char *next_prompt;
|
||||
|
||||
char *prompts;
|
||||
char *next_prompt;
|
||||
|
||||
char *template;
|
||||
int idx;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *inputs, *prompts;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
char *prompt, *ptr, *input = NULL;
|
||||
size_t n;
|
||||
|
||||
if (c->prompt_string != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->c = c;
|
||||
cdata->idx = 1;
|
||||
|
||||
cdata->inputs = NULL;
|
||||
cdata->next_input = NULL;
|
||||
cdata->next_prompt = NULL;
|
||||
|
||||
cdata->prompts = NULL;
|
||||
cdata->next_prompt = NULL;
|
||||
|
||||
cdata->template = NULL;
|
||||
cdata->idx = 1;
|
||||
|
||||
if (args->argc != 0)
|
||||
cdata->template = xstrdup(args->argv[0]);
|
||||
@@ -108,34 +116,56 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
input = strsep(&cdata->next_input, ",");
|
||||
}
|
||||
|
||||
if (args_has(args, '1'))
|
||||
cdata->flags |= PROMPT_SINGLE;
|
||||
else if (args_has(args, 'N'))
|
||||
cdata->flags |= PROMPT_NUMERIC;
|
||||
else if (args_has(args, 'i'))
|
||||
cdata->flags |= PROMPT_INCREMENTAL;
|
||||
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
|
||||
cmd_command_prompt_free, cdata, 0);
|
||||
cmd_command_prompt_free, cdata, cdata->flags);
|
||||
free(prompt);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_command_prompt_callback(void *data, const char *s)
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_command_prompt_callback(void *data, const char *s, int done)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause, *new_template, *prompt, *ptr;
|
||||
char *input = NULL;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
if (done && (cdata->flags & PROMPT_INCREMENTAL))
|
||||
return (0);
|
||||
|
||||
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||
free(cdata->template);
|
||||
cdata->template = new_template;
|
||||
if (done) {
|
||||
free(cdata->template);
|
||||
cdata->template = new_template;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if there are more prompts; if so, get its respective input
|
||||
* and update the prompt data.
|
||||
*/
|
||||
if ((ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||
if (done && (ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||
xasprintf(&prompt, "%s ", ptr);
|
||||
input = strsep(&cdata->next_input, ",");
|
||||
status_prompt_update(c, prompt, input);
|
||||
@@ -145,24 +175,29 @@ cmd_command_prompt_callback(void *data, const char *s)
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(new_template, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (0);
|
||||
new_item = cmdq_get_callback(cmd_command_prompt_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
cmdq_run(c->cmdq, cmdlist, NULL);
|
||||
cmd_list_free(cmdlist);
|
||||
if (new_item != NULL)
|
||||
cmdq_append(c, new_item);
|
||||
|
||||
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
|
||||
if (!done)
|
||||
free(new_template);
|
||||
if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_command_prompt_free(void *data)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
|
||||
@@ -28,10 +28,11 @@
|
||||
* Asks for confirmation before executing a command.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
int cmd_confirm_before_callback(void *, const char *);
|
||||
void cmd_confirm_before_free(void *);
|
||||
static int cmd_confirm_before_callback(void *, const char *, int);
|
||||
static void cmd_confirm_before_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_confirm_before_entry = {
|
||||
.name = "confirm-before",
|
||||
@@ -51,12 +52,12 @@ struct cmd_confirm_before_data {
|
||||
struct client *client;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
char *cmd, *copy, *new_prompt, *ptr;
|
||||
const char *prompt;
|
||||
|
||||
@@ -83,12 +84,24 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_confirm_before_callback(void *data, const char *s)
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_confirm_before_callback(void *data, const char *s, __unused int done)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct client *c = cdata->client;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause;
|
||||
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
@@ -99,21 +112,25 @@ cmd_confirm_before_callback(void *data, const char *s)
|
||||
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
return (0);
|
||||
|
||||
if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(c->cmdq, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (0);
|
||||
new_item = cmdq_get_callback(cmd_confirm_before_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
cmdq_run(c->cmdq, cmdlist, NULL);
|
||||
cmd_list_free(cmdlist);
|
||||
if (new_item != NULL)
|
||||
cmdq_append(c, new_item);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Enter copy or clock mode.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_copy_mode_entry = {
|
||||
.name = "copy-mode",
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_copy_mode_exec
|
||||
};
|
||||
|
||||
@@ -48,20 +48,20 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_copy_mode_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->client;
|
||||
struct client *c = item->client;
|
||||
struct session *s;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if ((wp = cmd_mouse_pane(&cmdq->item->mouse, &s, NULL)) == NULL)
|
||||
if ((wp = cmd_mouse_pane(&item->mouse, &s, NULL)) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (c == NULL || c->session != s)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -80,7 +80,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'M')) {
|
||||
if (wp->mode != NULL && wp->mode != &window_copy_mode)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_start_drag(c, &cmdq->item->mouse);
|
||||
window_copy_start_drag(c, &item->mouse);
|
||||
}
|
||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
|
||||
@@ -26,14 +26,16 @@
|
||||
* Detach a client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_detach_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_detach_client_entry = {
|
||||
.name = "detach-client",
|
||||
.alias = "detach",
|
||||
|
||||
.args = { "as:t:P", 0, 0 },
|
||||
.usage = "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
.args = { "aE:s:t:P", 0, 0 },
|
||||
.usage = "[-aP] [-E shell-command] "
|
||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.sflag = CMD_SESSION,
|
||||
.tflag = CMD_CLIENT,
|
||||
@@ -55,13 +57,14 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
||||
.exec = cmd_detach_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c, *cloop;
|
||||
struct client *c = item->state.c, *cloop;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
const char *cmd = args_get(args, 'E');
|
||||
|
||||
if (self->entry == &cmd_suspend_client_entry) {
|
||||
tty_stop_tty(&c->tty);
|
||||
@@ -76,22 +79,33 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
msgtype = MSG_DETACH;
|
||||
|
||||
if (args_has(args, 's')) {
|
||||
s = cmdq->state.sflag.s;
|
||||
s = item->state.sflag.s;
|
||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
||||
if (cloop->session == s)
|
||||
server_client_detach(cloop, msgtype);
|
||||
if (cloop->session == s) {
|
||||
if (cmd != NULL)
|
||||
server_client_exec(cloop, cmd);
|
||||
else
|
||||
server_client_detach(cloop, msgtype);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_STOP);
|
||||
}
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
||||
if (cloop->session != NULL && cloop != c)
|
||||
server_client_detach(cloop, msgtype);
|
||||
if (cloop->session != NULL && cloop != c) {
|
||||
if (cmd != NULL)
|
||||
server_client_exec(cloop, cmd);
|
||||
else
|
||||
server_client_detach(cloop, msgtype);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
server_client_detach(c, msgtype);
|
||||
if (cmd != NULL)
|
||||
server_client_exec(c, cmd);
|
||||
else
|
||||
server_client_detach(c, msgtype);
|
||||
return (CMD_RETURN_STOP);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
"#{window_name}, current pane #{pane_index} " \
|
||||
"- (%H:%M %d-%b-%y)"
|
||||
|
||||
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_display_message_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_message_entry = {
|
||||
.name = "display-message",
|
||||
@@ -45,24 +46,24 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.cflag = CMD_CLIENT_CANFAIL,
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_message_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
const char *template;
|
||||
char *msg;
|
||||
struct format_tree *ft;
|
||||
|
||||
if (args_has(args, 'F') && args->argc != 0) {
|
||||
cmdq_error(cmdq, "only one of -F or argument must be given");
|
||||
cmdq_error(item, "only one of -F or argument must be given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -72,12 +73,12 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (template == NULL)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
msg = format_expand_time(ft, template, time(NULL));
|
||||
if (args_has(self->args, 'p'))
|
||||
cmdq_print(cmdq, "%s", msg);
|
||||
cmdq_print(item, "%s", msg);
|
||||
else if (c != NULL)
|
||||
status_message_set(c, "%s", msg);
|
||||
free(msg);
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
* Display panes on a client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_display_panes_callback(struct client *,
|
||||
struct window_pane *);
|
||||
static void cmd_display_panes_callback(struct client *,
|
||||
struct window_pane *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
.name = "display-panes",
|
||||
@@ -41,15 +42,15 @@ const struct cmd_entry cmd_display_panes_entry = {
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_panes_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
|
||||
if (c->identify_callback != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -60,7 +61,18 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else
|
||||
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
||||
|
||||
server_set_identify(c);
|
||||
server_client_set_identify(c);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -68,29 +80,35 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static void
|
||||
cmd_display_panes_callback(struct client *c, struct window_pane *wp)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
char *template, *cmd, *expanded, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *template, *cmd, *expanded, *cause;
|
||||
|
||||
template = c->identify_callback_data;
|
||||
if (wp != NULL) {
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(template, expanded, 1);
|
||||
if (wp == NULL)
|
||||
goto out;
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(template, expanded, 1);
|
||||
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
*cause = toupper((u_char) *cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
} else {
|
||||
cmdq_run(c->cmdq, cmdlist, NULL);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_display_panes_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
if (new_item != NULL)
|
||||
cmdq_append(c, new_item);
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
|
||||
out:
|
||||
free(c->identify_callback_data);
|
||||
c->identify_callback_data = NULL;
|
||||
c->identify_callback = NULL;
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
"[#{window_width}x#{window_height}] " \
|
||||
"(#{window_panes} panes) #{window_find_matches}"
|
||||
|
||||
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_find_window_callback(struct window_choose_data *);
|
||||
static void cmd_find_window_callback(struct window_choose_data *);
|
||||
|
||||
/* Flags for determining matching behavior. */
|
||||
#define CMD_FIND_WINDOW_BY_TITLE 0x1
|
||||
@@ -68,11 +68,11 @@ struct cmd_find_window_data {
|
||||
};
|
||||
TAILQ_HEAD(cmd_find_window_list, cmd_find_window_data);
|
||||
|
||||
u_int cmd_find_window_match_flags(struct args *);
|
||||
void cmd_find_window_match(struct cmd_find_window_list *, int,
|
||||
struct winlink *, const char *, const char *);
|
||||
static u_int cmd_find_window_match_flags(struct args *);
|
||||
static void cmd_find_window_match(struct cmd_find_window_list *, int,
|
||||
struct winlink *, const char *, const char *);
|
||||
|
||||
u_int
|
||||
static u_int
|
||||
cmd_find_window_match_flags(struct args *args)
|
||||
{
|
||||
u_int match_flags = 0;
|
||||
@@ -92,7 +92,7 @@ cmd_find_window_match_flags(struct args *args)
|
||||
return (match_flags);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_find_window_match(struct cmd_find_window_list *find_list,
|
||||
int match_flags, struct winlink *wl, const char *str,
|
||||
const char *searchstr)
|
||||
@@ -138,14 +138,14 @@ cmd_find_window_match(struct cmd_find_window_list *find_list,
|
||||
free(find_data);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
struct window_choose_data *cdata;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl, *wm;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl, *wm;
|
||||
struct cmd_find_window_list find_list;
|
||||
struct cmd_find_window_data *find_data;
|
||||
struct cmd_find_window_data *find_data1;
|
||||
@@ -154,7 +154,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
u_int i, match_flags;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(cmdq, "no client available");
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
free(searchstr);
|
||||
|
||||
if (TAILQ_EMPTY(&find_list)) {
|
||||
cmdq_error(cmdq, "no windows matching: %s", str);
|
||||
cmdq_error(item, "no windows matching: %s", str);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ out:
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_find_window_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
280
cmd-find.c
280
cmd-find.c
@@ -26,33 +26,35 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct session *cmd_find_try_TMUX(struct client *, struct window *);
|
||||
int cmd_find_client_better(struct client *, struct client *);
|
||||
struct client *cmd_find_best_client(struct client **, u_int);
|
||||
int cmd_find_session_better(struct session *, struct session *,
|
||||
int);
|
||||
struct session *cmd_find_best_session(struct session **, u_int, int);
|
||||
int cmd_find_best_session_with_window(struct cmd_find_state *);
|
||||
int cmd_find_best_winlink_with_window(struct cmd_find_state *);
|
||||
static struct session *cmd_find_try_TMUX(struct client *, struct window *);
|
||||
static int cmd_find_client_better(struct client *, struct client *);
|
||||
static struct client *cmd_find_best_client(struct client **, u_int);
|
||||
static int cmd_find_session_better(struct session *, struct session *,
|
||||
int);
|
||||
static struct session *cmd_find_best_session(struct session **, u_int, int);
|
||||
static int cmd_find_best_session_with_window(struct cmd_find_state *);
|
||||
static int cmd_find_best_winlink_with_window(struct cmd_find_state *);
|
||||
|
||||
int cmd_find_current_session_with_client(struct cmd_find_state *);
|
||||
int cmd_find_current_session(struct cmd_find_state *);
|
||||
struct client *cmd_find_current_client(struct cmd_q *);
|
||||
static int cmd_find_current_session_with_client(struct cmd_find_state *);
|
||||
static int cmd_find_current_session(struct cmd_find_state *);
|
||||
static struct client *cmd_find_current_client(struct cmdq_item *);
|
||||
|
||||
const char *cmd_find_map_table(const char *[][2], const char *);
|
||||
static const char *cmd_find_map_table(const char *[][2], const char *);
|
||||
|
||||
int cmd_find_get_session(struct cmd_find_state *, const char *);
|
||||
int cmd_find_get_window(struct cmd_find_state *, const char *);
|
||||
int cmd_find_get_window_with_session(struct cmd_find_state *, const char *);
|
||||
int cmd_find_get_window_with_pane(struct cmd_find_state *);
|
||||
int cmd_find_get_pane(struct cmd_find_state *, const char *);
|
||||
int cmd_find_get_pane_with_session(struct cmd_find_state *, const char *);
|
||||
int cmd_find_get_pane_with_window(struct cmd_find_state *, const char *);
|
||||
static int cmd_find_get_session(struct cmd_find_state *, const char *);
|
||||
static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
|
||||
static int cmd_find_get_window_with_session(struct cmd_find_state *,
|
||||
const char *);
|
||||
static int cmd_find_get_pane(struct cmd_find_state *, const char *, int);
|
||||
static int cmd_find_get_pane_with_session(struct cmd_find_state *,
|
||||
const char *);
|
||||
static int cmd_find_get_pane_with_window(struct cmd_find_state *,
|
||||
const char *);
|
||||
|
||||
const char *cmd_find_session_table[][2] = {
|
||||
static const char *cmd_find_session_table[][2] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
const char *cmd_find_window_table[][2] = {
|
||||
static const char *cmd_find_window_table[][2] = {
|
||||
{ "{start}", "^" },
|
||||
{ "{last}", "!" },
|
||||
{ "{end}", "$" },
|
||||
@@ -60,7 +62,7 @@ const char *cmd_find_window_table[][2] = {
|
||||
{ "{previous}", "-" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
const char *cmd_find_pane_table[][2] = {
|
||||
static const char *cmd_find_pane_table[][2] = {
|
||||
{ "{last}", "!" },
|
||||
{ "{next}", "+" },
|
||||
{ "{previous}", "-" },
|
||||
@@ -80,7 +82,7 @@ const char *cmd_find_pane_table[][2] = {
|
||||
};
|
||||
|
||||
/* Get session from TMUX if present. */
|
||||
struct session *
|
||||
static struct session *
|
||||
cmd_find_try_TMUX(struct client *c, struct window *w)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
@@ -107,7 +109,7 @@ cmd_find_try_TMUX(struct client *c, struct window *w)
|
||||
}
|
||||
|
||||
/* Is this client better? */
|
||||
int
|
||||
static int
|
||||
cmd_find_client_better(struct client *c, struct client *than)
|
||||
{
|
||||
if (than == NULL)
|
||||
@@ -116,7 +118,7 @@ cmd_find_client_better(struct client *c, struct client *than)
|
||||
}
|
||||
|
||||
/* Find best client from a list, or all if list is NULL. */
|
||||
struct client *
|
||||
static struct client *
|
||||
cmd_find_best_client(struct client **clist, u_int csize)
|
||||
{
|
||||
struct client *c_loop, *c;
|
||||
@@ -142,7 +144,7 @@ cmd_find_best_client(struct client **clist, u_int csize)
|
||||
}
|
||||
|
||||
/* Is this session better? */
|
||||
int
|
||||
static int
|
||||
cmd_find_session_better(struct session *s, struct session *than, int flags)
|
||||
{
|
||||
int attached;
|
||||
@@ -160,7 +162,7 @@ cmd_find_session_better(struct session *s, struct session *than, int flags)
|
||||
}
|
||||
|
||||
/* Find best session from a list, or all if list is NULL. */
|
||||
struct session *
|
||||
static struct session *
|
||||
cmd_find_best_session(struct session **slist, u_int ssize, int flags)
|
||||
{
|
||||
struct session *s_loop, *s;
|
||||
@@ -182,15 +184,15 @@ cmd_find_best_session(struct session **slist, u_int ssize, int flags)
|
||||
}
|
||||
|
||||
/* Find best session and winlink for window. */
|
||||
int
|
||||
static int
|
||||
cmd_find_best_session_with_window(struct cmd_find_state *fs)
|
||||
{
|
||||
struct session **slist = NULL;
|
||||
u_int ssize;
|
||||
struct session *s;
|
||||
|
||||
if (fs->cmdq != NULL && fs->cmdq->client != NULL) {
|
||||
fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w);
|
||||
if (fs->item != NULL && fs->item->client != NULL) {
|
||||
fs->s = cmd_find_try_TMUX(fs->item->client, fs->w);
|
||||
if (fs->s != NULL)
|
||||
return (cmd_find_best_winlink_with_window(fs));
|
||||
}
|
||||
@@ -219,13 +221,13 @@ fail:
|
||||
* Find the best winlink for a window (the current if it contains the pane,
|
||||
* otherwise the first).
|
||||
*/
|
||||
int
|
||||
static int
|
||||
cmd_find_best_winlink_with_window(struct cmd_find_state *fs)
|
||||
{
|
||||
struct winlink *wl, *wl_loop;
|
||||
|
||||
wl = NULL;
|
||||
if (fs->s->curw->window == fs->w)
|
||||
if (fs->s->curw != NULL && fs->s->curw->window == fs->w)
|
||||
wl = fs->s->curw;
|
||||
else {
|
||||
RB_FOREACH(wl_loop, winlinks, &fs->s->windows) {
|
||||
@@ -243,7 +245,7 @@ cmd_find_best_winlink_with_window(struct cmd_find_state *fs)
|
||||
}
|
||||
|
||||
/* Find current session when we have an unattached client. */
|
||||
int
|
||||
static int
|
||||
cmd_find_current_session_with_client(struct cmd_find_state *fs)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
@@ -253,9 +255,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
|
||||
* sessions to those containing that pane (we still use the current
|
||||
* window in the best session).
|
||||
*/
|
||||
if (fs->cmdq != NULL && fs->cmdq->client->tty.path != NULL) {
|
||||
if (fs->item != NULL) {
|
||||
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
||||
if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0)
|
||||
if (strcmp(wp->tty, fs->item->client->ttyname) == 0)
|
||||
break;
|
||||
}
|
||||
} else
|
||||
@@ -289,8 +291,8 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
|
||||
|
||||
unknown_pane:
|
||||
fs->s = NULL;
|
||||
if (fs->cmdq != NULL)
|
||||
fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL);
|
||||
if (fs->item != NULL)
|
||||
fs->s = cmd_find_try_TMUX(fs->item->client, NULL);
|
||||
if (fs->s == NULL)
|
||||
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
|
||||
if (fs->s == NULL)
|
||||
@@ -307,16 +309,16 @@ unknown_pane:
|
||||
* Work out the best current state. If this function succeeds, the state is
|
||||
* guaranteed to be completely filled in.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
cmd_find_current_session(struct cmd_find_state *fs)
|
||||
{
|
||||
/* If we know the current client, use it. */
|
||||
if (fs->cmdq != NULL && fs->cmdq->client != NULL) {
|
||||
log_debug("%s: have client %p%s", __func__, fs->cmdq->client,
|
||||
fs->cmdq->client->session == NULL ? "" : " (with session)");
|
||||
if (fs->cmdq->client->session == NULL)
|
||||
if (fs->item != NULL && fs->item->client != NULL) {
|
||||
log_debug("%s: have client %p%s", __func__, fs->item->client,
|
||||
fs->item->client->session == NULL ? "" : " (with session)");
|
||||
if (fs->item->client->session == NULL)
|
||||
return (cmd_find_current_session_with_client(fs));
|
||||
fs->s = fs->cmdq->client->session;
|
||||
fs->s = fs->item->client->session;
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
@@ -337,8 +339,8 @@ cmd_find_current_session(struct cmd_find_state *fs)
|
||||
}
|
||||
|
||||
/* Work out the best current client. */
|
||||
struct client *
|
||||
cmd_find_current_client(struct cmd_q *cmdq)
|
||||
static struct client *
|
||||
cmd_find_current_client(struct cmdq_item *item)
|
||||
{
|
||||
struct cmd_find_state current;
|
||||
struct session *s;
|
||||
@@ -346,14 +348,14 @@ cmd_find_current_client(struct cmd_q *cmdq)
|
||||
u_int csize;
|
||||
|
||||
/* If the queue client has a session, use it. */
|
||||
if (cmdq->client != NULL && cmdq->client->session != NULL) {
|
||||
log_debug("%s: using cmdq %p client %p", __func__, cmdq,
|
||||
cmdq->client);
|
||||
return (cmdq->client);
|
||||
if (item->client != NULL && item->client->session != NULL) {
|
||||
log_debug("%s: using item %p client %p", __func__, item,
|
||||
item->client);
|
||||
return (item->client);
|
||||
}
|
||||
|
||||
/* Otherwise find the current session. */
|
||||
cmd_find_clear_state(¤t, cmdq, 0);
|
||||
cmd_find_clear_state(¤t, item, 0);
|
||||
if (cmd_find_current_session(¤t) != 0)
|
||||
return (NULL);
|
||||
|
||||
@@ -383,7 +385,7 @@ cmd_find_current_client(struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
/* Maps string in table. */
|
||||
const char *
|
||||
static const char *
|
||||
cmd_find_map_table(const char *table[][2], const char *s)
|
||||
{
|
||||
u_int i;
|
||||
@@ -396,7 +398,7 @@ cmd_find_map_table(const char *table[][2], const char *s)
|
||||
}
|
||||
|
||||
/* Find session from string. Fills in s. */
|
||||
int
|
||||
static int
|
||||
cmd_find_get_session(struct cmd_find_state *fs, const char *session)
|
||||
{
|
||||
struct session *s, *s_loop;
|
||||
@@ -460,8 +462,8 @@ cmd_find_get_session(struct cmd_find_state *fs, const char *session)
|
||||
}
|
||||
|
||||
/* Find window from string. Fills in s, wl, w. */
|
||||
int
|
||||
cmd_find_get_window(struct cmd_find_state *fs, const char *window)
|
||||
static int
|
||||
cmd_find_get_window(struct cmd_find_state *fs, const char *window, int only)
|
||||
{
|
||||
log_debug("%s: %s", __func__, window);
|
||||
|
||||
@@ -481,7 +483,7 @@ cmd_find_get_window(struct cmd_find_state *fs, const char *window)
|
||||
return (0);
|
||||
|
||||
/* Otherwise try as a session itself. */
|
||||
if (cmd_find_get_session(fs, window) == 0) {
|
||||
if (!only && cmd_find_get_session(fs, window) == 0) {
|
||||
fs->wl = fs->s->curw;
|
||||
fs->w = fs->wl->window;
|
||||
if (~fs->flags & CMD_FIND_WINDOW_INDEX)
|
||||
@@ -496,7 +498,7 @@ cmd_find_get_window(struct cmd_find_state *fs, const char *window)
|
||||
* Find window from string, assuming it is in given session. Needs s, fills in
|
||||
* wl and w.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
||||
{
|
||||
struct winlink *wl;
|
||||
@@ -646,26 +648,16 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Find window from given pane. Needs wp, fills in s and wl and w. */
|
||||
int
|
||||
cmd_find_get_window_with_pane(struct cmd_find_state *fs)
|
||||
{
|
||||
log_debug("%s", __func__);
|
||||
|
||||
fs->w = fs->wp->window;
|
||||
return (cmd_find_best_session_with_window(fs));
|
||||
}
|
||||
|
||||
/* Find pane from string. Fills in s, wl, w, wp. */
|
||||
int
|
||||
cmd_find_get_pane(struct cmd_find_state *fs, const char *pane)
|
||||
static int
|
||||
cmd_find_get_pane(struct cmd_find_state *fs, const char *pane, int only)
|
||||
{
|
||||
log_debug("%s: %s", __func__, pane);
|
||||
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
fs->w = fs->wp->window;
|
||||
return (cmd_find_best_session_with_window(fs));
|
||||
@@ -682,7 +674,7 @@ cmd_find_get_pane(struct cmd_find_state *fs, const char *pane)
|
||||
return (0);
|
||||
|
||||
/* Otherwise try as a window itself (this will also try as session). */
|
||||
if (cmd_find_get_window(fs, pane) == 0) {
|
||||
if (!only && cmd_find_get_window(fs, pane, 0) == 0) {
|
||||
fs->wp = fs->w->active;
|
||||
return (0);
|
||||
}
|
||||
@@ -694,7 +686,7 @@ cmd_find_get_pane(struct cmd_find_state *fs, const char *pane)
|
||||
* Find pane from string, assuming it is in given session. Needs s, fills in wl
|
||||
* and w and wp.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane)
|
||||
{
|
||||
log_debug("%s: %s", __func__, pane);
|
||||
@@ -702,7 +694,7 @@ cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane)
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
fs->w = fs->wp->window;
|
||||
return (cmd_find_best_winlink_with_window(fs));
|
||||
@@ -721,7 +713,7 @@ cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane)
|
||||
* Find pane from string, assuming it is in the given window. Needs w, fills in
|
||||
* wp.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
{
|
||||
const char *errstr;
|
||||
@@ -734,7 +726,9 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL || fs->wp->window != fs->w)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
if (fs->wp->window != fs->w)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
@@ -744,25 +738,27 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
if (fs->w->last == NULL)
|
||||
return (-1);
|
||||
fs->wp = fs->w->last;
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{up-of}") == 0) {
|
||||
fs->wp = window_pane_find_up(fs->w->active);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{down-of}") == 0) {
|
||||
fs->wp = window_pane_find_down(fs->w->active);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{left-of}") == 0) {
|
||||
fs->wp = window_pane_find_left(fs->w->active);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{right-of}") == 0) {
|
||||
fs->wp = window_pane_find_right(fs->w->active);
|
||||
if (fs->wp == NULL)
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
@@ -778,7 +774,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
fs->wp = window_pane_next_by_number(fs->w, wp, n);
|
||||
else
|
||||
fs->wp = window_pane_previous_by_number(fs->w, wp, n);
|
||||
if (fs->wp != NULL)
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -786,13 +782,13 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
idx = strtonum(pane, 0, INT_MAX, &errstr);
|
||||
if (errstr == NULL) {
|
||||
fs->wp = window_pane_at_index(fs->w, idx);
|
||||
if (fs->wp != NULL)
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Try as a description. */
|
||||
fs->wp = window_find_string(fs->w, pane);
|
||||
if (fs->wp != NULL)
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
@@ -800,16 +796,26 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
|
||||
/* Clear state. */
|
||||
void
|
||||
cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
|
||||
cmd_find_clear_state(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
int flags)
|
||||
{
|
||||
memset(fs, 0, sizeof *fs);
|
||||
|
||||
fs->cmdq = cmdq;
|
||||
fs->item = item;
|
||||
fs->flags = flags;
|
||||
|
||||
fs->idx = -1;
|
||||
}
|
||||
|
||||
/* Check if state is empty/ */
|
||||
int
|
||||
cmd_find_empty_state(struct cmd_find_state *fs)
|
||||
{
|
||||
if (fs->s == NULL && fs->wl == NULL && fs->w == NULL && fs->wp == NULL)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Check if a state if valid. */
|
||||
int
|
||||
cmd_find_valid_state(struct cmd_find_state *fs)
|
||||
@@ -834,7 +840,7 @@ cmd_find_valid_state(struct cmd_find_state *fs)
|
||||
|
||||
if (!window_has_pane(fs->w, fs->wp))
|
||||
return (0);
|
||||
return (window_pane_visible(fs->wp));
|
||||
return (!window_pane_outside(fs->wp));
|
||||
}
|
||||
|
||||
/* Copy a state. */
|
||||
@@ -902,6 +908,23 @@ cmd_find_from_winlink(struct cmd_find_state *fs, struct session *s,
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from a session and window. */
|
||||
int
|
||||
cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s,
|
||||
struct window *w)
|
||||
{
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
|
||||
fs->s = s;
|
||||
fs->w = w;
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0)
|
||||
return (-1);
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from a window. */
|
||||
int
|
||||
cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
|
||||
@@ -913,6 +936,7 @@ cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
|
||||
return (-1);
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0)
|
||||
return (-1);
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
@@ -924,6 +948,8 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
|
||||
{
|
||||
if (cmd_find_from_window(fs, wp->window) != 0)
|
||||
return (-1);
|
||||
if (window_pane_outside(wp))
|
||||
return (-1);
|
||||
fs->wp = wp;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
@@ -932,12 +958,12 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
|
||||
|
||||
/* Find current state. */
|
||||
int
|
||||
cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
|
||||
cmd_find_current(struct cmd_find_state *fs, struct cmdq_item *item, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, cmdq, flags);
|
||||
cmd_find_clear_state(fs, item, flags);
|
||||
if (cmd_find_current_session(fs) != 0) {
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "no current session");
|
||||
cmdq_error(item, "no current session");
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
@@ -949,29 +975,38 @@ cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
|
||||
*/
|
||||
int
|
||||
cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
struct cmd_q *cmdq, const char *target, enum cmd_find_type type, int flags)
|
||||
struct cmdq_item *item, const char *target, enum cmd_find_type type,
|
||||
int flags)
|
||||
{
|
||||
struct mouse_event *m;
|
||||
char *colon, *period, *copy = NULL;
|
||||
const char *session, *window, *pane;
|
||||
int window_only = 0, pane_only = 0;
|
||||
|
||||
/* Log the arguments. */
|
||||
if (target == NULL)
|
||||
log_debug("%s: target none, type %d", __func__, type);
|
||||
else
|
||||
log_debug("%s: target %s, type %d", __func__, target, type);
|
||||
log_debug("%s: cmdq %p, flags %#x", __func__, cmdq, flags);
|
||||
log_debug("%s: item %p, flags %#x", __func__, item, flags);
|
||||
|
||||
/* Clear new state. */
|
||||
cmd_find_clear_state(fs, cmdq, flags);
|
||||
cmd_find_clear_state(fs, item, flags);
|
||||
|
||||
/* Find current state. */
|
||||
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED))
|
||||
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
|
||||
fs->current = &marked_pane;
|
||||
else if (cmd_find_valid_state(&cmdq->current))
|
||||
fs->current = &cmdq->current;
|
||||
else
|
||||
log_debug("%s: current is marked pane", __func__);
|
||||
} else if (cmd_find_valid_state(&item->current)) {
|
||||
fs->current = &item->current;
|
||||
log_debug("%s: current is from queue", __func__);
|
||||
} else {
|
||||
fs->current = current;
|
||||
log_debug("%s: current is from argument", __func__);
|
||||
}
|
||||
if (!cmd_find_empty_state(fs->current) &&
|
||||
!cmd_find_valid_state(fs->current))
|
||||
fatalx("invalid current find state");
|
||||
|
||||
/* An empty or NULL target is the current. */
|
||||
if (target == NULL || *target == '\0')
|
||||
@@ -979,11 +1014,11 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
|
||||
/* Mouse target is a plain = or {mouse}. */
|
||||
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
|
||||
m = &cmdq->item->mouse;
|
||||
m = &item->mouse;
|
||||
switch (type) {
|
||||
case CMD_FIND_PANE:
|
||||
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
|
||||
if (fs->wp != NULL)
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
fs->w = fs->wl->window;
|
||||
break;
|
||||
case CMD_FIND_WINDOW:
|
||||
@@ -997,7 +1032,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
}
|
||||
if (fs->wp == NULL) {
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "no mouse target");
|
||||
cmdq_error(item, "no mouse target");
|
||||
goto error;
|
||||
}
|
||||
goto found;
|
||||
@@ -1007,7 +1042,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
if (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) {
|
||||
if (!server_check_marked()) {
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "no marked target");
|
||||
cmdq_error(item, "no marked target");
|
||||
goto error;
|
||||
}
|
||||
cmd_find_copy_state(fs, &marked_pane);
|
||||
@@ -1031,13 +1066,17 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
if (colon != NULL && period != NULL) {
|
||||
session = copy;
|
||||
window = colon;
|
||||
window_only = 1;
|
||||
pane = period;
|
||||
pane_only = 1;
|
||||
} else if (colon != NULL && period == NULL) {
|
||||
session = copy;
|
||||
window = colon;
|
||||
window_only = 1;
|
||||
} else if (colon == NULL && period != NULL) {
|
||||
window = copy;
|
||||
pane = period;
|
||||
pane_only = 1;
|
||||
} else {
|
||||
if (*copy == '$')
|
||||
session = copy;
|
||||
@@ -1093,7 +1132,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* No pane is allowed if want an index. */
|
||||
if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) {
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "can't specify pane here");
|
||||
cmdq_error(item, "can't specify pane here");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -1144,7 +1183,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* No session. If window and pane, try them. */
|
||||
if (window != NULL && pane != NULL) {
|
||||
/* This will fill in session, winlink and window. */
|
||||
if (cmd_find_get_window(fs, window) != 0)
|
||||
if (cmd_find_get_window(fs, window, window_only) != 0)
|
||||
goto no_window;
|
||||
/* This will fill in pane. */
|
||||
if (cmd_find_get_pane_with_window(fs, pane) != 0)
|
||||
@@ -1155,7 +1194,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* If just window is present, try it. */
|
||||
if (window != NULL && pane == NULL) {
|
||||
/* This will fill in session, winlink and window. */
|
||||
if (cmd_find_get_window(fs, window) != 0)
|
||||
if (cmd_find_get_window(fs, window, window_only) != 0)
|
||||
goto no_window;
|
||||
fs->wp = fs->wl->window->active;
|
||||
goto found;
|
||||
@@ -1164,7 +1203,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* If just pane is present, try it. */
|
||||
if (window == NULL && pane != NULL) {
|
||||
/* This will fill in session, winlink, window and pane. */
|
||||
if (cmd_find_get_pane(fs, pane) != 0)
|
||||
if (cmd_find_get_pane(fs, pane, pane_only) != 0)
|
||||
goto no_pane;
|
||||
goto found;
|
||||
}
|
||||
@@ -1178,7 +1217,7 @@ current:
|
||||
|
||||
error:
|
||||
fs->current = NULL;
|
||||
log_debug(" error");
|
||||
log_debug("%s: error", __func__);
|
||||
|
||||
free(copy);
|
||||
return (-1);
|
||||
@@ -1192,34 +1231,33 @@ found:
|
||||
|
||||
no_session:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "can't find session %s", session);
|
||||
cmdq_error(item, "can't find session %s", session);
|
||||
goto error;
|
||||
|
||||
no_window:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "can't find window %s", window);
|
||||
cmdq_error(item, "can't find window %s", window);
|
||||
goto error;
|
||||
|
||||
no_pane:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(cmdq, "can't find pane %s", pane);
|
||||
cmdq_error(item, "can't find pane %s", pane);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Find the target client or report an error and return NULL. */
|
||||
struct client *
|
||||
cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
|
||||
cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
|
||||
{
|
||||
struct client *c;
|
||||
char *copy;
|
||||
size_t size;
|
||||
const char *path;
|
||||
|
||||
/* A NULL argument means the current client. */
|
||||
if (cmdq != NULL && target == NULL) {
|
||||
c = cmd_find_current_client(cmdq);
|
||||
if (item != NULL && target == NULL) {
|
||||
c = cmd_find_current_client(item);
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(cmdq, "no current client");
|
||||
cmdq_error(item, "no current client");
|
||||
log_debug("%s: no target, return %p", __func__, c);
|
||||
return (c);
|
||||
}
|
||||
@@ -1230,26 +1268,26 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
|
||||
if (size != 0 && copy[size - 1] == ':')
|
||||
copy[size - 1] = '\0';
|
||||
|
||||
/* Check path of each client. */
|
||||
/* Check name and path of each client. */
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == NULL || c->tty.path == NULL)
|
||||
if (c->session == NULL)
|
||||
continue;
|
||||
path = c->tty.path;
|
||||
|
||||
/* Try for exact match. */
|
||||
if (strcmp(copy, path) == 0)
|
||||
if (strcmp(copy, c->name) == 0)
|
||||
break;
|
||||
|
||||
/* Try without leading /dev. */
|
||||
if (strncmp(path, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
|
||||
if (*c->ttyname == '\0')
|
||||
continue;
|
||||
if (strcmp(copy, path + (sizeof _PATH_DEV) - 1) == 0)
|
||||
if (strcmp(copy, c->ttyname) == 0)
|
||||
break;
|
||||
if (strncmp(c->ttyname, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
|
||||
continue;
|
||||
if (strcmp(copy, c->ttyname + (sizeof _PATH_DEV) - 1) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If no client found, report an error. */
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(cmdq, "can't find client %s", copy);
|
||||
cmdq_error(item, "can't find client %s", copy);
|
||||
|
||||
free(copy);
|
||||
log_debug("%s: target %s, return %p", __func__, target, c);
|
||||
|
||||
155
cmd-if-shell.c
155
cmd-if-shell.c
@@ -29,11 +29,11 @@
|
||||
* Executes a tmux command if a shell command returns true or false.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_if_shell_callback(struct job *);
|
||||
void cmd_if_shell_done(struct cmd_q *);
|
||||
void cmd_if_shell_free(void *);
|
||||
static enum cmd_retval cmd_if_shell_error(struct cmdq_item *, void *);
|
||||
static void cmd_if_shell_callback(struct job *);
|
||||
static void cmd_if_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_if_shell_entry = {
|
||||
.name = "if-shell",
|
||||
@@ -50,41 +50,39 @@ const struct cmd_entry cmd_if_shell_entry = {
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
char *file;
|
||||
u_int line;
|
||||
|
||||
char *cmd_if;
|
||||
char *cmd_else;
|
||||
|
||||
struct cmd_q *cmdq;
|
||||
struct client *client;
|
||||
struct cmdq_item *item;
|
||||
struct mouse_event mouse;
|
||||
|
||||
int bflag;
|
||||
int references;
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_if_shell_data *cdata;
|
||||
char *shellcmd, *cmd, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct format_tree *ft;
|
||||
struct cmdq_item *new_item;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
const char *cwd;
|
||||
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, cmdq->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (args_has(args, 'F')) {
|
||||
cmd = NULL;
|
||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||
@@ -94,19 +92,25 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
free(shellcmd);
|
||||
if (cmd == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmdq_run(cmdq, cmdlist, &cmdq->item->mouse);
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &item->mouse, 0);
|
||||
cmdq_insert_after(item, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (self->file != NULL) {
|
||||
cdata->file = xstrdup(self->file);
|
||||
cdata->line = self->line;
|
||||
}
|
||||
|
||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
||||
if (args->argc == 3)
|
||||
@@ -114,92 +118,85 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else
|
||||
cdata->cmd_else = NULL;
|
||||
|
||||
cdata->bflag = args_has(args, 'b');
|
||||
cdata->client = item->client;
|
||||
cdata->client->references++;
|
||||
|
||||
cdata->cmdq = cmdq;
|
||||
memcpy(&cdata->mouse, &cmdq->item->mouse, sizeof cdata->mouse);
|
||||
cmdq->references++;
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
else
|
||||
cdata->item = NULL;
|
||||
memcpy(&cdata->mouse, &item->mouse, sizeof cdata->mouse);
|
||||
|
||||
cdata->references = 1;
|
||||
job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free,
|
||||
cdata);
|
||||
free(shellcmd);
|
||||
|
||||
if (cdata->bflag)
|
||||
if (args_has(args, 'b'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
void
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job->data;
|
||||
struct cmd_q *cmdq = cdata->cmdq, *cmdq1;
|
||||
struct client *c = cdata->client;
|
||||
struct cmd_list *cmdlist;
|
||||
char *cause, *cmd;
|
||||
|
||||
if (cmdq->flags & CMD_Q_DEAD)
|
||||
return;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause, *cmd, *file = cdata->file;
|
||||
u_int line = cdata->line;
|
||||
|
||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||
cmd = cdata->cmd_else;
|
||||
else
|
||||
cmd = cdata->cmd_if;
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
goto out;
|
||||
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return;
|
||||
cmdlist = cmd_string_parse(cmd, file, line, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL)
|
||||
new_item = cmdq_get_callback(cmd_if_shell_error, cause);
|
||||
else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &cdata->mouse, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
cmdq1 = cmdq_new(cmdq->client);
|
||||
cmdq1->flags |= cmdq->flags & CMD_Q_NOHOOKS;
|
||||
cmdq1->emptyfn = cmd_if_shell_done;
|
||||
cmdq1->data = cdata;
|
||||
if (new_item != NULL) {
|
||||
if (cdata->item == NULL)
|
||||
cmdq_append(c, new_item);
|
||||
else
|
||||
cmdq_insert_after(cdata->item, new_item);
|
||||
}
|
||||
|
||||
cdata->references++;
|
||||
cmdq_run(cmdq1, cmdlist, &cdata->mouse);
|
||||
cmd_list_free(cmdlist);
|
||||
out:
|
||||
if (cdata->item != NULL)
|
||||
cdata->item->flags &= ~CMDQ_WAITING;
|
||||
}
|
||||
|
||||
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;
|
||||
cmdq_free(cmdq1);
|
||||
|
||||
if (--cdata->references != 0)
|
||||
return;
|
||||
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_if_shell_free(void *data)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = data;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
|
||||
if (--cdata->references != 0)
|
||||
return;
|
||||
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
server_client_unref(cdata->client);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
|
||||
free(cdata->file);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
* Join or move a pane into another (like split/swap/kill).
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
|
||||
static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_join_pane_entry = {
|
||||
.name = "join-pane",
|
||||
@@ -60,14 +58,8 @@ const struct cmd_entry cmd_move_pane_entry = {
|
||||
.exec = cmd_join_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
static enum cmd_retval
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *dst_s;
|
||||
@@ -78,25 +70,31 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
int size, percentage, dst_idx;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
int not_same_window;
|
||||
|
||||
dst_s = cmdq->state.tflag.s;
|
||||
dst_wl = cmdq->state.tflag.wl;
|
||||
dst_wp = cmdq->state.tflag.wp;
|
||||
if (self->entry == &cmd_join_pane_entry)
|
||||
not_same_window = 1;
|
||||
else
|
||||
not_same_window = 0;
|
||||
|
||||
dst_s = item->state.tflag.s;
|
||||
dst_wl = item->state.tflag.wl;
|
||||
dst_wp = item->state.tflag.wp;
|
||||
dst_w = dst_wl->window;
|
||||
dst_idx = dst_wl->idx;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
src_wl = cmdq->state.sflag.wl;
|
||||
src_wp = cmdq->state.sflag.wp;
|
||||
src_wl = item->state.sflag.wl;
|
||||
src_wp = item->state.sflag.wp;
|
||||
src_w = src_wl->window;
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (not_same_window && src_w == dst_w) {
|
||||
cmdq_error(cmdq, "can't join a pane to its own window");
|
||||
cmdq_error(item, "can't join a pane to its own window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!not_same_window && src_wp == dst_wp) {
|
||||
cmdq_error(cmdq, "source and target panes must be different");
|
||||
cmdq_error(item, "source and target panes must be different");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -108,14 +106,14 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
if (args_has(args, 'l')) {
|
||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "size %s", cause);
|
||||
cmdq_error(item, "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) {
|
||||
cmdq_error(cmdq, "percentage %s", cause);
|
||||
cmdq_error(item, "percentage %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -126,7 +124,7 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
}
|
||||
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0);
|
||||
if (lc == NULL) {
|
||||
cmdq_error(cmdq, "create pane failed: pane too small");
|
||||
cmdq_error(item, "create pane failed: pane too small");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -154,8 +152,8 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
if (window_count_panes(src_w) == 0)
|
||||
server_kill_window(src_w);
|
||||
else
|
||||
notify_window_layout_changed(src_w);
|
||||
notify_window_layout_changed(dst_w);
|
||||
notify_window("window-layout-changed", src_w);
|
||||
notify_window("window-layout-changed", dst_w);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Kill pane.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_kill_pane_entry = {
|
||||
.name = "kill-pane",
|
||||
@@ -41,21 +41,14 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
.exec = cmd_kill_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = cmdq->state.tflag.wp;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp;
|
||||
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
/* Only one pane, kill the window. */
|
||||
server_kill_window(wl->window);
|
||||
recalculate_sizes();
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'a')) {
|
||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
||||
if (loopwp == wp)
|
||||
@@ -63,11 +56,17 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
layout_close_pane(loopwp);
|
||||
window_remove_pane(wl->window, loopwp);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
server_kill_window(wl->window);
|
||||
recalculate_sizes();
|
||||
} else {
|
||||
layout_close_pane(wp);
|
||||
window_remove_pane(wl->window, wp);
|
||||
server_redraw_window(wl->window);
|
||||
}
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Kill the server and do nothing else.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_kill_server_entry = {
|
||||
.name = "kill-server",
|
||||
@@ -51,8 +51,8 @@ const struct cmd_entry cmd_start_server_entry = {
|
||||
.exec = cmd_kill_server_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_server_exec(struct cmd *self, __unused struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_kill_server_exec(struct cmd *self, __unused struct cmdq_item *item)
|
||||
{
|
||||
if (self->entry == &cmd_kill_server_entry)
|
||||
kill(getpid(), SIGTERM);
|
||||
|
||||
@@ -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_q *);
|
||||
static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_kill_session_entry = {
|
||||
.name = "kill-session",
|
||||
@@ -42,14 +42,14 @@ const struct cmd_entry cmd_kill_session_entry = {
|
||||
.exec = cmd_kill_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s, *sloop, *stmp;
|
||||
struct winlink *wl;
|
||||
|
||||
s = cmdq->state.tflag.s;
|
||||
s = item->state.tflag.s;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Destroy window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_kill_window_entry = {
|
||||
.name = "kill-window",
|
||||
@@ -52,17 +52,17 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
||||
.exec = cmd_kill_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.tflag.wl, *wl2, *wl3;
|
||||
struct winlink *wl = item->state.tflag.wl, *wl2, *wl3;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct session *s = item->state.tflag.s;
|
||||
|
||||
if (self->entry == &cmd_unlink_window_entry) {
|
||||
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
|
||||
cmdq_error(cmdq, "window only linked to one session");
|
||||
cmdq_error(item, "window only linked to one session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_unlink_window(s, wl);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#define LIST_BUFFERS_TEMPLATE \
|
||||
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
|
||||
|
||||
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_buffers_entry = {
|
||||
.name = "list-buffers",
|
||||
@@ -39,12 +39,12 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
.args = { "F:", 0, 0 },
|
||||
.usage = "[-F format]",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_buffers_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct paste_buffer *pb;
|
||||
@@ -57,11 +57,11 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
pb = NULL;
|
||||
while ((pb = paste_walk(pb)) != NULL) {
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults_paste_buffer(ft, pb);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
*/
|
||||
|
||||
#define LIST_CLIENTS_TEMPLATE \
|
||||
"#{client_tty}: #{session_name} " \
|
||||
"#{client_name}: #{session_name} " \
|
||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
||||
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
|
||||
|
||||
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_clients_entry = {
|
||||
.name = "list-clients",
|
||||
@@ -44,12 +44,12 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
|
||||
.flags = CMD_READONLY,
|
||||
.flags = CMD_READONLY|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_clients_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
@@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
char *line;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
s = cmdq->state.tflag.s;
|
||||
s = item->state.tflag.s;
|
||||
else
|
||||
s = NULL;
|
||||
|
||||
@@ -72,12 +72,12 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (c->session == NULL || (s != NULL && s != c->session))
|
||||
continue;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", idx);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
113
cmd-list-keys.c
113
cmd-list-keys.c
@@ -27,19 +27,19 @@
|
||||
* List key bindings.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_keys_entry = {
|
||||
.name = "list-keys",
|
||||
.alias = "lsk",
|
||||
|
||||
.args = { "t:T:", 0, 0 },
|
||||
.usage = "[-t mode-table] [-T key-table]",
|
||||
.args = { "T:", 0, 0 },
|
||||
.usage = "[-T key-table]",
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
};
|
||||
|
||||
@@ -50,12 +50,12 @@ const struct cmd_entry cmd_list_commands_entry = {
|
||||
.args = { "F:", 0, 0 },
|
||||
.usage = "[-F format]",
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct key_table *table;
|
||||
@@ -65,14 +65,11 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
int repeat, width, tablewidth, keywidth;
|
||||
|
||||
if (self->entry == &cmd_list_commands_entry)
|
||||
return (cmd_list_keys_commands(self, cmdq));
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_list_keys_table(self, cmdq));
|
||||
return (cmd_list_keys_commands(self, item));
|
||||
|
||||
tablename = args_get(args, 'T');
|
||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
||||
cmdq_error(cmdq, "table %s doesn't exist", tablename);
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -124,7 +121,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
strlcat(tmp, cp, sizeof tmp);
|
||||
free(cp);
|
||||
|
||||
cmdq_print(cmdq, "bind-key %s", tmp);
|
||||
cmdq_print(item, "bind-key %s", tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,75 +129,13 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename, *key, *cmdstr, *mode;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind;
|
||||
char repeat[16];
|
||||
int width, keywidth, repeatwidth, any_mode;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
keywidth = repeatwidth = 0;
|
||||
any_mode = 0;
|
||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
key = key_string_lookup_key(mbind->key);
|
||||
|
||||
if (mbind->mode != 0)
|
||||
any_mode = 1;
|
||||
|
||||
width = strlen(key);
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
|
||||
if (mbind->repeat != 1) {
|
||||
snprintf(repeat, sizeof repeat, "%u", mbind->repeat);
|
||||
width = strlen(repeat);
|
||||
if (width > repeatwidth)
|
||||
repeatwidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||
key = key_string_lookup_key(mbind->key);
|
||||
|
||||
mode = "";
|
||||
if (mbind->mode != 0)
|
||||
mode = "c";
|
||||
snprintf(repeat, sizeof repeat, "%u", mbind->repeat);
|
||||
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
|
||||
if (cmdstr != NULL) {
|
||||
cmdq_print(cmdq,
|
||||
"bind-key -%st %s%s%s%*s %*s %s%s%s%s",
|
||||
mode, any_mode && *mode == '\0' ? " " : "",
|
||||
mtab->name,
|
||||
mbind->repeat != 1 ? " -R " :
|
||||
(repeatwidth == 0 ? "" : " "),
|
||||
repeatwidth, mbind->repeat != 1 ? repeat : "",
|
||||
(int)keywidth, key, cmdstr,
|
||||
mbind->arg != NULL ? " \"" : "",
|
||||
mbind->arg != NULL ? mbind->arg : "",
|
||||
mbind->arg != NULL ? "\"": "");
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq)
|
||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
const char *template;
|
||||
const char *template, *s;
|
||||
char *line;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL) {
|
||||
@@ -209,25 +144,27 @@ cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq)
|
||||
"#{command_list_usage}";
|
||||
}
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
entry = *entryp;
|
||||
|
||||
format_add(ft, "command_list_name", "%s", entry->name);
|
||||
if (entry->alias != NULL) {
|
||||
format_add(ft, "command_list_alias", "%s",
|
||||
entry->alias);
|
||||
}
|
||||
if (entry->alias != NULL) {
|
||||
format_add(ft, "command_list_usage", "%s",
|
||||
entry->usage);
|
||||
}
|
||||
if (entry->alias != NULL)
|
||||
s = entry->alias;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_alias", "%s", s);
|
||||
if (entry->usage != NULL)
|
||||
s = entry->usage;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_usage", "%s", s);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
if (*line != '\0')
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@
|
||||
* List panes on given window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_list_panes_server(struct cmd *, struct cmd_q *);
|
||||
void cmd_list_panes_session(struct cmd *, struct session *, struct cmd_q *,
|
||||
int);
|
||||
void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *,
|
||||
struct cmd_q *, int);
|
||||
static void cmd_list_panes_server(struct cmd *, struct cmdq_item *);
|
||||
static void cmd_list_panes_session(struct cmd *, struct session *,
|
||||
struct cmdq_item *, int);
|
||||
static void cmd_list_panes_window(struct cmd *, struct session *,
|
||||
struct winlink *, struct cmdq_item *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_panes_entry = {
|
||||
.name = "list-panes",
|
||||
@@ -43,49 +43,49 @@ const struct cmd_entry cmd_list_panes_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_panes_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_panes_server(self, cmdq);
|
||||
cmd_list_panes_server(self, item);
|
||||
else if (args_has(args, 's'))
|
||||
cmd_list_panes_session(self, s, cmdq, 1);
|
||||
cmd_list_panes_session(self, s, item, 1);
|
||||
else
|
||||
cmd_list_panes_window(self, s, wl, cmdq, 0);
|
||||
cmd_list_panes_window(self, s, wl, item, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq)
|
||||
static void
|
||||
cmd_list_panes_server(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
cmd_list_panes_session(self, s, cmdq, 2);
|
||||
cmd_list_panes_session(self, s, item, 2);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq,
|
||||
int type)
|
||||
static void
|
||||
cmd_list_panes_session(struct cmd *self, struct session *s,
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct winlink *wl;
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows)
|
||||
cmd_list_panes_window(self, s, wl, cmdq, type);
|
||||
cmd_list_panes_window(self, s, wl, item, type);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
struct cmd_q *cmdq, int type)
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp;
|
||||
@@ -123,12 +123,12 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, wp);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
"#{session_group}#{?session_grouped,),}" \
|
||||
"#{?session_attached, (attached),}"
|
||||
|
||||
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_sessions_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_sessions_entry = {
|
||||
.name = "list-sessions",
|
||||
@@ -45,12 +46,12 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
.args = { "F:", 0, 0 },
|
||||
.usage = "[-F format]",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_sessions_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s;
|
||||
@@ -64,12 +65,12 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, NULL, NULL);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -39,11 +39,11 @@
|
||||
"(#{window_panes} panes) " \
|
||||
"[#{window_width}x#{window_height}] "
|
||||
|
||||
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
|
||||
void cmd_list_windows_session(struct cmd *, struct session *,
|
||||
struct cmd_q *, int);
|
||||
static void cmd_list_windows_server(struct cmd *, struct cmdq_item *);
|
||||
static void cmd_list_windows_session(struct cmd *, struct session *,
|
||||
struct cmdq_item *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_windows_entry = {
|
||||
.name = "list-windows",
|
||||
@@ -54,35 +54,35 @@ const struct cmd_entry cmd_list_windows_entry = {
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_windows_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_windows_server(self, cmdq);
|
||||
cmd_list_windows_server(self, item);
|
||||
else
|
||||
cmd_list_windows_session(self, cmdq->state.tflag.s, cmdq, 0);
|
||||
cmd_list_windows_session(self, item->state.tflag.s, item, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq)
|
||||
static void
|
||||
cmd_list_windows_server(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
cmd_list_windows_session(self, s, cmdq, 1);
|
||||
cmd_list_windows_session(self, s, item, 1);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
struct cmd_q *cmdq, int type)
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
@@ -105,12 +105,12 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, NULL);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", line);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
@@ -31,8 +31,9 @@
|
||||
* Loads a paste buffer from a file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
void cmd_load_buffer_callback(struct client *, int, void *);
|
||||
static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_load_buffer_callback(struct client *, int, void *);
|
||||
|
||||
const struct cmd_entry cmd_load_buffer_entry = {
|
||||
.name = "load-buffer",
|
||||
@@ -41,21 +42,26 @@ const struct cmd_entry cmd_load_buffer_entry = {
|
||||
.args = { "b:", 1, 1 },
|
||||
.usage = CMD_BUFFER_USAGE " path",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_load_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
struct cmd_load_buffer_data {
|
||||
struct cmdq_item *item;
|
||||
char *bufname;
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s;
|
||||
FILE *f;
|
||||
const char *path, *bufname, *cwd;
|
||||
char *pdata, *new_pdata, *cause, *file, resolved[PATH_MAX];
|
||||
size_t psize;
|
||||
int ch, error;
|
||||
struct args *args = self->args;
|
||||
struct cmd_load_buffer_data *cdata;
|
||||
struct client *c = item->client;
|
||||
FILE *f;
|
||||
const char *path, *bufname;
|
||||
char *pdata, *new_pdata, *cause, *file;
|
||||
size_t psize;
|
||||
int ch, error;
|
||||
|
||||
bufname = NULL;
|
||||
if (args_has(args, 'b'))
|
||||
@@ -63,36 +69,27 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
path = args->argv[0];
|
||||
if (strcmp(path, "-") == 0) {
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->item = item;
|
||||
|
||||
if (bufname != NULL)
|
||||
cdata->bufname = xstrdup(bufname);
|
||||
|
||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
||||
(void *)bufname, &cause);
|
||||
cdata, &cause);
|
||||
if (error != 0) {
|
||||
cmdq_error(cmdq, "%s: %s", path, cause);
|
||||
cmdq_error(item, "%s: %s", path, cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = c->cwd;
|
||||
else if ((s = c->session) != NULL && s->cwd != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = ".";
|
||||
|
||||
if (*path == '/')
|
||||
file = xstrdup(path);
|
||||
else
|
||||
xasprintf(&file, "%s/%s", cwd, path);
|
||||
if (realpath(file, resolved) == NULL &&
|
||||
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) {
|
||||
cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
f = fopen(resolved, "rb");
|
||||
free(file);
|
||||
file = server_client_get_path(c, path);
|
||||
f = fopen(file, "rb");
|
||||
if (f == NULL) {
|
||||
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
free(file);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -101,23 +98,24 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
while ((ch = getc(f)) != EOF) {
|
||||
/* Do not let the server die due to memory exhaustion. */
|
||||
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
|
||||
cmdq_error(cmdq, "realloc error: %s", strerror(errno));
|
||||
cmdq_error(item, "realloc error: %s", strerror(errno));
|
||||
goto error;
|
||||
}
|
||||
pdata = new_pdata;
|
||||
pdata[psize++] = ch;
|
||||
}
|
||||
if (ferror(f)) {
|
||||
cmdq_error(cmdq, "%s: read error", resolved);
|
||||
cmdq_error(item, "%s: read error", file);
|
||||
goto error;
|
||||
}
|
||||
if (pdata != NULL)
|
||||
pdata[psize] = '\0';
|
||||
|
||||
fclose(f);
|
||||
free(file);
|
||||
|
||||
if (paste_set(pdata, psize, bufname, &cause) != 0) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(pdata);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -132,12 +130,12 @@ error:
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
{
|
||||
const char *bufname = data;
|
||||
char *pdata, *cause, *saved;
|
||||
size_t psize;
|
||||
struct cmd_load_buffer_data *cdata = data;
|
||||
char *pdata, *cause, *saved;
|
||||
size_t psize;
|
||||
|
||||
if (!closed)
|
||||
return;
|
||||
@@ -145,7 +143,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
|
||||
server_client_unref(c);
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
return;
|
||||
goto out;
|
||||
|
||||
psize = EVBUFFER_LENGTH(c->stdin_data);
|
||||
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL)
|
||||
@@ -155,7 +153,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
pdata[psize] = '\0';
|
||||
evbuffer_drain(c->stdin_data, psize);
|
||||
|
||||
if (paste_set(pdata, psize, bufname, &cause) != 0) {
|
||||
if (paste_set(pdata, psize, cdata->bufname, &cause) != 0) {
|
||||
/* No context so can't use server_client_msg_error. */
|
||||
if (~c->flags & CLIENT_UTF8) {
|
||||
saved = cause;
|
||||
@@ -167,7 +165,9 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
|
||||
free(pdata);
|
||||
free(cause);
|
||||
}
|
||||
|
||||
out:
|
||||
cmdq_continue(c->cmdq);
|
||||
cdata->item->flags &= ~CMDQ_WAITING;
|
||||
|
||||
free(cdata->bufname);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Lock commands.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_lock_server_entry = {
|
||||
.name = "lock-server",
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_lock_server_entry = {
|
||||
.args = { "", 0, 0 },
|
||||
.usage = "",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_lock_session_entry = {
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
};
|
||||
|
||||
@@ -59,19 +59,19 @@ const struct cmd_entry cmd_lock_client_entry = {
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, __unused struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, __unused struct cmdq_item *item)
|
||||
{
|
||||
if (self->entry == &cmd_lock_server_entry)
|
||||
server_lock();
|
||||
else if (self->entry == &cmd_lock_session_entry)
|
||||
server_lock_session(cmdq->state.tflag.s);
|
||||
server_lock_session(item->state.tflag.s);
|
||||
else
|
||||
server_lock_client(cmdq->state.c);
|
||||
server_lock_client(item->state.c);
|
||||
|
||||
recalculate_sizes();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Move a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_move_window_entry = {
|
||||
.name = "move-window",
|
||||
@@ -56,18 +56,15 @@ const struct cmd_entry cmd_link_window_entry = {
|
||||
.exec = cmd_move_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *src = cmdq->state.sflag.s;
|
||||
struct session *dst = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.sflag.wl;
|
||||
struct session *src = item->state.sflag.s;
|
||||
struct session *dst = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.sflag.wl;
|
||||
char *cause;
|
||||
int idx = cmdq->state.tflag.idx, kflag, dflag, sflag;
|
||||
|
||||
kflag = args_has(self->args, 'k');
|
||||
dflag = args_has(self->args, 'd');
|
||||
int idx = item->state.tflag.idx, kflag, dflag, sflag;
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
session_renumber_windows(dst);
|
||||
@@ -87,7 +84,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (server_link_window(src, wl, dst, idx, kflag, !dflag,
|
||||
&cause) != 0) {
|
||||
cmdq_error(cmdq, "can't link window: %s", cause);
|
||||
cmdq_error(item, "can't link window: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
#define NEW_SESSION_TEMPLATE "#{session_name}:"
|
||||
|
||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_new_session_entry = {
|
||||
.name = "new-session",
|
||||
@@ -63,23 +63,23 @@ const struct cmd_entry cmd_has_session_entry = {
|
||||
.exec = cmd_new_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s, *as;
|
||||
struct session *groupwith = cmdq->state.tflag.s;
|
||||
struct client *c = item->client;
|
||||
struct session *s, *as, *groupwith;
|
||||
struct window *w;
|
||||
struct environ *env;
|
||||
struct termios tio, *tiop;
|
||||
const char *newname, *target, *update, *errstr, *template;
|
||||
const char *path, *cwd, *to_free = NULL;
|
||||
char **argv, *cmd, *cause, *cp;
|
||||
struct session_group *sg;
|
||||
const char *newname, *errstr, *template, *group, *prefix;
|
||||
const char *path, *cmd, *cwd, *to_free = NULL;
|
||||
char **argv, *cause, *cp;
|
||||
int detached, already_attached, idx, argc;
|
||||
u_int sx, sy;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (self->entry == &cmd_has_session_entry) {
|
||||
/*
|
||||
@@ -90,41 +90,57 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
||||
cmdq_error(cmdq, "command or window name given with target");
|
||||
cmdq_error(item, "command or window name given with target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
newname = args_get(args, 's');
|
||||
if (newname != NULL) {
|
||||
if (!session_check_name(newname)) {
|
||||
cmdq_error(cmdq, "bad session name: %s", newname);
|
||||
cmdq_error(item, "bad session name: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((as = session_find(newname)) != NULL) {
|
||||
if (args_has(args, 'A')) {
|
||||
/*
|
||||
* This cmdq is now destined for
|
||||
* attach-session. Because attach-session
|
||||
* will have already been prepared, copy this
|
||||
* This item is now destined for
|
||||
* attach-session. Because attach-session will
|
||||
* have already been prepared, copy this
|
||||
* session into its tflag so it can be used.
|
||||
*/
|
||||
cmd_find_from_session(&cmdq->state.tflag, as);
|
||||
return (cmd_attach_session(cmdq,
|
||||
cmd_find_from_session(&item->state.tflag, as);
|
||||
return (cmd_attach_session(item,
|
||||
args_has(args, 'D'), 0, NULL,
|
||||
args_has(args, 'E')));
|
||||
}
|
||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ((target = args_get(args, 't')) != NULL) {
|
||||
/* Is this going to be part of a session group? */
|
||||
group = args_get(args, 't');
|
||||
if (group != NULL) {
|
||||
groupwith = item->state.tflag.s;
|
||||
if (groupwith == NULL) {
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
if (!session_check_name(group)) {
|
||||
cmdq_error(item, "bad group name: %s", group);
|
||||
goto error;
|
||||
}
|
||||
sg = session_group_find(group);
|
||||
} else
|
||||
sg = session_group_contains(groupwith);
|
||||
if (sg != NULL)
|
||||
prefix = sg->name;
|
||||
else if (groupwith != NULL)
|
||||
prefix = groupwith->name;
|
||||
else
|
||||
prefix = group;
|
||||
} else {
|
||||
groupwith = NULL;
|
||||
sg = NULL;
|
||||
prefix = NULL;
|
||||
}
|
||||
|
||||
/* Set -d if no client. */
|
||||
detached = args_has(args, 'd');
|
||||
@@ -138,10 +154,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, NULL, NULL, NULL);
|
||||
} else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = c->cwd;
|
||||
else
|
||||
@@ -157,8 +171,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
* over.
|
||||
*/
|
||||
if (!detached && !already_attached && c->tty.fd != -1) {
|
||||
if (server_client_check_nested(cmdq->client)) {
|
||||
cmdq_error(cmdq, "sessions should be nested with care, "
|
||||
if (server_client_check_nested(item->client)) {
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -171,7 +185,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
/* Open the terminal if necessary. */
|
||||
if (!detached && !already_attached) {
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(cmdq, "open terminal failed: %s", cause);
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
@@ -188,14 +202,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
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);
|
||||
cmdq_error(item, "width %s", errstr);
|
||||
goto 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);
|
||||
cmdq_error(item, "height %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -212,11 +226,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (!args_has(args, 't') && args->argc != 0) {
|
||||
argc = args->argc;
|
||||
argv = args->argv;
|
||||
} else if (groupwith == NULL) {
|
||||
} else if (sg == NULL && groupwith == NULL) {
|
||||
cmd = options_get_string(global_s_options, "default-command");
|
||||
if (cmd != NULL && *cmd != '\0') {
|
||||
argc = 1;
|
||||
argv = &cmd;
|
||||
argv = (char **)&cmd;
|
||||
} else {
|
||||
argc = 0;
|
||||
argv = NULL;
|
||||
@@ -233,19 +247,16 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
/* Construct the environment. */
|
||||
env = environ_create();
|
||||
if (c != NULL && !args_has(args, 'E')) {
|
||||
update = options_get_string(global_s_options,
|
||||
"update-environment");
|
||||
environ_update(update, c->environ, env);
|
||||
}
|
||||
if (c != NULL && !args_has(args, 'E'))
|
||||
environ_update(global_s_options, c->environ, env);
|
||||
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(global_s_options, "base-index");
|
||||
s = session_create(newname, argc, argv, path, cwd, env, tiop, idx, sx,
|
||||
sy, &cause);
|
||||
s = session_create(prefix, newname, argc, argv, path, cwd, env, tiop,
|
||||
idx, sx, sy, &cause);
|
||||
environ_free(env);
|
||||
if (s == NULL) {
|
||||
cmdq_error(cmdq, "create session failed: %s", cause);
|
||||
cmdq_error(item, "create session failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
@@ -261,11 +272,19 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
* If a target session is given, this is to be part of a session group,
|
||||
* so add it to the group and synchronize.
|
||||
*/
|
||||
if (groupwith != NULL) {
|
||||
session_group_add(groupwith, s);
|
||||
if (group != NULL) {
|
||||
if (sg == NULL) {
|
||||
if (groupwith != NULL) {
|
||||
sg = session_group_new(groupwith->name);
|
||||
session_group_add(sg, groupwith);
|
||||
} else
|
||||
sg = session_group_new(group);
|
||||
}
|
||||
session_group_add(sg, s);
|
||||
session_group_synchronize_to(s);
|
||||
session_select(s, RB_MIN(winlinks, &s->windows)->idx);
|
||||
}
|
||||
notify_session("session-created", s);
|
||||
|
||||
/*
|
||||
* Set the client to the new session. If a command client exists, it is
|
||||
@@ -278,9 +297,10 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
} else if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
server_client_set_key_table(c, NULL);
|
||||
if (!item->repeat)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
@@ -299,22 +319,20 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_SESSION_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
cp = format_single(item, template, c, s, NULL, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
if (!detached)
|
||||
cmdq->client_exit = 0;
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_from_session(&fs, s);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
||||
|
||||
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_new_window_entry = {
|
||||
.name = "new-window",
|
||||
@@ -48,23 +48,23 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
.exec = cmd_new_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct client *c = cmdq->state.c;
|
||||
int idx = cmdq->state.tflag.idx;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct client *c = item->state.c;
|
||||
int idx = item->state.tflag.idx;
|
||||
const char *cmd, *path, *template, *cwd, *to_free;
|
||||
char **argv, *cause, *cp;
|
||||
int argc, detached;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
||||
cmdq_error(cmdq, "no free window indexes");
|
||||
cmdq_error(item, "no free window indexes");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -85,8 +85,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(cmdq->client->environ, "PATH");
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
@@ -94,12 +94,10 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
cwd = to_free = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else
|
||||
cwd = s->cwd;
|
||||
|
||||
@@ -111,7 +109,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
* Can't use session_detach as it will destroy session if this
|
||||
* makes it empty.
|
||||
*/
|
||||
notify_window_unlinked(s, wl->window);
|
||||
notify_session_window("window-unlinked", s, wl->window);
|
||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||
winlink_stack_remove(&s->lastw, wl);
|
||||
winlink_remove(&s->windows, wl);
|
||||
@@ -128,7 +126,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
|
||||
&cause);
|
||||
if (wl == NULL) {
|
||||
cmdq_error(cmdq, "create window failed: %s", cause);
|
||||
cmdq_error(item, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
@@ -141,19 +139,17 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, c, s, wl, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
cp = format_single(item, template, c, s, wl, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_from_winlink(&fs, s, wl);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
|
||||
@@ -27,10 +27,7 @@
|
||||
* Paste paste buffer if present.
|
||||
*/
|
||||
|
||||
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);
|
||||
static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.name = "paste-buffer",
|
||||
@@ -42,15 +39,15 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_paste_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct paste_buffer *pb;
|
||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
||||
size_t seplen, bufsize;
|
||||
@@ -65,7 +62,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else {
|
||||
pb = paste_get_name(bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(cmdq, "no buffer %s", bufname);
|
||||
cmdq_error(item, "no buffer %s", bufname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
* Open pipe to redirect pane output. If already open, close first.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||
|
||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
.name = "pipe-pane",
|
||||
@@ -45,18 +45,18 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_pipe_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct client *c = item->state.c;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
char *cmd;
|
||||
int old_fd, pipe_fd[2], null_fd;
|
||||
struct format_tree *ft;
|
||||
@@ -84,12 +84,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
/* Open the new pipe. */
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||
cmdq_error(cmdq, "socketpair error: %s", strerror(errno));
|
||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Expand the command. */
|
||||
ft = format_create(cmdq, 0);
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cmd = format_expand_time(ft, args->argv[0], time(NULL));
|
||||
format_free(ft);
|
||||
@@ -97,7 +97,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
/* Fork the child. */
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
cmdq_error(cmdq, "fork error: %s", strerror(errno));
|
||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
||||
|
||||
free(cmd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -141,7 +141,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
|
||||
__unused short what, void *data)
|
||||
{
|
||||
|
||||
569
cmd-queue.c
569
cmd-queue.c
@@ -25,51 +25,357 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
static enum cmd_retval cmdq_continue_one(struct cmd_q *);
|
||||
/* Global command queue. */
|
||||
static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue);
|
||||
|
||||
/* Create new command queue. */
|
||||
struct cmd_q *
|
||||
cmdq_new(struct client *c)
|
||||
/* Get command queue name. */
|
||||
static const char *
|
||||
cmdq_name(struct client *c)
|
||||
{
|
||||
struct cmd_q *cmdq;
|
||||
static char s[32];
|
||||
|
||||
cmdq = xcalloc(1, sizeof *cmdq);
|
||||
cmdq->references = 1;
|
||||
cmdq->flags = 0;
|
||||
|
||||
cmdq->client = c;
|
||||
cmdq->client_exit = -1;
|
||||
|
||||
TAILQ_INIT(&cmdq->queue);
|
||||
cmdq->item = NULL;
|
||||
cmdq->cmd = NULL;
|
||||
|
||||
cmd_find_clear_state(&cmdq->current, NULL, 0);
|
||||
cmdq->parent = NULL;
|
||||
|
||||
return (cmdq);
|
||||
if (c == NULL)
|
||||
return ("<global>");
|
||||
xsnprintf(s, sizeof s, "<%p>", c);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* Free command queue */
|
||||
int
|
||||
cmdq_free(struct cmd_q *cmdq)
|
||||
/* Get command queue from client. */
|
||||
static struct cmdq_list *
|
||||
cmdq_get(struct client *c)
|
||||
{
|
||||
if (--cmdq->references != 0) {
|
||||
if (cmdq->flags & CMD_Q_DEAD)
|
||||
return (1);
|
||||
if (c == NULL)
|
||||
return (&global_queue);
|
||||
return (&c->queue);
|
||||
}
|
||||
|
||||
/* Append an item. */
|
||||
void
|
||||
cmdq_append(struct client *c, struct cmdq_item *item)
|
||||
{
|
||||
struct cmdq_list *queue = cmdq_get(c);
|
||||
struct cmdq_item *next;
|
||||
|
||||
do {
|
||||
next = item->next;
|
||||
item->next = NULL;
|
||||
|
||||
if (c != NULL)
|
||||
c->references++;
|
||||
item->client = c;
|
||||
|
||||
item->queue = queue;
|
||||
TAILQ_INSERT_TAIL(queue, item, entry);
|
||||
|
||||
item = next;
|
||||
} while (item != NULL);
|
||||
}
|
||||
|
||||
/* Insert an item. */
|
||||
void
|
||||
cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = after->client;
|
||||
struct cmdq_list *queue = after->queue;
|
||||
struct cmdq_item *next;
|
||||
|
||||
do {
|
||||
next = item->next;
|
||||
item->next = NULL;
|
||||
|
||||
if (c != NULL)
|
||||
c->references++;
|
||||
item->client = c;
|
||||
|
||||
item->queue = queue;
|
||||
if (after->next != NULL)
|
||||
TAILQ_INSERT_AFTER(queue, after->next, item, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(queue, after, item, entry);
|
||||
after->next = item;
|
||||
|
||||
item = next;
|
||||
} while (item != NULL);
|
||||
}
|
||||
|
||||
/* Remove an item. */
|
||||
static void
|
||||
cmdq_remove(struct cmdq_item *item)
|
||||
{
|
||||
if (item->formats != NULL)
|
||||
format_free(item->formats);
|
||||
|
||||
if (item->client != NULL)
|
||||
server_client_unref(item->client);
|
||||
|
||||
if (item->type == CMDQ_COMMAND)
|
||||
cmd_list_free(item->cmdlist);
|
||||
|
||||
TAILQ_REMOVE(item->queue, item, entry);
|
||||
|
||||
free((void *)item->name);
|
||||
free(item);
|
||||
}
|
||||
|
||||
/* Set command group. */
|
||||
static u_int
|
||||
cmdq_next_group(void)
|
||||
{
|
||||
static u_int group;
|
||||
|
||||
return (++group);
|
||||
}
|
||||
|
||||
/* Remove all subsequent items that match this item's group. */
|
||||
static void
|
||||
cmdq_remove_group(struct cmdq_item *item)
|
||||
{
|
||||
struct cmdq_item *this, *next;
|
||||
|
||||
this = TAILQ_NEXT(item, entry);
|
||||
while (this != NULL) {
|
||||
next = TAILQ_NEXT(this, entry);
|
||||
if (this->group == item->group)
|
||||
cmdq_remove(this);
|
||||
this = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a command for the command queue. */
|
||||
struct cmdq_item *
|
||||
cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
struct mouse_event *m, int flags)
|
||||
{
|
||||
struct cmdq_item *item, *first = NULL, *last = NULL;
|
||||
struct cmd *cmd;
|
||||
u_int group = cmdq_next_group();
|
||||
char *tmp;
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
xasprintf(&tmp, "command[%s]", cmd->entry->name);
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->name = tmp;
|
||||
item->type = CMDQ_COMMAND;
|
||||
|
||||
item->group = group;
|
||||
item->flags = flags;
|
||||
|
||||
item->cmdlist = cmdlist;
|
||||
item->cmd = cmd;
|
||||
|
||||
if (current != NULL)
|
||||
cmd_find_copy_state(&item->current, current);
|
||||
if (m != NULL)
|
||||
memcpy(&item->mouse, m, sizeof item->mouse);
|
||||
cmdlist->references++;
|
||||
|
||||
if (first == NULL)
|
||||
first = item;
|
||||
if (last != NULL)
|
||||
last->next = item;
|
||||
last = item;
|
||||
}
|
||||
return (first);
|
||||
}
|
||||
|
||||
/* Fire command on command queue. */
|
||||
static enum cmd_retval
|
||||
cmdq_fire_command(struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct cmd *cmd = item->cmd;
|
||||
enum cmd_retval retval;
|
||||
const char *name;
|
||||
struct cmd_find_state *fsp, fs;
|
||||
int flags;
|
||||
|
||||
flags = !!(cmd->flags & CMD_CONTROL);
|
||||
cmdq_guard(item, "begin", flags);
|
||||
|
||||
if (cmd_prepare_state(cmd, item) != 0) {
|
||||
retval = CMD_RETURN_ERROR;
|
||||
goto out;
|
||||
}
|
||||
if (item->client == NULL)
|
||||
item->client = cmd_find_client(item, NULL, CMD_FIND_QUIET);
|
||||
|
||||
retval = cmd->entry->exec(cmd, item);
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
goto out;
|
||||
|
||||
if (cmd->entry->flags & CMD_AFTERHOOK) {
|
||||
name = cmd->entry->name;
|
||||
if (cmd_find_valid_state(&item->state.tflag))
|
||||
fsp = &item->state.tflag;
|
||||
else {
|
||||
if (cmd_find_current(&fs, item, CMD_FIND_QUIET) != 0)
|
||||
goto out;
|
||||
fsp = &fs;
|
||||
}
|
||||
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
|
||||
}
|
||||
|
||||
out:
|
||||
item->client = c;
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
cmdq_guard(item, "error", flags);
|
||||
else
|
||||
cmdq_guard(item, "end", flags);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* Get a callback for the command queue. */
|
||||
struct cmdq_item *
|
||||
cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
|
||||
{
|
||||
struct cmdq_item *item;
|
||||
char *tmp;
|
||||
|
||||
xasprintf(&tmp, "callback[%s]", name);
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->name = tmp;
|
||||
item->type = CMDQ_CALLBACK;
|
||||
|
||||
item->group = 0;
|
||||
item->flags = 0;
|
||||
|
||||
item->cb = cb;
|
||||
item->data = data;
|
||||
|
||||
return (item);
|
||||
}
|
||||
|
||||
/* Fire callback on callback queue. */
|
||||
static enum cmd_retval
|
||||
cmdq_fire_callback(struct cmdq_item *item)
|
||||
{
|
||||
return (item->cb(item, item->data));
|
||||
}
|
||||
|
||||
/* Add a format to command queue. */
|
||||
void
|
||||
cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct cmdq_item *loop;
|
||||
char *value;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&value, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
for (loop = item; loop != NULL; loop = item->next) {
|
||||
if (loop->formats == NULL)
|
||||
loop->formats = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_add(loop->formats, key, "%s", value);
|
||||
}
|
||||
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Process next item on command queue. */
|
||||
u_int
|
||||
cmdq_next(struct client *c)
|
||||
{
|
||||
struct cmdq_list *queue = cmdq_get(c);
|
||||
const char *name = cmdq_name(c);
|
||||
struct cmdq_item *item;
|
||||
enum cmd_retval retval;
|
||||
u_int items = 0;
|
||||
static u_int number;
|
||||
|
||||
if (TAILQ_EMPTY(queue)) {
|
||||
log_debug("%s %s: empty", __func__, name);
|
||||
return (0);
|
||||
}
|
||||
if (TAILQ_FIRST(queue)->flags & CMDQ_WAITING) {
|
||||
log_debug("%s %s: waiting", __func__, name);
|
||||
return (0);
|
||||
}
|
||||
|
||||
cmdq_flush(cmdq);
|
||||
free(cmdq);
|
||||
return (1);
|
||||
log_debug("%s %s: enter", __func__, name);
|
||||
for (;;) {
|
||||
item = TAILQ_FIRST(queue);
|
||||
if (item == NULL)
|
||||
break;
|
||||
log_debug("%s %s: %s (%d), flags %x", __func__, name,
|
||||
item->name, item->type, item->flags);
|
||||
|
||||
/*
|
||||
* Any item with the waiting flag set waits until an external
|
||||
* event clears the flag (for example, a job - look at
|
||||
* run-shell).
|
||||
*/
|
||||
if (item->flags & CMDQ_WAITING)
|
||||
goto waiting;
|
||||
|
||||
/*
|
||||
* Items are only fired once, once the fired flag is set, a
|
||||
* waiting flag can only be cleared by an external event.
|
||||
*/
|
||||
if (~item->flags & CMDQ_FIRED) {
|
||||
item->time = time(NULL);
|
||||
item->number = ++number;
|
||||
|
||||
switch (item->type)
|
||||
{
|
||||
case CMDQ_COMMAND:
|
||||
retval = cmdq_fire_command(item);
|
||||
|
||||
/*
|
||||
* If a command returns an error, remove any
|
||||
* subsequent commands in the same group.
|
||||
*/
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
cmdq_remove_group(item);
|
||||
break;
|
||||
case CMDQ_CALLBACK:
|
||||
retval = cmdq_fire_callback(item);
|
||||
break;
|
||||
default:
|
||||
retval = CMD_RETURN_ERROR;
|
||||
break;
|
||||
}
|
||||
item->flags |= CMDQ_FIRED;
|
||||
|
||||
if (retval == CMD_RETURN_WAIT) {
|
||||
item->flags |= CMDQ_WAITING;
|
||||
goto waiting;
|
||||
}
|
||||
items++;
|
||||
}
|
||||
cmdq_remove(item);
|
||||
}
|
||||
|
||||
log_debug("%s %s: exit (empty)", __func__, name);
|
||||
return (items);
|
||||
|
||||
waiting:
|
||||
log_debug("%s %s: exit (wait)", __func__, name);
|
||||
return (items);
|
||||
}
|
||||
|
||||
/* Print a guard line. */
|
||||
void
|
||||
cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
|
||||
if (c == NULL || !(c->flags & CLIENT_CONTROL))
|
||||
return;
|
||||
|
||||
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
|
||||
(long)item->time, item->number, flags);
|
||||
server_client_push_stdout(c);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct client *c = item->client;
|
||||
struct window *w;
|
||||
va_list ap;
|
||||
char *tmp, *msg;
|
||||
@@ -104,10 +410,10 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
|
||||
/* Show error from command. */
|
||||
void
|
||||
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
cmdq_error(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct cmd *cmd = cmdq->cmd;
|
||||
struct client *c = item->client;
|
||||
struct cmd *cmd = item->cmd;
|
||||
va_list ap;
|
||||
char *msg;
|
||||
size_t msglen;
|
||||
@@ -137,198 +443,3 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
|
||||
|
||||
free(msg);
|
||||
}
|
||||
|
||||
/* Print a guard line. */
|
||||
void
|
||||
cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
|
||||
if (c == NULL || !(c->flags & CLIENT_CONTROL))
|
||||
return;
|
||||
|
||||
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
|
||||
(long) cmdq->time, cmdq->number, flags);
|
||||
server_client_push_stdout(c);
|
||||
}
|
||||
|
||||
/* Add command list to queue and begin processing if needed. */
|
||||
void
|
||||
cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
|
||||
{
|
||||
cmdq_append(cmdq, cmdlist, m);
|
||||
|
||||
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 mouse_event *m)
|
||||
{
|
||||
struct cmd_q_item *item;
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->cmdlist = cmdlist;
|
||||
TAILQ_INSERT_TAIL(&cmdq->queue, item, qentry);
|
||||
cmdlist->references++;
|
||||
|
||||
if (m != NULL)
|
||||
memcpy(&item->mouse, m, sizeof item->mouse);
|
||||
else
|
||||
item->mouse.valid = 0;
|
||||
}
|
||||
|
||||
/* Process one command. */
|
||||
static enum cmd_retval
|
||||
cmdq_continue_one(struct cmd_q *cmdq)
|
||||
{
|
||||
struct cmd *cmd = cmdq->cmd;
|
||||
const char *name = cmd->entry->name;
|
||||
struct session *s;
|
||||
struct hooks *hooks;
|
||||
enum cmd_retval retval;
|
||||
char *tmp;
|
||||
int flags = !!(cmd->flags & CMD_CONTROL);
|
||||
|
||||
tmp = cmd_print(cmd);
|
||||
log_debug("cmdq %p: %s", cmdq, tmp);
|
||||
free(tmp);
|
||||
|
||||
cmdq->time = time(NULL);
|
||||
cmdq->number++;
|
||||
|
||||
if (~cmdq->flags & CMD_Q_REENTRY)
|
||||
cmdq_guard(cmdq, "begin", flags);
|
||||
|
||||
if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
|
||||
goto error;
|
||||
|
||||
if (~cmdq->flags & CMD_Q_NOHOOKS) {
|
||||
s = NULL;
|
||||
if (cmdq->state.tflag.s != NULL)
|
||||
s = cmdq->state.tflag.s;
|
||||
else if (cmdq->state.sflag.s != NULL)
|
||||
s = cmdq->state.sflag.s;
|
||||
else if (cmdq->state.c != NULL)
|
||||
s = cmdq->state.c->session;
|
||||
if (s != NULL)
|
||||
hooks = s->hooks;
|
||||
else
|
||||
hooks = global_hooks;
|
||||
|
||||
if (~cmdq->flags & CMD_Q_REENTRY) {
|
||||
cmdq->flags |= CMD_Q_REENTRY;
|
||||
if (hooks_wait(hooks, cmdq, NULL,
|
||||
"before-%s", name) == 0)
|
||||
return (CMD_RETURN_WAIT);
|
||||
if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
hooks = NULL;
|
||||
cmdq->flags &= ~CMD_Q_REENTRY;
|
||||
|
||||
retval = cmd->entry->exec(cmd, cmdq);
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
goto error;
|
||||
|
||||
if (hooks != NULL && hooks_wait(hooks, cmdq, NULL,
|
||||
"after-%s", name) == 0)
|
||||
retval = CMD_RETURN_WAIT;
|
||||
cmdq_guard(cmdq, "end", flags);
|
||||
|
||||
return (retval);
|
||||
|
||||
error:
|
||||
cmdq_guard(cmdq, "error", flags);
|
||||
cmdq->flags &= ~CMD_Q_REENTRY;
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Continue processing command queue. Returns 1 if finishes empty. */
|
||||
int
|
||||
cmdq_continue(struct cmd_q *cmdq)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct cmd_q_item *next;
|
||||
enum cmd_retval retval;
|
||||
int empty;
|
||||
|
||||
cmdq->references++;
|
||||
notify_disable();
|
||||
|
||||
log_debug("continuing cmdq %p: flags %#x, client %p", cmdq, cmdq->flags,
|
||||
c);
|
||||
|
||||
empty = TAILQ_EMPTY(&cmdq->queue);
|
||||
if (empty)
|
||||
goto empty;
|
||||
|
||||
/*
|
||||
* If the command isn't in the middle of running hooks (due to
|
||||
* CMD_RETURN_WAIT), move onto the next command; otherwise, leave the
|
||||
* state of the queue as it is.
|
||||
*/
|
||||
if (~cmdq->flags & CMD_Q_REENTRY) {
|
||||
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 {
|
||||
while (cmdq->cmd != NULL) {
|
||||
retval = cmdq_continue_one(cmdq);
|
||||
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);
|
||||
}
|
||||
next = TAILQ_NEXT(cmdq->item, 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);
|
||||
empty = 1;
|
||||
|
||||
out:
|
||||
notify_enable();
|
||||
cmdq_free(cmdq);
|
||||
|
||||
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,7 +24,8 @@
|
||||
* Refresh client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_refresh_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.name = "refresh-client",
|
||||
@@ -35,34 +36,34 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_refresh_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
const char *size;
|
||||
u_int w, h;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
if ((size = args_get(args, 'C')) == NULL) {
|
||||
cmdq_error(cmdq, "missing size");
|
||||
cmdq_error(item, "missing size");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (sscanf(size, "%u,%u", &w, &h) != 2) {
|
||||
cmdq_error(cmdq, "bad size argument");
|
||||
cmdq_error(item, "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");
|
||||
cmdq_error(item, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!(c->flags & CLIENT_CONTROL)) {
|
||||
cmdq_error(cmdq, "not a control client");
|
||||
cmdq_error(item, "not a control client");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (tty_set_size(&c->tty, w, h))
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,7 +27,8 @@
|
||||
* Change session name.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_rename_session_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_rename_session_entry = {
|
||||
.name = "rename-session",
|
||||
@@ -37,24 +39,27 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct session *s = item->state.tflag.s;
|
||||
const char *newname;
|
||||
|
||||
newname = args->argv[0];
|
||||
if (strcmp(newname, s->name) == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (!session_check_name(newname)) {
|
||||
cmdq_error(cmdq, "bad session name: %s", newname);
|
||||
cmdq_error(item, "bad session name: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
cmdq_error(cmdq, "duplicate session: %s", newname);
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -64,7 +69,7 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
|
||||
server_status_session(s);
|
||||
notify_session_renamed(s);
|
||||
notify_session("session-renamed", s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
* Rename a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_rename_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_rename_window_entry = {
|
||||
.name = "rename-window",
|
||||
@@ -37,15 +38,15 @@ const struct cmd_entry cmd_rename_window_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
|
||||
window_set_name(wl->window, args->argv[0]);
|
||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
* Increase or decrease pane size.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_resize_pane_mouse_update(struct client *, struct mouse_event *);
|
||||
static void cmd_resize_pane_mouse_update(struct client *,
|
||||
struct mouse_event *);
|
||||
|
||||
const struct cmd_entry cmd_resize_pane_entry = {
|
||||
.name = "resize-pane",
|
||||
@@ -40,31 +41,31 @@ const struct cmd_entry cmd_resize_pane_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_resize_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct client *c = item->client;
|
||||
struct session *s = item->state.tflag.s;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust;
|
||||
int x, y;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if (cmd_mouse_window(&cmdq->item->mouse, &s) == NULL)
|
||||
if (cmd_mouse_window(&item->mouse, &s) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (c == NULL || c->session != s)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
|
||||
cmd_resize_pane_mouse_update(c, &cmdq->item->mouse);
|
||||
cmd_resize_pane_mouse_update(c, &item->mouse);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(cmdq, "adjustment %s", errstr);
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +94,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "width %s", cause);
|
||||
cmdq_error(item, "width %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -103,7 +104,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "height %s", cause);
|
||||
cmdq_error(item, "height %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -111,19 +112,19 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'L'))
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1);
|
||||
else if (args_has(self->args, 'R'))
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1);
|
||||
else if (args_has(self->args, 'U'))
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust);
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1);
|
||||
else if (args_has(self->args, 'D'))
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust, 1);
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
||||
{
|
||||
struct winlink *wl;
|
||||
@@ -154,13 +155,15 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
||||
continue;
|
||||
|
||||
if (wp->xoff + wp->sx == m->lx &&
|
||||
wp->yoff <= 1 + ly && wp->yoff + wp->sy >= ly) {
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx);
|
||||
wp->yoff <= 1 + ly &&
|
||||
wp->yoff + wp->sy >= ly) {
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx, 0);
|
||||
found = 1;
|
||||
}
|
||||
if (wp->yoff + wp->sy == ly &&
|
||||
wp->xoff <= 1 + m->lx && wp->xoff + wp->sx >= m->lx) {
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly);
|
||||
wp->xoff <= 1 + m->lx &&
|
||||
wp->xoff + wp->sx >= m->lx) {
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly, 0);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_q *);
|
||||
static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
.name = "respawn-pane",
|
||||
@@ -43,14 +43,14 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
.exec = cmd_respawn_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct environ *env;
|
||||
const char *path;
|
||||
char *cause;
|
||||
@@ -60,38 +60,35 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
||||
if (window_pane_index(wp, &idx) != 0)
|
||||
fatalx("index not found");
|
||||
cmdq_error(cmdq, "pane still active: %s:%d.%u",
|
||||
cmdq_error(item, "pane still active: %s:%d.%u",
|
||||
s->name, wl->idx, idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
env = environ_create();
|
||||
environ_copy(global_environ, env);
|
||||
environ_copy(s->environ, env);
|
||||
server_fill_environ(s, env);
|
||||
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(cmdq->client->environ, "PATH");
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
||||
s->tio, &cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn pane failed: %s", cause);
|
||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(env);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_free(env);
|
||||
|
||||
wp->flags |= PANE_REDRAW;
|
||||
server_status_window(w);
|
||||
|
||||
environ_free(env);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
* Respawn a window (restart the command). Kill existing if -k given.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_respawn_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.name = "respawn-window",
|
||||
@@ -42,12 +43,12 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.exec = cmd_respawn_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp;
|
||||
struct environ *env;
|
||||
@@ -59,17 +60,12 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
cmdq_error(cmdq, "window still active: %s:%d", s->name,
|
||||
cmdq_error(item, "window still active: %s:%d", s->name,
|
||||
wl->idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
env = environ_create();
|
||||
environ_copy(global_environ, env);
|
||||
environ_copy(s->environ, env);
|
||||
server_fill_environ(s, env);
|
||||
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
layout_free(w);
|
||||
@@ -78,21 +74,23 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(cmdq->client->environ, "PATH");
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
||||
s->tio, &cause) != 0) {
|
||||
cmdq_error(cmdq, "respawn window failed: %s", cause);
|
||||
cmdq_error(item, "respawn window failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(env);
|
||||
server_destroy_pane(wp, 0);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_free(env);
|
||||
layout_init(w, wp);
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
@@ -102,6 +100,5 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
recalculate_sizes();
|
||||
server_redraw_window(w);
|
||||
|
||||
environ_free(env);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
* Rotate the panes in a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_rotate_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_rotate_window_entry = {
|
||||
.name = "rotate-window",
|
||||
@@ -39,15 +40,17 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
.exec = cmd_rotate_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp, *wp2;
|
||||
struct layout_cell *lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args_has(self->args, 'D')) {
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
* Runs a command without a window.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_run_shell_callback(struct job *);
|
||||
void cmd_run_shell_free(void *);
|
||||
void cmd_run_shell_print(struct job *, const char *);
|
||||
static void cmd_run_shell_callback(struct job *);
|
||||
static void cmd_run_shell_free(void *);
|
||||
static void cmd_run_shell_print(struct job *, const char *);
|
||||
|
||||
const struct cmd_entry cmd_run_shell_entry = {
|
||||
.name = "run-shell",
|
||||
@@ -49,23 +49,30 @@ const struct cmd_entry cmd_run_shell_entry = {
|
||||
};
|
||||
|
||||
struct cmd_run_shell_data {
|
||||
char *cmd;
|
||||
struct cmd_q *cmdq;
|
||||
int bflag;
|
||||
int wp_id;
|
||||
char *cmd;
|
||||
struct cmdq_item *item;
|
||||
int wp_id;
|
||||
};
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_run_shell_print(struct job *job, const char *msg)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct window_pane *wp = NULL;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
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 (cdata->item != NULL) {
|
||||
cmdq_print(cdata->item, "%s", msg);
|
||||
return;
|
||||
}
|
||||
if (cmd_find_current (&fs, NULL, CMD_FIND_QUIET) != 0)
|
||||
return;
|
||||
wp = fs.wp;
|
||||
if (wp == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) == 0)
|
||||
@@ -74,65 +81,55 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
window_copy_add(wp, "%s", msg);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_run_shell_data *cdata;
|
||||
char *shellcmd;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct format_tree *ft;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
const char *cwd;
|
||||
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = NULL;
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, cmdq->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = shellcmd;
|
||||
cdata->bflag = args_has(args, 'b');
|
||||
cdata->wp_id = wp != NULL ? (int) wp->id : -1;
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
|
||||
cdata->cmdq = cmdq;
|
||||
cmdq->references++;
|
||||
if (args_has(args, 't') && wp != NULL)
|
||||
cdata->wp_id = wp->id;
|
||||
else
|
||||
cdata->wp_id = -1;
|
||||
|
||||
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
|
||||
job_run(cdata->cmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
cdata);
|
||||
|
||||
if (cdata->bflag)
|
||||
if (args_has(args, 'b'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_run_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
char *cmd, *msg, *line;
|
||||
char *cmd = cdata->cmd, *msg, *line;
|
||||
size_t size;
|
||||
int retcode;
|
||||
u_int lines;
|
||||
|
||||
if (cmdq->flags & CMD_Q_DEAD)
|
||||
return;
|
||||
cmd = cdata->cmd;
|
||||
|
||||
lines = 0;
|
||||
do {
|
||||
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||
cmd_run_shell_print(job, line);
|
||||
free(line);
|
||||
lines++;
|
||||
}
|
||||
} while (line != NULL);
|
||||
|
||||
@@ -143,7 +140,6 @@ cmd_run_shell_callback(struct job *job)
|
||||
line[size] = '\0';
|
||||
|
||||
cmd_run_shell_print(job, line);
|
||||
lines++;
|
||||
|
||||
free(line);
|
||||
}
|
||||
@@ -159,16 +155,15 @@ cmd_run_shell_callback(struct job *job)
|
||||
if (msg != NULL)
|
||||
cmd_run_shell_print(job, msg);
|
||||
free(msg);
|
||||
|
||||
if (cdata->item != NULL)
|
||||
cdata->item->flags &= ~CMDQ_WAITING;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_run_shell_free(void *data)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = data;
|
||||
struct cmd_q *cmdq = cdata->cmdq;
|
||||
|
||||
if (!cmdq_free(cmdq) && !cdata->bflag)
|
||||
cmdq_continue(cmdq);
|
||||
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
* Saves a paste buffer to a file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_save_buffer_entry = {
|
||||
.name = "save-buffer",
|
||||
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_save_buffer_entry = {
|
||||
.args = { "ab:", 1, 1 },
|
||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_save_buffer_exec
|
||||
};
|
||||
|
||||
@@ -51,33 +51,32 @@ const struct cmd_entry cmd_show_buffer_entry = {
|
||||
.args = { "b:", 0, 0 },
|
||||
.usage = CMD_BUFFER_USAGE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_save_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->client;
|
||||
struct session *s;
|
||||
struct client *c = item->client;
|
||||
struct paste_buffer *pb;
|
||||
const char *path, *bufname, *bufdata, *start, *end, *cwd;
|
||||
const char *path, *bufname, *bufdata, *start, *end;
|
||||
const char *flags;
|
||||
char *msg, *file, resolved[PATH_MAX];
|
||||
char *msg, *file;
|
||||
size_t size, used, msglen, bufsize;
|
||||
FILE *f;
|
||||
|
||||
if (!args_has(args, 'b')) {
|
||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
||||
cmdq_error(cmdq, "no buffers");
|
||||
cmdq_error(item, "no buffers");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
bufname = args_get(args, 'b');
|
||||
pb = paste_get_name(bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(cmdq, "no buffer %s", bufname);
|
||||
cmdq_error(item, "no buffer %s", bufname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -89,7 +88,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
path = args->argv[0];
|
||||
if (strcmp(path, "-") == 0) {
|
||||
if (c == NULL) {
|
||||
cmdq_error(cmdq, "can't write to stdout");
|
||||
cmdq_error(item, "can't write to stdout");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
||||
@@ -97,39 +96,26 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
goto do_print;
|
||||
}
|
||||
|
||||
if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = c->cwd;
|
||||
else if ((s = c->session) != NULL && s->cwd != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = ".";
|
||||
|
||||
flags = "wb";
|
||||
if (args_has(self->args, 'a'))
|
||||
flags = "ab";
|
||||
|
||||
if (*path == '/')
|
||||
file = xstrdup(path);
|
||||
else
|
||||
xasprintf(&file, "%s/%s", cwd, path);
|
||||
if (realpath(file, resolved) == NULL &&
|
||||
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) {
|
||||
cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
f = fopen(resolved, flags);
|
||||
free(file);
|
||||
file = server_client_get_path(c, path);
|
||||
f = fopen(file, flags);
|
||||
if (f == NULL) {
|
||||
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
free(file);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
|
||||
cmdq_error(cmdq, "%s: write error", resolved);
|
||||
cmdq_error(item, "%s: write error", file);
|
||||
fclose(f);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
free(file);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -140,7 +126,7 @@ do_stdout:
|
||||
|
||||
do_print:
|
||||
if (bufsize > (INT_MAX / 4) - 1) {
|
||||
cmdq_error(cmdq, "buffer too big");
|
||||
cmdq_error(item, "buffer too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
msg = NULL;
|
||||
@@ -158,7 +144,7 @@ do_print:
|
||||
msg = xrealloc(msg, msglen);
|
||||
|
||||
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
|
||||
cmdq_print(cmdq, "%s", msg);
|
||||
cmdq_print(item, "%s", msg);
|
||||
|
||||
used += size + (end != NULL);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
* Switch window to selected layout.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_select_layout_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_select_layout_entry = {
|
||||
.name = "select-layout",
|
||||
@@ -37,7 +38,7 @@ const struct cmd_entry cmd_select_layout_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
};
|
||||
|
||||
@@ -50,7 +51,7 @@ const struct cmd_entry cmd_next_layout_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
};
|
||||
|
||||
@@ -63,15 +64,15 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w;
|
||||
const char *layoutname;
|
||||
char *oldlayout;
|
||||
@@ -118,7 +119,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (layoutname != NULL) {
|
||||
if (layout_parse(w, layoutname) == -1) {
|
||||
cmdq_error(cmdq, "can't set layout: %s", layoutname);
|
||||
cmdq_error(item, "can't set layout: %s", layoutname);
|
||||
goto error;
|
||||
}
|
||||
goto changed;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Select pane.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_select_pane_entry = {
|
||||
.name = "select-pane",
|
||||
@@ -52,20 +52,19 @@ const struct cmd_entry cmd_last_pane_entry = {
|
||||
.exec = cmd_select_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp, *lastwp, *markedwp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
|
||||
const char *style;
|
||||
|
||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
|
||||
if (wl->window->last == NULL) {
|
||||
cmdq_error(cmdq, "no last pane");
|
||||
cmdq_error(item, "no last pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -112,13 +111,13 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
style = args_get(args, 'P');
|
||||
if (style_parse(&grid_default_cell, &wp->colgc,
|
||||
style) == -1) {
|
||||
cmdq_error(cmdq, "bad style: %s", style);
|
||||
cmdq_error(item, "bad style: %s", style);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
wp->flags |= PANE_REDRAW;
|
||||
}
|
||||
if (args_has(self->args, 'g'))
|
||||
cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
|
||||
cmdq_print(item, "%s", style_tostring(&wp->colgc));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
server_unzoom_window(wp->window);
|
||||
if (!window_pane_visible(wp)) {
|
||||
cmdq_error(cmdq, "pane not visible");
|
||||
cmdq_error(item, "pane not visible");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
window_redraw_active_switch(w, wp);
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
* Select window by index.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_select_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_select_window_entry = {
|
||||
.name = "select-window",
|
||||
@@ -80,11 +81,11 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
.exec = cmd_select_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct session *s = item->state.tflag.s;
|
||||
int next, previous, last, activity;
|
||||
|
||||
next = self->entry == &cmd_next_window_entry;
|
||||
@@ -101,17 +102,17 @@ cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
activity = args_has(self->args, 'a');
|
||||
if (next) {
|
||||
if (session_next(s, activity) != 0) {
|
||||
cmdq_error(cmdq, "no next window");
|
||||
cmdq_error(item, "no next window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (previous) {
|
||||
if (session_previous(s, activity) != 0) {
|
||||
cmdq_error(cmdq, "no previous window");
|
||||
cmdq_error(item, "no previous window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (session_last(s) != 0) {
|
||||
cmdq_error(cmdq, "no last window");
|
||||
cmdq_error(item, "no last window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +125,7 @@ cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
*/
|
||||
if (args_has(self->args, 'T') && wl == s->curw) {
|
||||
if (session_last(s) != 0) {
|
||||
cmdq_error(cmdq, "no last window");
|
||||
cmdq_error(item, "no last window");
|
||||
return (-1);
|
||||
}
|
||||
server_redraw_session(s);
|
||||
|
||||
@@ -27,18 +27,18 @@
|
||||
* Send keys to client.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_send_keys_entry = {
|
||||
.name = "send-keys",
|
||||
.alias = "send",
|
||||
|
||||
.args = { "lRMt:", 0, -1 },
|
||||
.usage = "[-lRM] " CMD_TARGET_PANE_USAGE " key ...",
|
||||
.args = { "lXRMN:t:", 0, -1 },
|
||||
.usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_send_keys_exec
|
||||
};
|
||||
|
||||
@@ -51,25 +51,52 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_send_keys_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct mouse_event *m = &cmdq->item->mouse;
|
||||
const u_char *keystr;
|
||||
struct client *c = item->state.c;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct mouse_event *m = &item->mouse;
|
||||
struct utf8_data *ud, *uc;
|
||||
wchar_t wc;
|
||||
int i, literal;
|
||||
key_code key;
|
||||
u_int np = 1;
|
||||
char *cause = NULL;
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "repeat count %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(args, 'X') || args->argc == 0)
|
||||
wp->modeprefix = np;
|
||||
}
|
||||
|
||||
if (args_has(args, 'X')) {
|
||||
if (wp->mode == NULL || wp->mode->command == NULL) {
|
||||
cmdq_error(item, "not in a mode");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!m->valid)
|
||||
wp->mode->command(wp, c, s, args, NULL);
|
||||
else
|
||||
wp->mode->command(wp, c, s, args, m);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
wp = cmd_mouse_pane(m, &s, NULL);
|
||||
if (wp == NULL) {
|
||||
cmdq_error(cmdq, "no mouse target");
|
||||
cmdq_error(item, "no mouse target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
window_pane_key(wp, NULL, s, m->key, m);
|
||||
@@ -85,22 +112,32 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'R'))
|
||||
if (args_has(args, 'R')) {
|
||||
window_pane_reset_palette(wp);
|
||||
input_reset(wp, 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
literal = args_has(args, 'l');
|
||||
if (!literal) {
|
||||
key = key_string_lookup_string(args->argv[i]);
|
||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN)
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
else
|
||||
literal = 1;
|
||||
}
|
||||
if (literal) {
|
||||
for (keystr = args->argv[i]; *keystr != '\0'; keystr++)
|
||||
window_pane_key(wp, NULL, s, *keystr, NULL);
|
||||
for (; np != 0; np--) {
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
literal = args_has(args, 'l');
|
||||
if (!literal) {
|
||||
key = key_string_lookup_string(args->argv[i]);
|
||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN)
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
else
|
||||
literal = 1;
|
||||
}
|
||||
if (literal) {
|
||||
ud = utf8_fromcstr(args->argv[i]);
|
||||
for (uc = ud; uc->size != 0; uc++) {
|
||||
if (utf8_combine(uc, &wc) != UTF8_DONE)
|
||||
continue;
|
||||
window_pane_key(wp, NULL, s, wc, NULL);
|
||||
}
|
||||
free(ud);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Add, set, append to or delete a paste buffer.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_set_buffer_entry = {
|
||||
.name = "set-buffer",
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
|
||||
.args = { "ab:n:", 0, 1 },
|
||||
.usage = "[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_buffer_exec
|
||||
};
|
||||
|
||||
@@ -47,12 +47,12 @@ const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
.args = { "b:", 0, 0 },
|
||||
.usage = CMD_BUFFER_USAGE,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_buffer_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct paste_buffer *pb;
|
||||
@@ -70,7 +70,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (pb == NULL)
|
||||
pb = paste_get_top(&bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(cmdq, "no buffer");
|
||||
cmdq_error(item, "no buffer");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
paste_free(pb);
|
||||
@@ -81,11 +81,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (pb == NULL)
|
||||
pb = paste_get_top(&bufname);
|
||||
if (pb == NULL) {
|
||||
cmdq_error(cmdq, "no buffer");
|
||||
cmdq_error(item, "no buffer");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
if (args->argc != 1) {
|
||||
cmdq_error(cmdq, "no data specified");
|
||||
cmdq_error(item, "no data specified");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((newsize = strlen(args->argv[0])) == 0)
|
||||
@@ -113,7 +113,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
bufsize += newsize;
|
||||
|
||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(bufdata);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
* Set an environment variable.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_set_environment_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_set_environment_entry = {
|
||||
.name = "set-environment",
|
||||
@@ -38,12 +39,12 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_environment_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct environ *env;
|
||||
@@ -51,11 +52,11 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
name = args->argv[0];
|
||||
if (*name == '\0') {
|
||||
cmdq_error(cmdq, "empty variable name");
|
||||
cmdq_error(item, "empty variable name");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (strchr(name, '=') != NULL) {
|
||||
cmdq_error(cmdq, "variable name contains =");
|
||||
cmdq_error(item, "variable name contains =");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -67,32 +68,32 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (cmdq->state.tflag.s == NULL) {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(cmdq, "no current session");
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
env = cmdq->state.tflag.s->environ;
|
||||
env = item->state.tflag.s->environ;
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'u')) {
|
||||
if (value != NULL) {
|
||||
cmdq_error(cmdq, "can't specify a value with -u");
|
||||
cmdq_error(item, "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) {
|
||||
cmdq_error(cmdq, "can't specify a value with -r");
|
||||
cmdq_error(item, "can't specify a value with -r");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_clear(env, name);
|
||||
} else {
|
||||
if (value == NULL) {
|
||||
cmdq_error(cmdq, "no value specified");
|
||||
cmdq_error(item, "no value specified");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_set(env, name, "%s", value);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Set or show global or session hooks.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_set_hook_entry = {
|
||||
.name = "set-hook",
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_set_hook_entry = {
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
};
|
||||
|
||||
@@ -51,12 +51,12 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_list *cmdlist;
|
||||
@@ -68,22 +68,22 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'g'))
|
||||
hooks = global_hooks;
|
||||
else {
|
||||
if (cmdq->state.tflag.s == NULL) {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(cmdq, "no current session");
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
hooks = cmdq->state.tflag.s->hooks;
|
||||
hooks = item->state.tflag.s->hooks;
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_show_hooks_entry) {
|
||||
hook = hooks_first(hooks);
|
||||
while (hook != NULL) {
|
||||
tmp = cmd_list_print(hook->cmdlist);
|
||||
cmdq_print(cmdq, "%s -> %s", hook->name, tmp);
|
||||
cmdq_print(item, "%s -> %s", hook->name, tmp);
|
||||
free(tmp);
|
||||
|
||||
hook = hooks_next(hook);
|
||||
@@ -93,7 +93,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
name = args->argv[0];
|
||||
if (*name == '\0') {
|
||||
cmdq_error(cmdq, "invalid hook name");
|
||||
cmdq_error(item, "invalid hook name");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args->argc < 2)
|
||||
@@ -103,7 +103,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
if (cmd != NULL) {
|
||||
cmdq_error(cmdq, "command passed to unset hook: %s",
|
||||
cmdq_error(item, "command passed to unset hook: %s",
|
||||
name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -112,12 +112,13 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
if (cmd == NULL) {
|
||||
cmdq_error(cmdq, "no command to set hook: %s", name);
|
||||
cmdq_error(item, "no command to set hook: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(cmdq, "%s", cause);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
633
cmd-set-option.c
633
cmd-set-option.c
@@ -27,42 +27,16 @@
|
||||
* Set an option.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
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_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
|
||||
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_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
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_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
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_q *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
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 *);
|
||||
static int cmd_set_option_set(struct cmd *, struct cmdq_item *,
|
||||
struct options *, struct options_entry *, const char *);
|
||||
static int cmd_set_option_flag(struct cmdq_item *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
static int cmd_set_option_choice(struct cmdq_item *,
|
||||
const struct options_table_entry *, struct options *,
|
||||
const char *);
|
||||
|
||||
const struct cmd_entry cmd_set_option_entry = {
|
||||
.name = "set-option",
|
||||
@@ -73,7 +47,7 @@ const struct cmd_entry cmd_set_option_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_option_exec
|
||||
};
|
||||
|
||||
@@ -86,133 +60,201 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_option_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct window *w;
|
||||
struct client *c;
|
||||
const struct options_table_entry *oe;
|
||||
struct options *oo;
|
||||
const char *optstr, *valstr, *target;
|
||||
struct args *args = self->args;
|
||||
int append = args_has(args, 'a');
|
||||
struct cmd_find_state *fs = &item->state.tflag;
|
||||
struct session *s = fs->s;
|
||||
struct winlink *wl = fs->wl;
|
||||
struct window *w;
|
||||
struct client *c;
|
||||
enum options_table_scope scope;
|
||||
struct options *oo;
|
||||
struct options_entry *parent, *o;
|
||||
const char *name, *value, *target;
|
||||
int window, idx, already, error, ambiguous;
|
||||
char *cause;
|
||||
|
||||
/* Get the option name and value. */
|
||||
optstr = args->argv[0];
|
||||
if (*optstr == '\0') {
|
||||
cmdq_error(cmdq, "invalid option");
|
||||
/* Parse option name and index. */
|
||||
name = options_match(args->argv[0], &idx, &ambiguous);
|
||||
if (name == NULL) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (ambiguous)
|
||||
cmdq_error(item, "ambiguous option: %s", args->argv[0]);
|
||||
else
|
||||
cmdq_error(item, "invalid option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args->argc < 2)
|
||||
valstr = NULL;
|
||||
value = NULL;
|
||||
else
|
||||
valstr = args->argv[1];
|
||||
value = 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. */
|
||||
oe = NULL;
|
||||
if (options_table_find(optstr, &oe) != 0) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "ambiguous option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
/*
|
||||
* Figure out the scope: for user options it comes from the arguments,
|
||||
* otherwise from the option name.
|
||||
*/
|
||||
if (*name == '@') {
|
||||
window = (self->entry == &cmd_set_window_option_entry);
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
} else {
|
||||
if (options_get_only(global_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_SERVER;
|
||||
else if (options_get_only(global_s_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_SESSION;
|
||||
else if (options_get_only(global_w_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_WINDOW;
|
||||
else {
|
||||
scope = OPTIONS_TABLE_NONE;
|
||||
xasprintf(&cause, "unknown option: %s", args->argv[0]);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (oe == NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Work out the tree from the scope of the option. */
|
||||
if (oe->scope == OPTIONS_TABLE_SERVER)
|
||||
/* Which table should this option go into? */
|
||||
if (scope == OPTIONS_TABLE_SERVER)
|
||||
oo = global_options;
|
||||
else if (oe->scope == OPTIONS_TABLE_WINDOW) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_w_options;
|
||||
else if (wl == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(cmdq, "no such window: %s",
|
||||
target);
|
||||
} else
|
||||
cmdq_error(cmdq, "no current window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
oo = wl->window->options;
|
||||
} else if (oe->scope == OPTIONS_TABLE_SESSION) {
|
||||
else if (scope == OPTIONS_TABLE_SESSION) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_s_options;
|
||||
else if (s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(cmdq, "no such session: %s",
|
||||
target);
|
||||
} else
|
||||
cmdq_error(cmdq, "no current session");
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
oo = s->options;
|
||||
} else {
|
||||
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, cmdq, oe, oo, valstr) != 0)
|
||||
} else if (scope == OPTIONS_TABLE_WINDOW) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_w_options;
|
||||
else if (wl == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such window: %s", target);
|
||||
else
|
||||
cmdq_error(item, "no current window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
oo = wl->window->options;
|
||||
}
|
||||
o = options_get_only(oo, name);
|
||||
parent = options_get(oo, name);
|
||||
|
||||
/* Check that array options and indexes match up. */
|
||||
if (idx != -1) {
|
||||
if (*name == '@' || options_array_size(parent, NULL) == -1) {
|
||||
cmdq_error(item, "not an array: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "already set: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Start or stop timers if necessary. */
|
||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||
/* With -o, check this option is not already set. */
|
||||
if (!args_has(args, 'u') && args_has(args, 'o')) {
|
||||
if (idx == -1)
|
||||
already = (o != NULL);
|
||||
else {
|
||||
if (o == NULL)
|
||||
already = 0;
|
||||
else
|
||||
already = (options_array_get(o, idx) != NULL);
|
||||
}
|
||||
if (already) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(item, "already set: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Change the option. */
|
||||
if (args_has(args, 'u')) {
|
||||
if (o == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (idx == -1) {
|
||||
if (oo == global_options ||
|
||||
oo == global_s_options ||
|
||||
oo == global_w_options)
|
||||
options_default(oo, options_table_entry(o));
|
||||
else
|
||||
options_remove(o);
|
||||
} else
|
||||
options_array_set(o, idx, NULL, 0);
|
||||
} else if (*name == '@') {
|
||||
if (value == NULL) {
|
||||
cmdq_error(item, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
options_set_string(oo, name, append, "%s", value);
|
||||
} else if (idx == -1 && options_array_size(parent, NULL) == -1) {
|
||||
error = cmd_set_option_set(self, item, oo, parent, value);
|
||||
if (error != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else {
|
||||
if (value == NULL) {
|
||||
cmdq_error(item, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (o == NULL)
|
||||
o = options_empty(oo, options_table_entry(parent));
|
||||
if (idx == -1) {
|
||||
if (!append)
|
||||
options_array_clear(o);
|
||||
options_array_assign(o, value);
|
||||
} else if (options_array_set(o, idx, value, append) != 0) {
|
||||
cmdq_error(item, "invalid index: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update timers and so on for various options. */
|
||||
if (strcmp(name, "automatic-rename") == 0) {
|
||||
RB_FOREACH(w, windows, &windows) {
|
||||
if (w->active == NULL)
|
||||
continue;
|
||||
if (options_get_number(w->options, "automatic-rename"))
|
||||
w->active->flags |= PANE_CHANGED;
|
||||
}
|
||||
}
|
||||
if (strcmp(oe->name, "key-table") == 0) {
|
||||
if (strcmp(name, "key-table") == 0) {
|
||||
TAILQ_FOREACH(c, &clients, entry)
|
||||
server_client_set_key_table(c, NULL);
|
||||
}
|
||||
if (strcmp(oe->name, "status") == 0 ||
|
||||
strcmp(oe->name, "status-interval") == 0)
|
||||
if (strcmp(name, "status") == 0 ||
|
||||
strcmp(name, "status-interval") == 0)
|
||||
status_timer_start_all();
|
||||
if (strcmp(oe->name, "monitor-silence") == 0)
|
||||
if (strcmp(name, "monitor-silence") == 0)
|
||||
alerts_reset_all();
|
||||
if (strcmp(oe->name, "window-style") == 0 ||
|
||||
strcmp(oe->name, "window-active-style") == 0) {
|
||||
if (strcmp(name, "window-style") == 0 ||
|
||||
strcmp(name, "window-active-style") == 0) {
|
||||
RB_FOREACH(w, windows, &windows)
|
||||
w->flags |= WINDOW_STYLECHANGED;
|
||||
}
|
||||
|
||||
/* When the pane-border-status option has been changed, resize panes. */
|
||||
if (strcmp(oe->name, "pane-border-status") == 0) {
|
||||
if (strcmp(name, "pane-border-status") == 0) {
|
||||
RB_FOREACH(w, windows, &windows)
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
}
|
||||
RB_FOREACH (s, sessions, &sessions)
|
||||
status_update_saved(s);
|
||||
|
||||
/* Update sizes and redraw. May not need it but meh. */
|
||||
/*
|
||||
* Update sizes and redraw. May not always be necessary but do it
|
||||
* anyway.
|
||||
*/
|
||||
recalculate_sizes();
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != NULL)
|
||||
@@ -222,244 +264,82 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
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)
|
||||
static int
|
||||
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
struct options_entry *parent, const char *value)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct options *oo;
|
||||
struct options_entry *o;
|
||||
const struct options_table_entry *oe;
|
||||
struct args *args = self->args;
|
||||
int append = args_has(args, 'a');
|
||||
struct options_entry *o;
|
||||
long long number;
|
||||
const char *errstr;
|
||||
key_code key;
|
||||
|
||||
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
|
||||
oo = wl->window->options;
|
||||
} else {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_s_options;
|
||||
else
|
||||
oo = s->options;
|
||||
}
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
if (options_find1(oo, optstr) == NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "unknown option: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (valstr != NULL) {
|
||||
cmdq_error(cmdq, "value passed to unset option: %s",
|
||||
optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
options_remove(oo, optstr);
|
||||
} else {
|
||||
o = options_find1(oo, optstr);
|
||||
if (args_has(args, 'o') && o != NULL) {
|
||||
if (!args_has(args, 'q')) {
|
||||
cmdq_error(cmdq, "already set: %s", optstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (valstr == NULL) {
|
||||
cmdq_error(cmdq, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (o != NULL && args_has(args, 'a'))
|
||||
options_set_string(oo, optstr, "%s%s", o->str, valstr);
|
||||
else
|
||||
options_set_string(oo, optstr, "%s", valstr);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Unset an option. */
|
||||
int
|
||||
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 (value != NULL) {
|
||||
cmdq_error(cmdq, "value passed to unset option: %s", oe->name);
|
||||
oe = options_table_entry(parent);
|
||||
if (value == NULL &&
|
||||
oe->type != OPTIONS_TABLE_FLAG &&
|
||||
oe->type != OPTIONS_TABLE_CHOICE) {
|
||||
cmdq_error(item, "empty value");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (args_has(args, 'g') || oo == global_options) {
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_STRING:
|
||||
options_set_string(oo, oe->name, "%s", oe->default_str);
|
||||
break;
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
options_set_style(oo, oe->name, oe->default_str, 0);
|
||||
break;
|
||||
default:
|
||||
options_set_number(oo, oe->name, oe->default_num);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
options_remove(oo, oe->name);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set an option. */
|
||||
int
|
||||
cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
struct options_entry *o;
|
||||
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
case OPTIONS_TABLE_CHOICE:
|
||||
break;
|
||||
default:
|
||||
if (value == NULL) {
|
||||
cmdq_error(cmdq, "empty value");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
o = NULL;
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_STRING:
|
||||
o = cmd_set_option_string(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
options_set_string(oo, oe->name, append, "%s", value);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_NUMBER:
|
||||
o = cmd_set_option_number(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
number = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "value is %s: %s", errstr, value);
|
||||
return (-1);
|
||||
}
|
||||
options_set_number(oo, oe->name, number);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_KEY:
|
||||
o = cmd_set_option_key(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
key = key_string_lookup_string(value);
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "bad key: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
options_set_number(oo, oe->name, key);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_COLOUR:
|
||||
o = cmd_set_option_colour(self, cmdq, oe, oo, value);
|
||||
if (o != NULL)
|
||||
style_update_new(oo, o->name, oe->style);
|
||||
break;
|
||||
if ((number = colour_fromstring(value)) == -1) {
|
||||
cmdq_error(item, "bad colour: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
o = options_set_number(oo, oe->name, number);
|
||||
options_style_update_new(oo, o);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_ATTRIBUTES:
|
||||
o = cmd_set_option_attributes(self, cmdq, oe, oo, value);
|
||||
if (o != NULL)
|
||||
style_update_new(oo, o->name, oe->style);
|
||||
break;
|
||||
if ((number = attributes_fromstring(value)) == -1) {
|
||||
cmdq_error(item, "bad attributes: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
o = options_set_number(oo, oe->name, number);
|
||||
options_style_update_new(oo, o);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
o = cmd_set_option_flag(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
return (cmd_set_option_flag(item, oe, oo, value));
|
||||
case OPTIONS_TABLE_CHOICE:
|
||||
o = cmd_set_option_choice(self, cmdq, oe, oo, value);
|
||||
break;
|
||||
return (cmd_set_option_choice(item, oe, oo, value));
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
o = cmd_set_option_style(self, cmdq, oe, oo, value);
|
||||
o = options_set_style(oo, oe->name, append, value);
|
||||
if (o == NULL) {
|
||||
cmdq_error(item, "bad style: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
options_style_update_old(oo, o);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_ARRAY:
|
||||
break;
|
||||
}
|
||||
if (o == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set a string option. */
|
||||
struct options_entry *
|
||||
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;
|
||||
struct options_entry *o;
|
||||
char *oldval, *newval;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
oldval = options_get_string(oo, oe->name);
|
||||
xasprintf(&newval, "%s%s", oldval, value);
|
||||
} else
|
||||
newval = xstrdup(value);
|
||||
|
||||
o = options_set_string(oo, oe->name, "%s", newval);
|
||||
|
||||
free(newval);
|
||||
return (o);
|
||||
}
|
||||
|
||||
/* Set a number option. */
|
||||
struct options_entry *
|
||||
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;
|
||||
const char *errstr;
|
||||
|
||||
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(cmdq, "value is %s: %s", errstr, value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, ll));
|
||||
}
|
||||
|
||||
/* Set a key option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
key_code key;
|
||||
|
||||
key = key_string_lookup_string(value);
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
cmdq_error(cmdq, "bad key: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, key));
|
||||
}
|
||||
|
||||
/* Set a colour option. */
|
||||
struct options_entry *
|
||||
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) {
|
||||
cmdq_error(cmdq, "bad colour: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, colour));
|
||||
}
|
||||
|
||||
/* Set an attributes option. */
|
||||
struct options_entry *
|
||||
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) {
|
||||
cmdq_error(cmdq, "bad attributes: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, attr));
|
||||
}
|
||||
|
||||
/* Set a flag option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq,
|
||||
static int
|
||||
cmd_set_option_flag(struct cmdq_item *item,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
@@ -467,31 +347,28 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq,
|
||||
|
||||
if (value == NULL || *value == '\0')
|
||||
flag = !options_get_number(oo, oe->name);
|
||||
else if (strcmp(value, "1") == 0 ||
|
||||
strcasecmp(value, "on") == 0 ||
|
||||
strcasecmp(value, "yes") == 0)
|
||||
flag = 1;
|
||||
else if (strcmp(value, "0") == 0 ||
|
||||
strcasecmp(value, "off") == 0 ||
|
||||
strcasecmp(value, "no") == 0)
|
||||
flag = 0;
|
||||
else {
|
||||
if ((value[0] == '1' && value[1] == '\0') ||
|
||||
strcasecmp(value, "on") == 0 ||
|
||||
strcasecmp(value, "yes") == 0)
|
||||
flag = 1;
|
||||
else if ((value[0] == '0' && value[1] == '\0') ||
|
||||
strcasecmp(value, "off") == 0 ||
|
||||
strcasecmp(value, "no") == 0)
|
||||
flag = 0;
|
||||
else {
|
||||
cmdq_error(cmdq, "bad value: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
cmdq_error(item, "bad value: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (options_set_number(oo, oe->name, flag));
|
||||
options_set_number(oo, oe->name, flag);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set a choice option. */
|
||||
struct options_entry *
|
||||
cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq,
|
||||
static int
|
||||
cmd_set_option_choice(struct cmdq_item *item,
|
||||
const struct options_table_entry *oe, struct options *oo,
|
||||
const char *value)
|
||||
{
|
||||
const char **choicep;
|
||||
const char **cp;
|
||||
int n, choice = -1;
|
||||
|
||||
if (value == NULL) {
|
||||
@@ -500,42 +377,16 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq,
|
||||
choice = !choice;
|
||||
} else {
|
||||
n = 0;
|
||||
for (choicep = oe->choices; *choicep != NULL; choicep++) {
|
||||
for (cp = oe->choices; *cp != NULL; cp++) {
|
||||
if (strcmp(*cp, value) == 0)
|
||||
choice = n;
|
||||
n++;
|
||||
if (strncmp(*choicep, value, strlen(value)) != 0)
|
||||
continue;
|
||||
|
||||
if (choice != -1) {
|
||||
cmdq_error(cmdq, "ambiguous value: %s", value);
|
||||
return (NULL);
|
||||
}
|
||||
choice = n - 1;
|
||||
}
|
||||
if (choice == -1) {
|
||||
cmdq_error(cmdq, "unknown value: %s", value);
|
||||
return (NULL);
|
||||
cmdq_error(item, "unknown value: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
options_set_number(oo, oe->name, choice);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
* Show environment.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_show_environment_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
char *cmd_show_environment_escape(struct environ_entry *);
|
||||
void cmd_show_environment_print(struct cmd *, struct cmd_q *,
|
||||
struct environ_entry *);
|
||||
static char *cmd_show_environment_escape(struct environ_entry *);
|
||||
static void cmd_show_environment_print(struct cmd *, struct cmdq_item *,
|
||||
struct environ_entry *);
|
||||
|
||||
const struct cmd_entry cmd_show_environment_entry = {
|
||||
.name = "show-environment",
|
||||
@@ -42,11 +43,11 @@ const struct cmd_entry cmd_show_environment_entry = {
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_environment_exec
|
||||
};
|
||||
|
||||
char *
|
||||
static char *
|
||||
cmd_show_environment_escape(struct environ_entry *envent)
|
||||
{
|
||||
const char *value = envent->value;
|
||||
@@ -64,31 +65,31 @@ cmd_show_environment_escape(struct environ_entry *envent)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_show_environment_print(struct cmd *self, struct cmd_q *cmdq,
|
||||
static void
|
||||
cmd_show_environment_print(struct cmd *self, struct cmdq_item *item,
|
||||
struct environ_entry *envent)
|
||||
{
|
||||
char *escaped;
|
||||
|
||||
if (!args_has(self->args, 's')) {
|
||||
if (envent->value != NULL)
|
||||
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
|
||||
cmdq_print(item, "%s=%s", envent->name, envent->value);
|
||||
else
|
||||
cmdq_print(cmdq, "-%s", envent->name);
|
||||
cmdq_print(item, "-%s", envent->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (envent->value != NULL) {
|
||||
escaped = cmd_show_environment_escape(envent);
|
||||
cmdq_print(cmdq, "%s=\"%s\"; export %s;", envent->name, escaped,
|
||||
cmdq_print(item, "%s=\"%s\"; export %s;", envent->name, escaped,
|
||||
envent->name);
|
||||
free(escaped);
|
||||
} else
|
||||
cmdq_print(cmdq, "unset %s;", envent->name);
|
||||
cmdq_print(item, "unset %s;", envent->name);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct environ *env;
|
||||
@@ -96,8 +97,8 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
const char *target;
|
||||
|
||||
if ((target = args_get(args, 't')) != NULL) {
|
||||
if (cmdq->state.tflag.s == NULL) {
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
if (item->state.tflag.s == NULL) {
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -105,30 +106,30 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (cmdq->state.tflag.s == NULL) {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(cmdq, "no current session");
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
env = cmdq->state.tflag.s->environ;
|
||||
env = item->state.tflag.s->environ;
|
||||
}
|
||||
|
||||
if (args->argc != 0) {
|
||||
envent = environ_find(env, args->argv[0]);
|
||||
if (envent == NULL) {
|
||||
cmdq_error(cmdq, "unknown variable: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown variable: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmd_show_environment_print(self, cmdq, envent);
|
||||
cmd_show_environment_print(self, item, envent);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
envent = environ_first(env);
|
||||
while (envent != NULL) {
|
||||
cmd_show_environment_print(self, cmdq, envent);
|
||||
cmd_show_environment_print(self, item, envent);
|
||||
envent = environ_next(envent);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
* Show client message log.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_show_messages_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_show_messages_entry = {
|
||||
.name = "show-messages",
|
||||
@@ -39,26 +40,15 @@ const struct cmd_entry cmd_show_messages_entry = {
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_messages_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_server_info_entry = {
|
||||
.name = "server-info",
|
||||
.alias = "info",
|
||||
static int cmd_show_messages_terminals(struct cmdq_item *, int);
|
||||
static int cmd_show_messages_jobs(struct cmdq_item *, int);
|
||||
|
||||
.args = { "", 0, 0 },
|
||||
.usage = "",
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_show_messages_exec
|
||||
};
|
||||
|
||||
int cmd_show_messages_terminals(struct cmd_q *, int);
|
||||
int cmd_show_messages_jobs(struct cmd_q *, int);
|
||||
|
||||
int
|
||||
cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
|
||||
static int
|
||||
cmd_show_messages_terminals(struct cmdq_item *item, int blank)
|
||||
{
|
||||
struct tty_term *term;
|
||||
u_int i, n;
|
||||
@@ -66,20 +56,20 @@ cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
|
||||
n = 0;
|
||||
LIST_FOREACH(term, &tty_terms, entry) {
|
||||
if (blank) {
|
||||
cmdq_print(cmdq, "%s", "");
|
||||
cmdq_print(item, "%s", "");
|
||||
blank = 0;
|
||||
}
|
||||
cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:",
|
||||
cmdq_print(item, "Terminal %u: %s [references=%u, flags=0x%x]:",
|
||||
n, term->name, term->references, term->flags);
|
||||
n++;
|
||||
for (i = 0; i < tty_term_ncodes(); i++)
|
||||
cmdq_print(cmdq, "%s", tty_term_describe(term, i));
|
||||
cmdq_print(item, "%s", tty_term_describe(term, i));
|
||||
}
|
||||
return (n != 0);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
|
||||
static int
|
||||
cmd_show_messages_jobs(struct cmdq_item *item, int blank)
|
||||
{
|
||||
struct job *job;
|
||||
u_int n;
|
||||
@@ -87,32 +77,32 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
|
||||
n = 0;
|
||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||
if (blank) {
|
||||
cmdq_print(cmdq, "%s", "");
|
||||
cmdq_print(item, "%s", "");
|
||||
blank = 0;
|
||||
}
|
||||
cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]",
|
||||
n, job->cmd, job->fd, job->pid, job->status);
|
||||
cmdq_print(item, "Job %u: %s [fd=%d, pid=%ld, status=%d]",
|
||||
n, job->cmd, job->fd, (long)job->pid, job->status);
|
||||
n++;
|
||||
}
|
||||
return (n != 0);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmdq->state.c;
|
||||
struct client *c = item->state.c;
|
||||
struct message_entry *msg;
|
||||
char *tim;
|
||||
int done, blank;
|
||||
|
||||
done = blank = 0;
|
||||
if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) {
|
||||
blank = cmd_show_messages_terminals(cmdq, blank);
|
||||
if (args_has(args, 'T')) {
|
||||
blank = cmd_show_messages_terminals(item, blank);
|
||||
done = 1;
|
||||
}
|
||||
if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) {
|
||||
cmd_show_messages_jobs(cmdq, blank);
|
||||
if (args_has(args, 'J')) {
|
||||
cmd_show_messages_jobs(item, blank);
|
||||
done = 1;
|
||||
}
|
||||
if (done)
|
||||
@@ -122,7 +112,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
tim = ctime(&msg->msg_time);
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
cmdq_print(cmdq, "%s %s", tim, msg->msg);
|
||||
cmdq_print(item, "%s %s", tim, msg->msg);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
* Show options.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
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 *,
|
||||
struct options *, enum options_table_scope);
|
||||
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *,
|
||||
struct options *);
|
||||
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
||||
struct options *);
|
||||
|
||||
const struct cmd_entry cmd_show_options_entry = {
|
||||
.name = "show-options",
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_show_options_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_options_exec
|
||||
};
|
||||
|
||||
@@ -56,142 +56,124 @@ const struct cmd_entry cmd_show_window_options_entry = {
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_options_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct cmd_find_state *fs = &item->state.tflag;
|
||||
struct options *oo;
|
||||
enum options_table_scope scope;
|
||||
int quiet;
|
||||
const char *target;
|
||||
char *cause;
|
||||
int window;
|
||||
|
||||
if (args_has(self->args, 's')) {
|
||||
oo = global_options;
|
||||
scope = OPTIONS_TABLE_SERVER;
|
||||
} else if (args_has(self->args, 'w') ||
|
||||
self->entry == &cmd_show_window_options_entry) {
|
||||
scope = OPTIONS_TABLE_WINDOW;
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_w_options;
|
||||
else if (wl == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(cmdq, "no such window: %s", target);
|
||||
} else
|
||||
cmdq_error(cmdq, "no current window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
oo = wl->window->options;
|
||||
} else {
|
||||
scope = OPTIONS_TABLE_SESSION;
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_s_options;
|
||||
else if (s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(cmdq, "no such session: %s", target);
|
||||
} else
|
||||
cmdq_error(cmdq, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
oo = s->options;
|
||||
window = (self->entry == &cmd_show_window_options_entry);
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
quiet = args_has(self->args, 'q');
|
||||
if (args->argc == 0)
|
||||
return (cmd_show_options_all(self, cmdq, oo, scope));
|
||||
return (cmd_show_options_all(self, item, oo));
|
||||
else
|
||||
return (cmd_show_options_one(self, cmdq, oo, quiet));
|
||||
return (cmd_show_options_one(self, item, oo));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
|
||||
struct options *oo, int quiet)
|
||||
static void
|
||||
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
struct options_entry *o, int idx)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *name = args->argv[0];
|
||||
const struct options_table_entry *oe;
|
||||
struct options_entry *o;
|
||||
const char *optval;
|
||||
const char *name;
|
||||
const char *value;
|
||||
char *tmp, *escaped;
|
||||
u_int size, i;
|
||||
|
||||
retry:
|
||||
if (*name == '@') {
|
||||
if ((o = options_find1(oo, name)) == NULL) {
|
||||
if (quiet)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(cmdq, "unknown option: %s", name);
|
||||
if (idx != -1) {
|
||||
xasprintf(&tmp, "%s[%d]", options_name(o), idx);
|
||||
name = tmp;
|
||||
} else {
|
||||
if (options_array_size(o, &size) != -1) {
|
||||
for (i = 0; i < size; i++) {
|
||||
if (options_array_get(o, i) == NULL)
|
||||
continue;
|
||||
cmd_show_options_print(self, item, o, i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmp = NULL;
|
||||
name = options_name(o);
|
||||
}
|
||||
|
||||
value = options_tostring(o, idx, 0);
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(item, "%s", value);
|
||||
else if (options_isstring(o)) {
|
||||
utf8_stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
|
||||
cmdq_print(item, "%s \"%s\"", name, escaped);
|
||||
free(escaped);
|
||||
} else
|
||||
cmdq_print(item, "%s %s", name, value);
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_options_one(struct cmd *self, struct cmdq_item *item,
|
||||
struct options *oo)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct options_entry *o;
|
||||
int idx, ambiguous;
|
||||
const char *name = args->argv[0];
|
||||
|
||||
o = options_match_get(oo, name, &idx, 1, &ambiguous);
|
||||
if (o == NULL) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (ambiguous) {
|
||||
cmdq_error(item, "ambiguous option: %s", name);
|
||||
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);
|
||||
}
|
||||
|
||||
oe = NULL;
|
||||
if (options_table_find(name, &oe) != 0) {
|
||||
cmdq_error(cmdq, "ambiguous option: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (oe == NULL) {
|
||||
if (quiet)
|
||||
if (*name != '@' &&
|
||||
options_match_get(oo, name, &idx, 0, &ambiguous) != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(cmdq, "unknown option: %s", name);
|
||||
cmdq_error(item, "unknown option: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (oe->style != NULL) {
|
||||
name = oe->style;
|
||||
goto retry;
|
||||
}
|
||||
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);
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo,
|
||||
enum options_table_scope scope)
|
||||
static enum cmd_retval
|
||||
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
|
||||
struct options *oo)
|
||||
{
|
||||
struct options_entry *o;
|
||||
const struct options_table_entry *oe;
|
||||
struct options_entry *o;
|
||||
const char *optval;
|
||||
int vflag;
|
||||
u_int size, idx;
|
||||
|
||||
o = options_first(oo);
|
||||
while (o != NULL) {
|
||||
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);
|
||||
oe = options_table_entry(o);
|
||||
if (oe != NULL && oe->style != NULL) {
|
||||
o = options_next(o);
|
||||
continue;
|
||||
}
|
||||
if (options_array_size(o, &size) == -1)
|
||||
cmd_show_options_print(self, item, o, -1);
|
||||
else {
|
||||
for (idx = 0; idx < size; idx++) {
|
||||
if (options_array_get(o, idx) == NULL)
|
||||
continue;
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
}
|
||||
}
|
||||
o = options_next(o);
|
||||
}
|
||||
|
||||
vflag = args_has(self->args, 'v');
|
||||
for (oe = options_table; oe->name != NULL; oe++) {
|
||||
if (oe->style != NULL || oe->scope != scope)
|
||||
continue;
|
||||
if ((o = options_find1(oo, oe->name)) == NULL)
|
||||
continue;
|
||||
optval = options_table_print_entry(oe, o, vflag);
|
||||
if (vflag)
|
||||
cmdq_print(cmdq, "%s", optval);
|
||||
else
|
||||
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,9 +29,9 @@
|
||||
* Sources a configuration file.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
void cmd_source_file_done(struct cmd_q *);
|
||||
static enum cmd_retval cmd_source_file_done(struct cmdq_item *, void *);
|
||||
|
||||
const struct cmd_entry cmd_source_file_entry = {
|
||||
.name = "source-file",
|
||||
@@ -41,57 +44,55 @@ const struct cmd_entry cmd_source_file_entry = {
|
||||
.exec = cmd_source_file_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_q *cmdq1;
|
||||
int quiet;
|
||||
struct args *args = self->args;
|
||||
int quiet = args_has(args, 'q');
|
||||
struct client *c = item->client;
|
||||
struct cmdq_item *new_item;
|
||||
enum cmd_retval retval;
|
||||
char *pattern, *tmp;
|
||||
const char *path = args->argv[0];
|
||||
glob_t g;
|
||||
u_int i;
|
||||
|
||||
cmdq1 = cmdq_new(cmdq->client);
|
||||
cmdq1->flags |= cmdq->flags & CMD_Q_NOHOOKS;
|
||||
cmdq1->emptyfn = cmd_source_file_done;
|
||||
cmdq1->data = cmdq;
|
||||
if (*path == '/')
|
||||
pattern = xstrdup(path);
|
||||
else {
|
||||
utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB);
|
||||
xasprintf(&pattern, "%s/%s", tmp, path);
|
||||
free(tmp);
|
||||
}
|
||||
log_debug("%s: %s", __func__, pattern);
|
||||
|
||||
quiet = args_has(args, 'q');
|
||||
switch (load_cfg(args->argv[0], cmdq1, quiet)) {
|
||||
case -1:
|
||||
cmdq_free(cmdq1);
|
||||
if (cfg_references == 0) {
|
||||
cfg_print_causes(cmdq);
|
||||
return (CMD_RETURN_ERROR);
|
||||
retval = CMD_RETURN_NORMAL;
|
||||
if (glob(pattern, 0, NULL, &g) != 0) {
|
||||
if (!quiet || errno != ENOENT) {
|
||||
cmdq_error(item, "%s: %s", path, strerror(errno));
|
||||
retval = CMD_RETURN_ERROR;
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
case 0:
|
||||
cmdq_free(cmdq1);
|
||||
if (cfg_references == 0)
|
||||
cfg_print_causes(cmdq);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
free(pattern);
|
||||
return (retval);
|
||||
}
|
||||
free(pattern);
|
||||
|
||||
for (i = 0; i < (u_int)g.gl_pathc; i++) {
|
||||
if (load_cfg(g.gl_pathv[i], c, item, quiet) < 0)
|
||||
retval = CMD_RETURN_ERROR;
|
||||
}
|
||||
if (cfg_finished) {
|
||||
new_item = cmdq_get_callback(cmd_source_file_done, NULL);
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
cmdq->references++;
|
||||
cfg_references++;
|
||||
|
||||
cmdq_continue(cmdq1);
|
||||
return (CMD_RETURN_WAIT);
|
||||
globfree(&g);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_source_file_done(struct cmd_q *cmdq1)
|
||||
static enum cmd_retval
|
||||
cmd_source_file_done(struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
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)
|
||||
cfg_print_causes(cmdq);
|
||||
cmdq_continue(cmdq);
|
||||
cfg_print_causes(item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
|
||||
#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
|
||||
|
||||
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_split_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_split_window_entry = {
|
||||
.name = "split-window",
|
||||
@@ -48,14 +49,15 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
.exec = cmd_split_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct winlink *wl = cmdq->state.tflag.wl;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = cmdq->state.tflag.wp, *new_wp = NULL;
|
||||
struct window_pane *wp = item->state.tflag.wp, *new_wp = NULL;
|
||||
struct environ *env;
|
||||
const char *cmd, *path, *shell, *template, *cwd, *to_free;
|
||||
char **argv, *cause, *new_cause, *cp;
|
||||
@@ -63,16 +65,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
int argc, size, percentage;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
server_unzoom_window(w);
|
||||
|
||||
env = environ_create();
|
||||
environ_copy(global_environ, env);
|
||||
environ_copy(s->environ, env);
|
||||
server_fill_environ(s, env);
|
||||
|
||||
if (args->argc == 0) {
|
||||
cmd = options_get_string(s->options, "default-command");
|
||||
if (cmd != NULL && *cmd != '\0') {
|
||||
@@ -89,12 +86,10 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, cmdq->state.c, s, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
cwd = cmdq->client->cwd;
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else
|
||||
cwd = s->cwd;
|
||||
|
||||
@@ -136,20 +131,24 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
cause = xstrdup("pane too small");
|
||||
goto error;
|
||||
}
|
||||
new_wp = window_add_pane(w, wp, hlimit);
|
||||
new_wp = window_add_pane(w, wp, args_has(args, 'b'), hlimit);
|
||||
layout_assign_pane(lc, new_wp);
|
||||
|
||||
path = NULL;
|
||||
if (cmdq->client != NULL && cmdq->client->session == NULL)
|
||||
envent = environ_find(cmdq->client->environ, "PATH");
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env,
|
||||
s->tio, &cause) != 0)
|
||||
s->tio, &cause) != 0) {
|
||||
environ_free(env);
|
||||
goto error;
|
||||
}
|
||||
environ_free(env);
|
||||
|
||||
server_redraw_window(w);
|
||||
|
||||
@@ -160,34 +159,34 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
} else
|
||||
server_status_session(s);
|
||||
|
||||
environ_free(env);
|
||||
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = SPLIT_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq, 0);
|
||||
format_defaults(ft, cmdq->state.c, s, wl, new_wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cmdq_print(cmdq, "%s", cp);
|
||||
cp = format_single(item, template, c, s, wl, new_wp);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
notify_window_layout_changed(w);
|
||||
notify_window("window-layout-changed", w);
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_clear_state(&fs, NULL, 0);
|
||||
fs.s = s;
|
||||
fs.wl = wl;
|
||||
fs.w = w;
|
||||
fs.wp = new_wp;
|
||||
cmd_find_log_state(__func__, &fs);
|
||||
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
environ_free(env);
|
||||
if (new_wp != NULL) {
|
||||
layout_close_pane(new_wp);
|
||||
window_remove_pane(w, new_wp);
|
||||
}
|
||||
cmdq_error(cmdq, "create pane failed: %s", cause);
|
||||
cmdq_error(item, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
|
||||
if (to_free != NULL)
|
||||
|
||||
138
cmd-string.c
138
cmd-string.c
@@ -31,14 +31,14 @@
|
||||
* Parse a command from a string.
|
||||
*/
|
||||
|
||||
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 *);
|
||||
static int cmd_string_getc(const char *, size_t *);
|
||||
static void cmd_string_ungetc(size_t *);
|
||||
static void cmd_string_copy(char **, char *, size_t *);
|
||||
static char *cmd_string_string(const char *, size_t *, char, int);
|
||||
static char *cmd_string_variable(const char *, size_t *);
|
||||
static char *cmd_string_expand_tilde(const char *, size_t *);
|
||||
|
||||
int
|
||||
static int
|
||||
cmd_string_getc(const char *s, size_t *p)
|
||||
{
|
||||
const u_char *ucs = s;
|
||||
@@ -48,38 +48,21 @@ cmd_string_getc(const char *s, size_t *p)
|
||||
return (ucs[(*p)++]);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_string_ungetc(size_t *p)
|
||||
{
|
||||
(*p)--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse command string. Returns -1 on error. If returning -1, cause is error
|
||||
* string, or NULL for empty command.
|
||||
*/
|
||||
int
|
||||
cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
|
||||
u_int line, char **cause)
|
||||
cmd_string_split(const char *s, int *rargc, char ***rargv)
|
||||
{
|
||||
size_t p;
|
||||
int ch, i, argc, rval;
|
||||
char **argv, *buf, *t;
|
||||
size_t p = 0;
|
||||
int ch, argc = 0, append = 0;
|
||||
char **argv = NULL, *buf = NULL, *t;
|
||||
const char *whitespace, *equals;
|
||||
size_t len;
|
||||
size_t len = 0;
|
||||
|
||||
argv = NULL;
|
||||
argc = 0;
|
||||
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
|
||||
*cause = NULL;
|
||||
|
||||
*cmdlist = NULL;
|
||||
rval = -1;
|
||||
|
||||
p = 0;
|
||||
for (;;) {
|
||||
ch = cmd_string_getc(s, &p);
|
||||
switch (ch) {
|
||||
@@ -130,50 +113,70 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
|
||||
argc--;
|
||||
memmove(argv, argv + 1, argc * (sizeof *argv));
|
||||
}
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
|
||||
*cmdlist = cmd_list_parse(argc, argv, file, line, cause);
|
||||
if (*cmdlist == NULL)
|
||||
goto out;
|
||||
|
||||
rval = 0;
|
||||
goto out;
|
||||
goto done;
|
||||
case '~':
|
||||
if (buf == NULL) {
|
||||
t = cmd_string_expand_tilde(s, &p);
|
||||
if (t == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
if (buf != NULL) {
|
||||
append = 1;
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
if (len >= SIZE_MAX - 2)
|
||||
t = cmd_string_expand_tilde(s, &p);
|
||||
if (t == NULL)
|
||||
goto error;
|
||||
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
default:
|
||||
append = 1;
|
||||
break;
|
||||
}
|
||||
if (append) {
|
||||
if (len >= SIZE_MAX - 2)
|
||||
goto error;
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
}
|
||||
append = 0;
|
||||
}
|
||||
|
||||
done:
|
||||
*rargc = argc;
|
||||
*rargv = argv;
|
||||
|
||||
free(buf);
|
||||
return (0);
|
||||
|
||||
error:
|
||||
if (argv != NULL)
|
||||
cmd_free_argv(argc, argv);
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
struct cmd_list *
|
||||
cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
|
||||
{
|
||||
struct cmd_list *cmdlist = NULL;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
*cause = NULL;
|
||||
if (cmd_string_split(s, &argc, &argv) != 0)
|
||||
goto error;
|
||||
if (argc != 0) {
|
||||
cmdlist = cmd_list_parse(argc, argv, file, line, cause);
|
||||
if (cmdlist == NULL) {
|
||||
cmd_free_argv(argc, argv);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
cmd_free_argv(argc, argv);
|
||||
return (cmdlist);
|
||||
|
||||
error:
|
||||
xasprintf(cause, "invalid or unknown command: %s", s);
|
||||
|
||||
out:
|
||||
free(buf);
|
||||
|
||||
if (argv != NULL) {
|
||||
for (i = 0; i < argc; i++)
|
||||
free(argv[i]);
|
||||
free(argv);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_string_copy(char **dst, char *src, size_t *len)
|
||||
{
|
||||
size_t srclen;
|
||||
@@ -187,7 +190,7 @@ cmd_string_copy(char **dst, char *src, size_t *len)
|
||||
free(src);
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
{
|
||||
int ch;
|
||||
@@ -245,7 +248,7 @@ error:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
cmd_string_variable(const char *s, size_t *p)
|
||||
{
|
||||
int ch, fch;
|
||||
@@ -314,7 +317,7 @@ error:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
{
|
||||
struct passwd *pw;
|
||||
@@ -337,7 +340,10 @@ cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
cp = user = xmalloc(strlen(s));
|
||||
for (;;) {
|
||||
last = cmd_string_getc(s, p);
|
||||
if (last == EOF || last == '/' || last == ' '|| last == '\t')
|
||||
if (last == EOF ||
|
||||
last == '/' ||
|
||||
last == ' '||
|
||||
last == '\t')
|
||||
break;
|
||||
*cp++ = last;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Swap two panes.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_swap_pane_entry = {
|
||||
.name = "swap-pane",
|
||||
@@ -42,18 +42,18 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
||||
.exec = cmd_swap_pane_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct window *src_w, *dst_w;
|
||||
struct window_pane *tmp_wp, *src_wp, *dst_wp;
|
||||
struct layout_cell *src_lc, *dst_lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
dst_w = cmdq->state.tflag.wl->window;
|
||||
dst_wp = cmdq->state.tflag.wp;
|
||||
src_w = cmdq->state.sflag.wl->window;
|
||||
src_wp = cmdq->state.sflag.wp;
|
||||
dst_w = item->state.tflag.wl->window;
|
||||
dst_wp = item->state.tflag.wp;
|
||||
src_w = item->state.sflag.wl->window;
|
||||
src_wp = item->state.sflag.wp;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
if (args_has(self->args, 'D')) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Swap one window with another.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_swap_window_entry = {
|
||||
.name = "swap-window",
|
||||
@@ -42,34 +42,40 @@ const struct cmd_entry cmd_swap_window_entry = {
|
||||
.exec = cmd_swap_window_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct session *src, *dst;
|
||||
struct session_group *sg_src, *sg_dst;
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct window *w;
|
||||
struct window *w_src, *w_dst;
|
||||
|
||||
wl_src = cmdq->state.sflag.wl;
|
||||
src = cmdq->state.sflag.s;
|
||||
sg_src = session_group_find(src);
|
||||
wl_src = item->state.sflag.wl;
|
||||
src = item->state.sflag.s;
|
||||
sg_src = session_group_contains(src);
|
||||
|
||||
wl_dst = cmdq->state.tflag.wl;
|
||||
dst = cmdq->state.tflag.s;
|
||||
sg_dst = session_group_find(dst);
|
||||
wl_dst = item->state.tflag.wl;
|
||||
dst = item->state.tflag.s;
|
||||
sg_dst = session_group_contains(dst);
|
||||
|
||||
if (src != dst && sg_src != NULL && sg_dst != NULL &&
|
||||
sg_src == sg_dst) {
|
||||
cmdq_error(cmdq, "can't move window, sessions are grouped");
|
||||
cmdq_error(item, "can't move window, sessions are grouped");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (wl_dst->window == wl_src->window)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
w = wl_dst->window;
|
||||
wl_dst->window = wl_src->window;
|
||||
wl_src->window = w;
|
||||
w_dst = wl_dst->window;
|
||||
TAILQ_REMOVE(&w_dst->winlinks, wl_dst, wentry);
|
||||
w_src = wl_src->window;
|
||||
TAILQ_REMOVE(&w_src->winlinks, wl_src, wentry);
|
||||
|
||||
wl_dst->window = w_src;
|
||||
TAILQ_INSERT_TAIL(&w_src->winlinks, wl_dst, wentry);
|
||||
wl_src->window = w_dst;
|
||||
TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry);
|
||||
|
||||
if (!args_has(self->args, 'd')) {
|
||||
session_select(dst, wl_dst->idx);
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
* Switch client to a different session.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_switch_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_switch_client_entry = {
|
||||
.name = "switch-client",
|
||||
@@ -44,15 +45,15 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
.exec = cmd_switch_client_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_state *state = &cmdq->state;
|
||||
struct cmd_state *state = &item->state;
|
||||
struct client *c = state->c;
|
||||
struct session *s = cmdq->state.tflag.s;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct window_pane *wp;
|
||||
const char *tablename, *update;
|
||||
const char *tablename;
|
||||
struct key_table *table;
|
||||
|
||||
if (args_has(args, 'r'))
|
||||
@@ -62,7 +63,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (tablename != NULL) {
|
||||
table = key_bindings_get_table(tablename, 0);
|
||||
if (table == NULL) {
|
||||
cmdq_error(cmdq, "table %s doesn't exist", tablename);
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
table->references++;
|
||||
@@ -73,12 +74,12 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (args_has(args, 'n')) {
|
||||
if ((s = session_next_session(c->session)) == NULL) {
|
||||
cmdq_error(cmdq, "can't find next session");
|
||||
cmdq_error(item, "can't find next session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
if ((s = session_previous_session(c->session)) == NULL) {
|
||||
cmdq_error(cmdq, "can't find previous session");
|
||||
cmdq_error(item, "can't find previous session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'l')) {
|
||||
@@ -87,11 +88,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
else
|
||||
s = NULL;
|
||||
if (s == NULL) {
|
||||
cmdq_error(cmdq, "can't find last session");
|
||||
cmdq_error(item, "can't find last session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (cmdq->client == NULL)
|
||||
if (item->client == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (state->tflag.wl != NULL) {
|
||||
wp = state->tflag.wp;
|
||||
@@ -101,15 +102,14 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
}
|
||||
|
||||
if (c != NULL && !args_has(args, 'E')) {
|
||||
update = options_get_string(s->options, "update-environment");
|
||||
environ_update(update, c->environ, s->environ);
|
||||
}
|
||||
if (!args_has(args, 'E'))
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
if (c->session != NULL && c->session != s)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
server_client_set_key_table(c, NULL);
|
||||
if (!item->repeat)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
|
||||
@@ -26,23 +26,21 @@
|
||||
* Unbind key from command.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *);
|
||||
enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *,
|
||||
key_code);
|
||||
static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_unbind_key_entry = {
|
||||
.name = "unbind-key",
|
||||
.alias = "unbind",
|
||||
|
||||
.args = { "acnt:T:", 0, 1 },
|
||||
.usage = "[-acn] [-t mode-table] [-T key-table] key",
|
||||
.args = { "anT:", 0, 1 },
|
||||
.usage = "[-an] [-T key-table] key",
|
||||
|
||||
.flags = 0,
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_unbind_key_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
key_code key;
|
||||
@@ -50,25 +48,22 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if (!args_has(args, 'a')) {
|
||||
if (args->argc != 1) {
|
||||
cmdq_error(cmdq, "missing key");
|
||||
cmdq_error(item, "missing key");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (args->argc != 0) {
|
||||
cmdq_error(cmdq, "key given with -a");
|
||||
cmdq_error(item, "key given with -a");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key = KEYC_UNKNOWN;
|
||||
}
|
||||
|
||||
if (args_has(args, 't'))
|
||||
return (cmd_unbind_key_mode_table(self, cmdq, key));
|
||||
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
tablename = args_get(args, 'T');
|
||||
if (tablename == NULL) {
|
||||
@@ -77,7 +72,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (key_bindings_get_table(tablename, 0) == NULL) {
|
||||
cmdq_error(cmdq, "table %s doesn't exist", tablename);
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key_bindings_remove_table(tablename);
|
||||
@@ -87,7 +82,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (args_has(args, 'T')) {
|
||||
tablename = args_get(args, 'T');
|
||||
if (key_bindings_get_table(tablename, 0) == NULL) {
|
||||
cmdq_error(cmdq, "table %s doesn't exist", tablename);
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'n'))
|
||||
@@ -97,35 +92,3 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
key_bindings_remove(tablename, key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *tablename;
|
||||
const struct mode_key_table *mtab;
|
||||
struct mode_key_binding *mbind, mtmp;
|
||||
|
||||
tablename = args_get(args, 't');
|
||||
if ((mtab = mode_key_findtable(tablename)) == NULL) {
|
||||
cmdq_error(cmdq, "unknown key table: %s", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (key == KEYC_UNKNOWN) {
|
||||
while (!RB_EMPTY(mtab->tree)) {
|
||||
mbind = RB_ROOT(mtab->tree);
|
||||
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||
free(mbind);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
mtmp.key = key;
|
||||
mtmp.mode = !!args_has(args, 'c');
|
||||
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||
free(mbind);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
134
cmd-wait-for.c
134
cmd-wait-for.c
@@ -28,7 +28,7 @@
|
||||
* Block or wake a client on a named wait channel.
|
||||
*/
|
||||
|
||||
enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *);
|
||||
static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_wait_for_entry = {
|
||||
.name = "wait-for",
|
||||
@@ -41,42 +41,46 @@ const struct cmd_entry cmd_wait_for_entry = {
|
||||
.exec = cmd_wait_for_exec
|
||||
};
|
||||
|
||||
struct wait_item {
|
||||
struct cmdq_item *item;
|
||||
TAILQ_ENTRY(wait_item) entry;
|
||||
};
|
||||
|
||||
struct wait_channel {
|
||||
const char *name;
|
||||
int locked;
|
||||
int woken;
|
||||
|
||||
TAILQ_HEAD(, cmd_q) waiters;
|
||||
TAILQ_HEAD(, cmd_q) lockers;
|
||||
TAILQ_HEAD(, wait_item) waiters;
|
||||
TAILQ_HEAD(, wait_item) lockers;
|
||||
|
||||
RB_ENTRY(wait_channel) entry;
|
||||
};
|
||||
RB_HEAD(wait_channels, wait_channel);
|
||||
struct wait_channels wait_channels = RB_INITIALIZER(wait_channels);
|
||||
static 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);
|
||||
static int wait_channel_cmp(struct wait_channel *, struct wait_channel *);
|
||||
RB_GENERATE_STATIC(wait_channels, wait_channel, entry, wait_channel_cmp);
|
||||
|
||||
int
|
||||
static 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 *);
|
||||
static enum cmd_retval cmd_wait_for_signal(struct cmdq_item *, const char *,
|
||||
struct wait_channel *);
|
||||
static enum cmd_retval cmd_wait_for_wait(struct cmdq_item *, const char *,
|
||||
struct wait_channel *);
|
||||
static enum cmd_retval cmd_wait_for_lock(struct cmdq_item *, const char *,
|
||||
struct wait_channel *);
|
||||
static enum cmd_retval cmd_wait_for_unlock(struct cmdq_item *, const char *,
|
||||
struct wait_channel *);
|
||||
|
||||
struct wait_channel *cmd_wait_for_add(const char *);
|
||||
void cmd_wait_for_remove(struct wait_channel *wc);
|
||||
static struct wait_channel *cmd_wait_for_add(const char *);
|
||||
static void cmd_wait_for_remove(struct wait_channel *);
|
||||
|
||||
struct wait_channel *
|
||||
static struct wait_channel *
|
||||
cmd_wait_for_add(const char *name)
|
||||
{
|
||||
struct wait_channel *wc;
|
||||
@@ -97,7 +101,7 @@ cmd_wait_for_add(const char *name)
|
||||
return (wc);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
cmd_wait_for_remove(struct wait_channel *wc)
|
||||
{
|
||||
if (wc->locked)
|
||||
@@ -113,8 +117,8 @@ cmd_wait_for_remove(struct wait_channel *wc)
|
||||
free(wc);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
const char *name = args->argv[0];
|
||||
@@ -124,19 +128,19 @@ cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
wc = RB_FIND(wait_channels, &wait_channels, &wc0);
|
||||
|
||||
if (args_has(args, 'S'))
|
||||
return (cmd_wait_for_signal(cmdq, name, wc));
|
||||
return (cmd_wait_for_signal(item, name, wc));
|
||||
if (args_has(args, 'L'))
|
||||
return (cmd_wait_for_lock(cmdq, name, wc));
|
||||
return (cmd_wait_for_lock(item, name, wc));
|
||||
if (args_has(args, 'U'))
|
||||
return (cmd_wait_for_unlock(cmdq, name, wc));
|
||||
return (cmd_wait_for_wait(cmdq, name, wc));
|
||||
return (cmd_wait_for_unlock(item, name, wc));
|
||||
return (cmd_wait_for_wait(item, name, wc));
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name,
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_signal(__unused struct cmdq_item *item, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
struct cmd_q *wq, *wq1;
|
||||
struct wait_item *wi, *wi1;
|
||||
|
||||
if (wc == NULL)
|
||||
wc = cmd_wait_for_add(name);
|
||||
@@ -148,24 +152,26 @@ cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name,
|
||||
}
|
||||
log_debug("signal wait channel %s, with waiters", wc->name);
|
||||
|
||||
TAILQ_FOREACH_SAFE(wq, &wc->waiters, waitentry, wq1) {
|
||||
TAILQ_REMOVE(&wc->waiters, wq, waitentry);
|
||||
if (!cmdq_free(wq))
|
||||
cmdq_continue(wq);
|
||||
TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) {
|
||||
wi->item->flags &= ~CMDQ_WAITING;
|
||||
|
||||
TAILQ_REMOVE(&wc->waiters, wi, entry);
|
||||
free(wi);
|
||||
}
|
||||
|
||||
cmd_wait_for_remove(wc);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_wait(struct cmd_q *cmdq, const char *name,
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_wait(struct cmdq_item *item, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
struct client *c = cmdq->client;
|
||||
struct client *c = item->client;
|
||||
struct wait_item *wi;
|
||||
|
||||
if (c == NULL || c->session != NULL) {
|
||||
cmdq_error(cmdq, "not able to wait");
|
||||
cmdq_error(item, "not able to wait");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -179,18 +185,21 @@ cmd_wait_for_wait(struct cmd_q *cmdq, const char *name,
|
||||
}
|
||||
log_debug("wait channel %s not woken (%p)", wc->name, c);
|
||||
|
||||
TAILQ_INSERT_TAIL(&wc->waiters, cmdq, waitentry);
|
||||
cmdq->references++;
|
||||
wi = xcalloc(1, sizeof *wi);
|
||||
wi->item = item;
|
||||
TAILQ_INSERT_TAIL(&wc->waiters, wi, entry);
|
||||
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_lock(struct cmd_q *cmdq, const char *name,
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_lock(struct cmdq_item *item, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
if (cmdq->client == NULL || cmdq->client->session != NULL) {
|
||||
cmdq_error(cmdq, "not able to lock");
|
||||
struct wait_item *wi;
|
||||
|
||||
if (item->client == NULL || item->client->session != NULL) {
|
||||
cmdq_error(item, "not able to lock");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -198,8 +207,9 @@ cmd_wait_for_lock(struct cmd_q *cmdq, const char *name,
|
||||
wc = cmd_wait_for_add(name);
|
||||
|
||||
if (wc->locked) {
|
||||
TAILQ_INSERT_TAIL(&wc->lockers, cmdq, waitentry);
|
||||
cmdq->references++;
|
||||
wi = xcalloc(1, sizeof *wi);
|
||||
wi->item = item;
|
||||
TAILQ_INSERT_TAIL(&wc->lockers, wi, entry);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
wc->locked = 1;
|
||||
@@ -207,21 +217,21 @@ cmd_wait_for_lock(struct cmd_q *cmdq, const char *name,
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
enum cmd_retval
|
||||
cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name,
|
||||
static enum cmd_retval
|
||||
cmd_wait_for_unlock(struct cmdq_item *item, const char *name,
|
||||
struct wait_channel *wc)
|
||||
{
|
||||
struct cmd_q *wq;
|
||||
struct wait_item *wi;
|
||||
|
||||
if (wc == NULL || !wc->locked) {
|
||||
cmdq_error(cmdq, "channel %s not locked", name);
|
||||
cmdq_error(item, "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);
|
||||
if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) {
|
||||
wi->item->flags &= ~CMDQ_WAITING;
|
||||
TAILQ_REMOVE(&wc->lockers, wi, entry);
|
||||
free(wi);
|
||||
} else {
|
||||
wc->locked = 0;
|
||||
cmd_wait_for_remove(wc);
|
||||
@@ -234,19 +244,19 @@ void
|
||||
cmd_wait_for_flush(void)
|
||||
{
|
||||
struct wait_channel *wc, *wc1;
|
||||
struct cmd_q *wq, *wq1;
|
||||
struct wait_item *wi, *wi1;
|
||||
|
||||
RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) {
|
||||
TAILQ_FOREACH_SAFE(wq, &wc->waiters, waitentry, wq1) {
|
||||
TAILQ_REMOVE(&wc->waiters, wq, waitentry);
|
||||
if (!cmdq_free(wq))
|
||||
cmdq_continue(wq);
|
||||
TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) {
|
||||
wi->item->flags &= ~CMDQ_WAITING;
|
||||
TAILQ_REMOVE(&wc->waiters, wi, entry);
|
||||
free(wi);
|
||||
}
|
||||
wc->woken = 1;
|
||||
TAILQ_FOREACH_SAFE(wq, &wc->lockers, waitentry, wq1) {
|
||||
TAILQ_REMOVE(&wc->lockers, wq, waitentry);
|
||||
if (!cmdq_free(wq))
|
||||
cmdq_continue(wq);
|
||||
TAILQ_FOREACH_SAFE(wi, &wc->lockers, entry, wi1) {
|
||||
wi->item->flags &= ~CMDQ_WAITING;
|
||||
TAILQ_REMOVE(&wc->lockers, wi, entry);
|
||||
free(wi);
|
||||
}
|
||||
wc->locked = 0;
|
||||
cmd_wait_for_remove(wc);
|
||||
|
||||
185
cmd.c
185
cmd.c
@@ -92,7 +92,6 @@ extern const struct cmd_entry cmd_select_pane_entry;
|
||||
extern const struct cmd_entry cmd_select_window_entry;
|
||||
extern const struct cmd_entry cmd_send_keys_entry;
|
||||
extern const struct cmd_entry cmd_send_prefix_entry;
|
||||
extern const struct cmd_entry cmd_server_info_entry;
|
||||
extern const struct cmd_entry cmd_set_buffer_entry;
|
||||
extern const struct cmd_entry cmd_set_environment_entry;
|
||||
extern const struct cmd_entry cmd_set_hook_entry;
|
||||
@@ -181,7 +180,6 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_select_window_entry,
|
||||
&cmd_send_keys_entry,
|
||||
&cmd_send_prefix_entry,
|
||||
&cmd_server_info_entry,
|
||||
&cmd_set_buffer_entry,
|
||||
&cmd_set_environment_entry,
|
||||
&cmd_set_hook_entry,
|
||||
@@ -307,21 +305,74 @@ cmd_stringify_argv(int argc, char **argv)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_try_alias(int *argc, char ***argv)
|
||||
{
|
||||
struct options_entry *o;
|
||||
int old_argc = *argc, new_argc;
|
||||
char **old_argv = *argv, **new_argv;
|
||||
u_int size, idx;
|
||||
int i;
|
||||
size_t wanted;
|
||||
const char *s, *cp = NULL;
|
||||
|
||||
o = options_get_only(global_options, "command-alias");
|
||||
if (o == NULL || options_array_size(o, &size) == -1 || size == 0)
|
||||
return (-1);
|
||||
|
||||
wanted = strlen(old_argv[0]);
|
||||
for (idx = 0; idx < size; idx++) {
|
||||
s = options_array_get(o, idx);
|
||||
if (s == NULL)
|
||||
continue;
|
||||
|
||||
cp = strchr(s, '=');
|
||||
if (cp == NULL || (size_t)(cp - s) != wanted)
|
||||
continue;
|
||||
if (strncmp(old_argv[0], s, wanted) == 0)
|
||||
break;
|
||||
}
|
||||
if (idx == size)
|
||||
return (-1);
|
||||
|
||||
if (cmd_string_split(cp + 1, &new_argc, &new_argv) != 0)
|
||||
return (-1);
|
||||
|
||||
*argc = new_argc + old_argc - 1;
|
||||
*argv = xcalloc((*argc) + 1, sizeof **argv);
|
||||
|
||||
for (i = 0; i < new_argc; i++)
|
||||
(*argv)[i] = xstrdup(new_argv[i]);
|
||||
for (i = 1; i < old_argc; i++)
|
||||
(*argv)[new_argc + i - 1] = xstrdup(old_argv[i]);
|
||||
|
||||
log_debug("alias: %s=%s", old_argv[0], cp + 1);
|
||||
for (i = 0; i < *argc; i++)
|
||||
log_debug("alias: argv[%d] = %s", i, (*argv)[i]);
|
||||
|
||||
cmd_free_argv(new_argc, new_argv);
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
{
|
||||
const char *name;
|
||||
const struct cmd_entry **entryp, *entry;
|
||||
struct cmd *cmd;
|
||||
struct args *args;
|
||||
char s[BUFSIZ];
|
||||
int ambiguous = 0;
|
||||
int ambiguous, allocated = 0;
|
||||
|
||||
*cause = NULL;
|
||||
if (argc == 0) {
|
||||
xasprintf(cause, "no command");
|
||||
return (NULL);
|
||||
}
|
||||
name = argv[0];
|
||||
|
||||
retry:
|
||||
ambiguous = 0;
|
||||
entry = NULL;
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
if ((*entryp)->alias != NULL &&
|
||||
@@ -341,10 +392,17 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
if (strcmp(entry->name, argv[0]) == 0)
|
||||
break;
|
||||
}
|
||||
if ((ambiguous || entry == NULL) &&
|
||||
server_proc != NULL &&
|
||||
!allocated &&
|
||||
cmd_try_alias(&argc, &argv) == 0) {
|
||||
allocated = 1;
|
||||
goto retry;
|
||||
}
|
||||
if (ambiguous)
|
||||
goto ambiguous;
|
||||
if (entry == NULL) {
|
||||
xasprintf(cause, "unknown command: %s", argv[0]);
|
||||
xasprintf(cause, "unknown command: %s", name);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -364,6 +422,8 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
cmd->file = xstrdup(file);
|
||||
cmd->line = line;
|
||||
|
||||
if (allocated)
|
||||
cmd_free_argv(argc, argv);
|
||||
return (cmd);
|
||||
|
||||
ambiguous:
|
||||
@@ -377,7 +437,7 @@ ambiguous:
|
||||
break;
|
||||
}
|
||||
s[strlen(s) - 2] = '\0';
|
||||
xasprintf(cause, "ambiguous command: %s, could be: %s", argv[0], s);
|
||||
xasprintf(cause, "ambiguous command: %s, could be: %s", name, s);
|
||||
return (NULL);
|
||||
|
||||
usage:
|
||||
@@ -389,12 +449,11 @@ usage:
|
||||
|
||||
static int
|
||||
cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
struct cmd_q *cmdq, struct cmd_q *parent)
|
||||
struct cmdq_item *item)
|
||||
{
|
||||
int targetflags, error;
|
||||
struct cmd_find_state *fs = NULL;
|
||||
struct cmd_find_state *current = NULL;
|
||||
struct cmd_find_state tmp;
|
||||
struct cmd_find_state current;
|
||||
|
||||
if (flag == CMD_NONE ||
|
||||
flag == CMD_CLIENT ||
|
||||
@@ -402,15 +461,15 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
return (0);
|
||||
|
||||
if (c == 't')
|
||||
fs = &cmdq->state.tflag;
|
||||
fs = &item->state.tflag;
|
||||
else if (c == 's')
|
||||
fs = &cmdq->state.sflag;
|
||||
fs = &item->state.sflag;
|
||||
|
||||
if (flag == CMD_SESSION_WITHPANE) {
|
||||
if (target != NULL && target[strcspn(target, ":.")] != '\0')
|
||||
flag = CMD_PANE;
|
||||
else
|
||||
flag = CMD_SESSION;
|
||||
flag = CMD_SESSION_PREFERUNATTACHED;
|
||||
}
|
||||
|
||||
targetflags = 0;
|
||||
@@ -418,6 +477,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
case CMD_SESSION:
|
||||
case CMD_SESSION_CANFAIL:
|
||||
case CMD_SESSION_PREFERUNATTACHED:
|
||||
case CMD_SESSION_WITHPANE:
|
||||
if (flag == CMD_SESSION_CANFAIL)
|
||||
targetflags |= CMD_FIND_QUIET;
|
||||
if (flag == CMD_SESSION_PREFERUNATTACHED)
|
||||
@@ -448,19 +508,16 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
default:
|
||||
fatalx("unknown %cflag %d", c, flag);
|
||||
}
|
||||
|
||||
log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
|
||||
if (parent != NULL) {
|
||||
if (c == 't')
|
||||
current = &parent->state.tflag;
|
||||
else if (c == 's')
|
||||
current = &parent->state.sflag;
|
||||
} else {
|
||||
error = cmd_find_current(&tmp, cmdq, targetflags);
|
||||
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
|
||||
|
||||
error = cmd_find_current(¤t, item, targetflags);
|
||||
if (error != 0) {
|
||||
if (~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
current = &tmp;
|
||||
cmd_find_clear_state(¤t, NULL, 0);
|
||||
}
|
||||
if (!cmd_find_empty_state(¤t) && !cmd_find_valid_state(¤t))
|
||||
fatalx("invalid current state");
|
||||
|
||||
switch (flag) {
|
||||
case CMD_NONE:
|
||||
@@ -471,13 +528,13 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
case CMD_SESSION_CANFAIL:
|
||||
case CMD_SESSION_PREFERUNATTACHED:
|
||||
case CMD_SESSION_WITHPANE:
|
||||
error = cmd_find_target(fs, current, cmdq, target,
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_SESSION, targetflags);
|
||||
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
case CMD_MOVEW_R:
|
||||
error = cmd_find_target(fs, current, cmdq, target,
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_SESSION, CMD_FIND_QUIET);
|
||||
if (error == 0)
|
||||
break;
|
||||
@@ -486,37 +543,43 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
case CMD_WINDOW_CANFAIL:
|
||||
case CMD_WINDOW_MARKED:
|
||||
case CMD_WINDOW_INDEX:
|
||||
error = cmd_find_target(fs, current, cmdq, target,
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_WINDOW, targetflags);
|
||||
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
case CMD_PANE:
|
||||
case CMD_PANE_CANFAIL:
|
||||
case CMD_PANE_MARKED:
|
||||
error = cmd_find_target(fs, current, cmdq, target,
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_PANE, targetflags);
|
||||
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
default:
|
||||
fatalx("unknown %cflag %d", c, flag);
|
||||
}
|
||||
return (0);
|
||||
|
||||
error:
|
||||
if (~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
|
||||
cmd_prepare_state(struct cmd *cmd, struct cmdq_item *item)
|
||||
{
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
struct cmd_state *state = &cmdq->state;
|
||||
char *tmp;
|
||||
enum cmd_entry_flag flag;
|
||||
const char *s;
|
||||
int error;
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
struct cmd_state *state = &item->state;
|
||||
char *tmp;
|
||||
enum cmd_entry_flag flag;
|
||||
const char *s;
|
||||
int error;
|
||||
|
||||
tmp = cmd_print(cmd);
|
||||
log_debug("preparing state for %s (client %p)", tmp, cmdq->client);
|
||||
log_debug("preparing state for %s (client %p)", tmp, item->client);
|
||||
free(tmp);
|
||||
|
||||
state->c = NULL;
|
||||
@@ -534,29 +597,37 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
|
||||
s = args_get(cmd->args, 'c');
|
||||
switch (flag) {
|
||||
case CMD_CLIENT:
|
||||
state->c = cmd_find_client(cmdq, s, 0);
|
||||
state->c = cmd_find_client(item, s, 0);
|
||||
if (state->c == NULL)
|
||||
return (-1);
|
||||
break;
|
||||
default:
|
||||
state->c = cmd_find_client(cmdq, s, 1);
|
||||
state->c = cmd_find_client(item, s, 1);
|
||||
break;
|
||||
}
|
||||
log_debug("using client %p", state->c);
|
||||
|
||||
s = args_get(cmd->args, 't');
|
||||
log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
|
||||
|
||||
error = cmd_prepare_state_flag('t', s, entry->tflag, cmdq, parent);
|
||||
error = cmd_prepare_state_flag('t', s, entry->tflag, item);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
s = args_get(cmd->args, 's');
|
||||
log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
|
||||
|
||||
error = cmd_prepare_state_flag('s', s, entry->sflag, cmdq, parent);
|
||||
error = cmd_prepare_state_flag('s', s, entry->sflag, item);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (!cmd_find_empty_state(&state->tflag) &&
|
||||
!cmd_find_valid_state(&state->tflag))
|
||||
fatalx("invalid -t state");
|
||||
if (!cmd_find_empty_state(&state->sflag) &&
|
||||
!cmd_find_valid_state(&state->sflag))
|
||||
fatalx("invalid -s state");
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -600,8 +671,10 @@ cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
|
||||
if (y < wp->yoff || y >= wp->yoff + wp->sy)
|
||||
return (-1);
|
||||
|
||||
*xp = x - wp->xoff;
|
||||
*yp = y - wp->yoff;
|
||||
if (xp != NULL)
|
||||
*xp = x - wp->xoff;
|
||||
if (yp != NULL)
|
||||
*yp = y - wp->yoff;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -649,8 +722,8 @@ char *
|
||||
cmd_template_replace(const char *template, const char *s, int idx)
|
||||
{
|
||||
char ch, *buf;
|
||||
const char *ptr;
|
||||
int replaced;
|
||||
const char *ptr, *cp, quote[] = "\"\\$";
|
||||
int replaced, quoted;
|
||||
size_t len;
|
||||
|
||||
if (strchr(template, '%') == NULL)
|
||||
@@ -672,9 +745,21 @@ cmd_template_replace(const char *template, const char *s, int idx)
|
||||
}
|
||||
ptr++;
|
||||
|
||||
len += strlen(s);
|
||||
buf = xrealloc(buf, len + 1);
|
||||
strlcat(buf, s, len + 1);
|
||||
quoted = (*ptr == '%');
|
||||
if (quoted)
|
||||
ptr++;
|
||||
|
||||
buf = xrealloc(buf, len + (strlen(s) * 3) + 1);
|
||||
for (cp = s; *cp != '\0'; cp++) {
|
||||
if (quoted && strchr(quote, *cp) != NULL)
|
||||
buf[len++] = '\\';
|
||||
if (quoted && *cp == ';') {
|
||||
buf[len++] = '\\';
|
||||
buf[len++] = '\\';
|
||||
}
|
||||
buf[len++] = *cp;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
continue;
|
||||
}
|
||||
buf = xrealloc(buf, len + 2);
|
||||
|
||||
2
colour.c
2
colour.c
@@ -48,7 +48,7 @@ colour_to_6cube(int v)
|
||||
* map our RGB colour to the closest in the cube, also work out the closest
|
||||
* grey, and use the nearest of the two.
|
||||
*
|
||||
* Note that the xterm has much lower resolution for darker colors (they are
|
||||
* Note that the xterm has much lower resolution for darker colours (they are
|
||||
* not evenly spread out), so our 6 levels are not evenly spread: 0x0, 0x5f
|
||||
* (95), 0x87 (135), 0xaf (175), 0xd7 (215) and 0xff (255). Greys are more
|
||||
* evenly spread (8, 18, 28 ... 238).
|
||||
|
||||
74
compat.h
74
compat.h
@@ -17,6 +17,14 @@
|
||||
#ifndef COMPAT_H
|
||||
#define COMPAT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(a)
|
||||
#endif
|
||||
@@ -43,11 +51,13 @@
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BSD_TYPES
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
#ifdef HAVE_ERR_H
|
||||
#include <err.h>
|
||||
#else
|
||||
void err(int, const char *, ...);
|
||||
void errx(int, const char *, ...);
|
||||
void warn(const char *, ...);
|
||||
void warnx(const char *, ...);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PATHS_H
|
||||
@@ -58,6 +68,16 @@ typedef uint64_t u_int64_t;
|
||||
#define _PATH_DEV "/dev/"
|
||||
#endif
|
||||
|
||||
#ifndef __OpenBSD__
|
||||
#define pledge(s, p) (0)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QUEUE_H
|
||||
#include <sys/queue.h>
|
||||
#else
|
||||
@@ -104,12 +124,6 @@ typedef uint64_t u_int64_t;
|
||||
#include "compat/imsg.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef BROKEN_CMSG_FIRSTHDR
|
||||
#undef CMSG_FIRSTHDR
|
||||
#define CMSG_FIRSTHDR(mhdr) \
|
||||
@@ -196,6 +210,16 @@ typedef uint64_t u_int64_t;
|
||||
#define flock(fd, op) (0)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_EXPLICIT_BZERO
|
||||
/* explicit_bzero.c */
|
||||
void explicit_bzero(void *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETDTABLECOUNT
|
||||
/* getdtablecount.c */
|
||||
int getdtablecount(void);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CLOSEFROM
|
||||
/* closefrom.c */
|
||||
void closefrom(int);
|
||||
@@ -226,6 +250,16 @@ size_t strlcpy(char *, const char *, size_t);
|
||||
size_t strlcat(char *, const char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNLEN
|
||||
/* strnlen.c */
|
||||
size_t strnlen(const char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
/* strndup.c */
|
||||
char *strndup(const char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
/* daemon.c */
|
||||
int daemon(int, int);
|
||||
@@ -242,9 +276,11 @@ void setproctitle(const char *, ...);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_B64_NTOP
|
||||
/* b64_ntop.c */
|
||||
#undef b64_ntop /* for Cygwin */
|
||||
/* base64.c */
|
||||
#undef b64_ntop
|
||||
#undef b64_pton
|
||||
int b64_ntop(const char *, size_t, char *, size_t);
|
||||
int b64_pton(const char *, u_char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
@@ -279,10 +315,9 @@ int unsetenv(const char *);
|
||||
void cfmakeraw(struct termios *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_OPENAT
|
||||
/* openat.c */
|
||||
#define AT_FDCWD -100
|
||||
int openat(int, const char *, int, ...);
|
||||
#ifndef HAVE_FREEZERO
|
||||
/* freezero.c */
|
||||
void freezero(void *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_REALLOCARRAY
|
||||
@@ -290,6 +325,11 @@ int openat(int, const char *, int, ...);
|
||||
void *reallocarray(void *, size_t, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RECALLOCARRAY
|
||||
/* recallocarray.c */
|
||||
void *recallocarray(void *, size_t, size_t, size_t);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTF8PROC
|
||||
/* utf8proc.c */
|
||||
int utf8proc_wcwidth(wchar_t);
|
||||
|
||||
@@ -14,16 +14,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
asprintf(char **ret, const char *fmt, ...)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* $OpenBSD: base64.c,v 1.8 2015/01/16 16:48:51 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996, 1998 by Internet Software Consortium.
|
||||
* Copyright (c) 1996 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -41,19 +43,18 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define Assert(Cond) if (!(Cond)) abort()
|
||||
|
||||
static const char Base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static const char Pad64 = '=';
|
||||
@@ -122,11 +123,16 @@ static const char Pad64 = '=';
|
||||
*/
|
||||
|
||||
int
|
||||
b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize) {
|
||||
b64_ntop(src, srclength, target, targsize)
|
||||
u_char const *src;
|
||||
size_t srclength;
|
||||
char *target;
|
||||
size_t targsize;
|
||||
{
|
||||
size_t datalength = 0;
|
||||
uint8_t input[3];
|
||||
uint8_t output[4];
|
||||
size_t i;
|
||||
u_char input[3];
|
||||
u_char output[4];
|
||||
int i;
|
||||
|
||||
while (2 < srclength) {
|
||||
input[0] = *src++;
|
||||
@@ -138,10 +144,6 @@ b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize) {
|
||||
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
|
||||
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
|
||||
output[3] = input[2] & 0x3f;
|
||||
Assert(output[0] < 64);
|
||||
Assert(output[1] < 64);
|
||||
Assert(output[2] < 64);
|
||||
Assert(output[3] < 64);
|
||||
|
||||
if (datalength + 4 > targsize)
|
||||
return (-1);
|
||||
@@ -161,9 +163,6 @@ b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize) {
|
||||
output[0] = input[0] >> 2;
|
||||
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
|
||||
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
|
||||
Assert(output[0] < 64);
|
||||
Assert(output[1] < 64);
|
||||
Assert(output[2] < 64);
|
||||
|
||||
if (datalength + 4 > targsize)
|
||||
return (-1);
|
||||
@@ -180,3 +179,137 @@ b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize) {
|
||||
target[datalength] = '\0'; /* Returned value doesn't count \0. */
|
||||
return (datalength);
|
||||
}
|
||||
|
||||
/* skips all whitespace anywhere.
|
||||
converts characters, four at a time, starting at (or after)
|
||||
src from base - 64 numbers into three 8 bit bytes in the target area.
|
||||
it returns the number of data bytes stored at the target, or -1 on error.
|
||||
*/
|
||||
|
||||
int
|
||||
b64_pton(src, target, targsize)
|
||||
char const *src;
|
||||
u_char *target;
|
||||
size_t targsize;
|
||||
{
|
||||
int tarindex, state, ch;
|
||||
u_char nextbyte;
|
||||
char *pos;
|
||||
|
||||
state = 0;
|
||||
tarindex = 0;
|
||||
|
||||
while ((ch = (unsigned char)*src++) != '\0') {
|
||||
if (isspace(ch)) /* Skip whitespace anywhere. */
|
||||
continue;
|
||||
|
||||
if (ch == Pad64)
|
||||
break;
|
||||
|
||||
pos = strchr(Base64, ch);
|
||||
if (pos == 0) /* A non-base64 character. */
|
||||
return (-1);
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (target) {
|
||||
if (tarindex >= targsize)
|
||||
return (-1);
|
||||
target[tarindex] = (pos - Base64) << 2;
|
||||
}
|
||||
state = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (target) {
|
||||
if (tarindex >= targsize)
|
||||
return (-1);
|
||||
target[tarindex] |= (pos - Base64) >> 4;
|
||||
nextbyte = ((pos - Base64) & 0x0f) << 4;
|
||||
if (tarindex + 1 < targsize)
|
||||
target[tarindex+1] = nextbyte;
|
||||
else if (nextbyte)
|
||||
return (-1);
|
||||
}
|
||||
tarindex++;
|
||||
state = 2;
|
||||
break;
|
||||
case 2:
|
||||
if (target) {
|
||||
if (tarindex >= targsize)
|
||||
return (-1);
|
||||
target[tarindex] |= (pos - Base64) >> 2;
|
||||
nextbyte = ((pos - Base64) & 0x03) << 6;
|
||||
if (tarindex + 1 < targsize)
|
||||
target[tarindex+1] = nextbyte;
|
||||
else if (nextbyte)
|
||||
return (-1);
|
||||
}
|
||||
tarindex++;
|
||||
state = 3;
|
||||
break;
|
||||
case 3:
|
||||
if (target) {
|
||||
if (tarindex >= targsize)
|
||||
return (-1);
|
||||
target[tarindex] |= (pos - Base64);
|
||||
}
|
||||
tarindex++;
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We are done decoding Base-64 chars. Let's see if we ended
|
||||
* on a byte boundary, and/or with erroneous trailing characters.
|
||||
*/
|
||||
|
||||
if (ch == Pad64) { /* We got a pad char. */
|
||||
ch = (unsigned char)*src++; /* Skip it, get next. */
|
||||
switch (state) {
|
||||
case 0: /* Invalid = in first position */
|
||||
case 1: /* Invalid = in second position */
|
||||
return (-1);
|
||||
|
||||
case 2: /* Valid, means one byte of info */
|
||||
/* Skip any number of spaces. */
|
||||
for (; ch != '\0'; ch = (unsigned char)*src++)
|
||||
if (!isspace(ch))
|
||||
break;
|
||||
/* Make sure there is another trailing = sign. */
|
||||
if (ch != Pad64)
|
||||
return (-1);
|
||||
ch = (unsigned char)*src++; /* Skip the = */
|
||||
/* Fall through to "single trailing =" case. */
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case 3: /* Valid, means two bytes of info */
|
||||
/*
|
||||
* We know this char is an =. Is there anything but
|
||||
* whitespace after it?
|
||||
*/
|
||||
for (; ch != '\0'; ch = (unsigned char)*src++)
|
||||
if (!isspace(ch))
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Now make sure for cases 2 and 3 that the "extra"
|
||||
* bits that slopped past the last full byte were
|
||||
* zeros. If we don't check them, they become a
|
||||
* subliminal channel.
|
||||
*/
|
||||
if (target && tarindex < targsize &&
|
||||
target[tarindex] != 0)
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* We ended by seeing the end of the string. Make sure we
|
||||
* have no partial bytes lying around.
|
||||
*/
|
||||
if (state != 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (tarindex);
|
||||
}
|
||||
@@ -15,9 +15,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
void
|
||||
cfmakeraw(struct termios *tio)
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef OPEN_MAX
|
||||
# define OPEN_MAX 256
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
daemon(int nochdir, int noclose)
|
||||
|
||||
93
compat/err.c
Normal file
93
compat/err.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@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 <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
void
|
||||
err(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int saved_errno = errno;
|
||||
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s\n", strerror(saved_errno));
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void
|
||||
errx(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
putc('\n', stderr);
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
void
|
||||
warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int saved_errno = errno;
|
||||
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, ": ");
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s\n", strerror(saved_errno));
|
||||
}
|
||||
|
||||
void
|
||||
warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
fprintf(stderr, "%s: ", getprogname());
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
putc('\n', stderr);
|
||||
}
|
||||
15
compat/explicit_bzero.c
Normal file
15
compat/explicit_bzero.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
|
||||
/*
|
||||
* Public domain.
|
||||
* Written by Matthew Dempsky.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
void
|
||||
explicit_bzero(void *buf, size_t len)
|
||||
{
|
||||
memset(buf, 0, len);
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
char *
|
||||
fgetln(FILE *fp, size_t *len)
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
pid_t
|
||||
forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
#include <stropts.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
pid_t
|
||||
forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
||||
|
||||
@@ -21,9 +21,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <stropts.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
pid_t
|
||||
forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* fparseln() specific operation flags.
|
||||
|
||||
31
compat/freezero.c
Normal file
31
compat/freezero.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@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 "compat.h"
|
||||
|
||||
void
|
||||
freezero(void *ptr, size_t size)
|
||||
{
|
||||
if (ptr != NULL) {
|
||||
memset(ptr, 0, size);
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@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
|
||||
@@ -18,38 +16,40 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include <glob.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* Clear pane history.
|
||||
*/
|
||||
#include "compat.h"
|
||||
|
||||
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *);
|
||||
void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
const struct cmd_entry cmd_clear_history_entry = {
|
||||
.name = "clear-history",
|
||||
.alias = "clearhist",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_clear_history_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_clear_history_exec(__unused struct cmd *self, struct cmd_q *cmdq)
|
||||
#ifdef HAVE_PROC_PID
|
||||
int
|
||||
getdtablecount(void)
|
||||
{
|
||||
struct window_pane *wp = cmdq->state.tflag.wp;
|
||||
struct grid *gd;
|
||||
char path[PATH_MAX];
|
||||
glob_t g;
|
||||
int n;
|
||||
|
||||
gd = cmdq->state.tflag.wp->base.grid;
|
||||
|
||||
if (wp->mode == &window_copy_mode)
|
||||
window_pane_reset_mode(wp);
|
||||
grid_clear_history(gd);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
||||
fatal("snprintf overflow");
|
||||
switch (glob(path, 0, NULL, &g)) {
|
||||
case GLOB_NOMATCH:
|
||||
return (0);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
fatal("glob(\"%s\") failed", path);
|
||||
}
|
||||
n = g.gl_pathc;
|
||||
globfree(&g);
|
||||
return (n);
|
||||
}
|
||||
#else
|
||||
int
|
||||
getdtablecount(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include <errno.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
|
||||
const char *
|
||||
getprogname(void)
|
||||
{
|
||||
extern char *program_invocation_short_name;
|
||||
|
||||
return (program_invocation_short_name);
|
||||
}
|
||||
#elif defined(HAVE___PROGNAME)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: imsg-buffer.c,v 1.7 2015/07/12 18:40:49 nicm Exp $ */
|
||||
/* $OpenBSD: imsg-buffer.c,v 1.10 2017/04/11 09:57:19 reyk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
#include "imsg.h"
|
||||
|
||||
int ibuf_realloc(struct ibuf *, size_t);
|
||||
@@ -78,7 +78,7 @@ ibuf_realloc(struct ibuf *buf, size_t len)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
b = realloc(buf->buf, buf->wpos + len);
|
||||
b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
|
||||
if (b == NULL)
|
||||
return (-1);
|
||||
buf->buf = b;
|
||||
@@ -180,7 +180,9 @@ again:
|
||||
void
|
||||
ibuf_free(struct ibuf *buf)
|
||||
{
|
||||
free(buf->buf);
|
||||
if (buf == NULL)
|
||||
return;
|
||||
freezero(buf->buf, buf->size);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: imsg.c,v 1.9 2015/07/12 18:40:49 nicm Exp $ */
|
||||
/* $OpenBSD: imsg.c,v 1.15 2017/04/11 09:57:19 reyk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@@ -25,47 +25,13 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
#include "compat.h"
|
||||
#include "imsg.h"
|
||||
|
||||
int imsg_fd_overhead = 0;
|
||||
|
||||
int imsg_get_fd(struct imsgbuf *);
|
||||
|
||||
int available_fds(unsigned int);
|
||||
|
||||
/*
|
||||
* The original code calls getdtablecount() which is OpenBSD specific. Use
|
||||
* available_fds() from OpenSMTPD instead.
|
||||
*/
|
||||
int
|
||||
available_fds(unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
int ret, fds[256];
|
||||
|
||||
if (n > (sizeof(fds)/sizeof(fds[0])))
|
||||
return (1);
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
fds[i] = -1;
|
||||
if ((fds[i] = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
|
||||
fds[i] = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (fds[i] < 0) {
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < n && fds[i] >= 0; i++)
|
||||
close(fds[i]);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||
{
|
||||
@@ -105,19 +71,18 @@ imsg_read(struct imsgbuf *ibuf)
|
||||
return (-1);
|
||||
|
||||
again:
|
||||
if (available_fds(imsg_fd_overhead +
|
||||
(CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))) {
|
||||
if (getdtablecount() + imsg_fd_overhead +
|
||||
(int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
|
||||
>= getdtablesize()) {
|
||||
errno = EAGAIN;
|
||||
free(ifd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
|
||||
if (errno == EMSGSIZE)
|
||||
goto fail;
|
||||
if (errno != EINTR && errno != EAGAIN)
|
||||
goto fail;
|
||||
goto again;
|
||||
if (errno == EINTR)
|
||||
goto again;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ibuf->r.wpos += n;
|
||||
@@ -151,8 +116,7 @@ again:
|
||||
}
|
||||
|
||||
fail:
|
||||
if (ifd)
|
||||
free(ifd);
|
||||
free(ifd);
|
||||
return (n);
|
||||
}
|
||||
|
||||
@@ -176,7 +140,9 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
||||
return (0);
|
||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
|
||||
if ((imsg->data = malloc(datalen)) == NULL)
|
||||
if (datalen == 0)
|
||||
imsg->data = NULL;
|
||||
else if ((imsg->data = malloc(datalen)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (imsg->hdr.flags & IMSGF_HASFD)
|
||||
@@ -197,8 +163,8 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
||||
}
|
||||
|
||||
int
|
||||
imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
pid_t pid, int fd, const void *data, u_int16_t datalen)
|
||||
imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
int fd, const void *data, uint16_t datalen)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
|
||||
@@ -216,8 +182,8 @@ imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
}
|
||||
|
||||
int
|
||||
imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
pid_t pid, int fd, const struct iovec *iov, int iovcnt)
|
||||
imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
int fd, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
int i, datalen = 0;
|
||||
@@ -241,8 +207,8 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
|
||||
/* ARGSUSED */
|
||||
struct ibuf *
|
||||
imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
pid_t pid, u_int16_t datalen)
|
||||
imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
uint16_t datalen)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
struct imsg_hdr hdr;
|
||||
@@ -268,7 +234,7 @@ imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
|
||||
}
|
||||
|
||||
int
|
||||
imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen)
|
||||
imsg_add(struct ibuf *msg, const void *data, uint16_t datalen)
|
||||
{
|
||||
if (datalen)
|
||||
if (ibuf_add(msg, data, datalen) == -1) {
|
||||
@@ -289,7 +255,7 @@ imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
||||
if (msg->fd != -1)
|
||||
hdr->flags |= IMSGF_HASFD;
|
||||
|
||||
hdr->len = (u_int16_t)msg->wpos;
|
||||
hdr->len = (uint16_t)msg->wpos;
|
||||
|
||||
ibuf_close(&ibuf->w, msg);
|
||||
}
|
||||
@@ -297,7 +263,7 @@ imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
||||
void
|
||||
imsg_free(struct imsg *imsg)
|
||||
{
|
||||
free(imsg->data);
|
||||
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: imsg.h,v 1.3 2013/12/26 17:32:33 eric Exp $ */
|
||||
/* $OpenBSD: imsg.h,v 1.4 2017/03/24 09:34:12 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
||||
@@ -18,8 +18,6 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#ifndef _IMSG_H_
|
||||
#define _IMSG_H_
|
||||
|
||||
@@ -39,7 +37,7 @@ struct ibuf {
|
||||
|
||||
struct msgbuf {
|
||||
TAILQ_HEAD(, ibuf) bufs;
|
||||
u_int32_t queued;
|
||||
uint32_t queued;
|
||||
int fd;
|
||||
};
|
||||
|
||||
@@ -65,11 +63,11 @@ struct imsgbuf {
|
||||
#define IMSGF_HASFD 1
|
||||
|
||||
struct imsg_hdr {
|
||||
u_int32_t type;
|
||||
u_int16_t len;
|
||||
u_int16_t flags;
|
||||
u_int32_t peerid;
|
||||
u_int32_t pid;
|
||||
uint32_t type;
|
||||
uint16_t len;
|
||||
uint16_t flags;
|
||||
uint32_t peerid;
|
||||
uint32_t pid;
|
||||
};
|
||||
|
||||
struct imsg {
|
||||
@@ -99,13 +97,12 @@ void msgbuf_drain(struct msgbuf *, size_t);
|
||||
void imsg_init(struct imsgbuf *, int);
|
||||
ssize_t imsg_read(struct imsgbuf *);
|
||||
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
||||
int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||
int, const void *, u_int16_t);
|
||||
int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||
int, const struct iovec *, int);
|
||||
struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
|
||||
u_int16_t);
|
||||
int imsg_add(struct ibuf *, const void *, u_int16_t);
|
||||
int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
||||
const void *, uint16_t);
|
||||
int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
||||
const struct iovec *, int);
|
||||
struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t);
|
||||
int imsg_add(struct ibuf *, const void *, uint16_t);
|
||||
void imsg_close(struct imsgbuf *, struct ibuf *);
|
||||
void imsg_free(struct imsg *);
|
||||
int imsg_flush(struct imsgbuf *);
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@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 <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) {
|
||||
saved_errno = errno;
|
||||
close(dotfd);
|
||||
errno = saved_errno;
|
||||
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);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user