1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
use crate::data::{Direction, InputMode, Resize};
use crate::setup::Setup;
use crate::{
consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV},
input::options::CliOptions,
};
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)]
#[clap(version, name = "zellij")]
pub struct CliArgs {
/// Maximum panes on screen, caution: opening more panes will close old ones
#[clap(long, value_parser)]
pub max_panes: Option<usize>,
/// Change where zellij looks for plugins
#[clap(long, value_parser, overrides_with = "data_dir")]
pub data_dir: Option<PathBuf>,
/// Run server listening at the specified socket path
#[clap(long, value_parser, hide = true, overrides_with = "server")]
pub server: Option<PathBuf>,
/// Specify name of a new session
#[clap(long, short, overrides_with = "session", value_parser)]
pub session: Option<String>,
/// Name of a predefined layout inside the layout directory or the path to a layout file
#[clap(short, long, value_parser, overrides_with = "layout")]
pub layout: Option<PathBuf>,
/// Change where zellij looks for the configuration file
#[clap(short, long, overrides_with = "config", env = ZELLIJ_CONFIG_FILE_ENV, value_parser)]
pub config: Option<PathBuf>,
/// Change where zellij looks for the configuration directory
#[clap(long, overrides_with = "config_dir", env = ZELLIJ_CONFIG_DIR_ENV, value_parser)]
pub config_dir: Option<PathBuf>,
#[clap(subcommand)]
pub command: Option<Command>,
/// Specify emitting additional debug information
#[clap(short, long, value_parser)]
pub debug: bool,
}
#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum Command {
/// Change the behaviour of zellij
#[clap(name = "options", value_parser)]
Options(CliOptions),
/// Setup zellij and check its configuration
#[clap(name = "setup", value_parser)]
Setup(Setup),
/// Explore existing zellij sessions
#[clap(flatten)]
Sessions(Sessions),
}
#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum SessionCommand {
/// Change the behaviour of zellij
#[clap(name = "options")]
Options(CliOptions),
}
#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum Sessions {
/// List active sessions
#[clap(visible_alias = "ls")]
ListSessions,
/// Attach to a session
#[clap(visible_alias = "a")]
Attach {
/// Name of the session to attach to.
#[clap(value_parser)]
session_name: Option<String>,
/// Create a session if one does not exist.
#[clap(short, long, value_parser)]
create: bool,
/// Number of the session index in the active sessions ordered creation date.
#[clap(long, value_parser)]
index: Option<usize>,
/// Change the behaviour of zellij
#[clap(subcommand, name = "options")]
options: Option<Box<SessionCommand>>,
},
/// Kill the specific session
#[clap(visible_alias = "k")]
KillSession {
/// Name of target session
#[clap(value_parser)]
target_session: Option<String>,
},
/// Kill all sessions
#[clap(visible_alias = "ka")]
KillAllSessions {
/// Automatic yes to prompts
#[clap(short, long, value_parser)]
yes: bool,
},
/// Send actions to a specific session
#[clap(visible_alias = "ac")]
#[clap(subcommand)]
Action(CliAction),
/// Run a command in a new pane
#[clap(visible_alias = "r")]
Run {
/// Command to run
#[clap(last(true), required(true))]
command: Vec<String>,
/// Direction to open the new pane in
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
/// Change the working directory of the new pane
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
/// Open the new pane in floating mode
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
/// Name of the new pane
#[clap(short, long, value_parser)]
name: Option<String>,
/// Close the pane immediately when its command exits
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
close_on_exit: bool,
/// Start the command suspended, only running after you first presses ENTER
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
start_suspended: bool,
},
/// Edit file with default $EDITOR / $VISUAL
#[clap(visible_alias = "e")]
Edit {
file: PathBuf,
/// Open the file in the specified line number
#[clap(short, long, value_parser)]
line_number: Option<usize>,
/// Direction to open the new pane in
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
/// Open the new pane in floating mode
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
/// Change the working directory of the editor
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
},
ConvertConfig {
old_config_file: PathBuf,
},
ConvertLayout {
old_layout_file: PathBuf,
},
ConvertTheme {
old_theme_file: PathBuf,
},
}
#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
pub enum CliAction {
/// Write bytes to the terminal.
Write {
bytes: Vec<u8>,
},
/// Write characters to the terminal.
WriteChars {
chars: String,
},
/// [increase|decrease] the focused panes area at the [left|down|up|right] border.
Resize {
resize: Resize,
direction: Option<Direction>,
},
/// Change focus to the next pane
FocusNextPane,
/// Change focus to the previous pane
FocusPreviousPane,
/// Move the focused pane in the specified direction. [right|left|up|down]
MoveFocus {
direction: Direction,
},
/// Move focus to the pane or tab (if on screen edge) in the specified direction
/// [right|left|up|down]
MoveFocusOrTab {
direction: Direction,
},
/// Change the location of the focused pane in the specified direction or rotate forwrads
/// [right|left|up|down]
MovePane {
direction: Option<Direction>,
},
/// Rotate the location of the previous pane backwards
MovePaneBackwards,
/// Clear all buffers for a focused pane
Clear,
/// Dump the focused pane to a file
DumpScreen {
path: PathBuf,
/// Dump the pane with full scrollback
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
full: bool,
},
/// Open the pane scrollback in your default editor
EditScrollback,
/// Scroll up in the focused pane
ScrollUp,
/// Scroll down in focus pane.
ScrollDown,
/// Scroll down to bottom in focus pane.
ScrollToBottom,
/// Scroll up to top in focus pane.
ScrollToTop,
/// Scroll up one page in focus pane.
PageScrollUp,
/// Scroll down one page in focus pane.
PageScrollDown,
/// Scroll up half page in focus pane.
HalfPageScrollUp,
/// Scroll down half page in focus pane.
HalfPageScrollDown,
/// Toggle between fullscreen focus pane and normal layout.
ToggleFullscreen,
/// Toggle frames around panes in the UI
TogglePaneFrames,
/// Toggle between sending text commands to all panes on the current tab and normal mode.
ToggleActiveSyncTab,
/// Open a new pane in the specified direction [right|down]
/// If no direction is specified, will try to use the biggest available space.
NewPane {
/// Direction to open the new pane in
#[clap(short, long, value_parser, conflicts_with("floating"))]
direction: Option<Direction>,
#[clap(last(true))]
command: Vec<String>,
#[clap(short, long, conflicts_with("command"), conflicts_with("direction"))]
plugin: Option<String>,
/// Change the working directory of the new pane
#[clap(long, value_parser)]
cwd: Option<PathBuf>,
/// Open the new pane in floating mode
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
/// Name of the new pane
#[clap(short, long, value_parser)]
name: Option<String>,
/// Close the pane immediately when its command exits
#[clap(
short,
long,
valu
|