Skip to content

Commit 7b84844

Browse files
authored
feature(workspace builder): Add shell-configuration to pane layer (#672)
* Added the ability to specify `shell` per pane. Had to implement the special case for the first pane. In that case the shell for the window that is created has to be overridden. This also fixed a bug (in my opinion) that `window_shell` only affected the first pane, and none of the other panes in a window. The system unfortunatelly still bailes out, when the specified shell is not executable (e.g. doesn't even exist). The problem is an unhandeled exception when the information for the pane can't be extracted (as it never really started). Not sure how to catch that and provide a sensible message to the user. * Added an example for the pane-shell configuration. * Added the documentation to the example.md file instead. As the examples.rst files was replaced by the md-files in the main line.
1 parent f5524b7 commit 7b84844

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

docs/examples.md

+20
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,26 @@ without `window_index` will use the lowest available window index.
307307

308308
```
309309

310+
## Shell per pane
311+
312+
Every pane can have its own shell or application started. This allows for usage
313+
of the ``remain-on-exit`` setting to be used properly, but also to have
314+
different shells on different panes.
315+
316+
### YAML
317+
318+
```{literalinclude} ../examples/pane-shell.yaml
319+
:language: yaml
320+
321+
```
322+
323+
### JSON
324+
325+
```{literalinclude} ../examples/pane-shell.json
326+
:language: json
327+
328+
```
329+
310330
## Set tmux options
311331

312332
Works with global (server-wide) options, session options

examples/pane-shell.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"session_name": "Pane shell example",
3+
"windows": [
4+
{
5+
"window_name": "first",
6+
"window_shell": "/usr/bin/python2",
7+
"layout": "even-vertical",
8+
"suppress_history": false,
9+
"options": {
10+
"remain-on-exit": true
11+
},
12+
"panes": [
13+
{
14+
"shell": "/usr/bin/python3",
15+
"shell_command": [
16+
"print('This is python 3')"
17+
]
18+
},
19+
{
20+
"shell": "/usr/bin/vim -u none",
21+
"shell_command": [
22+
"iAll panes have the `remain-on-exit` setting on.",
23+
"When you exit out of the shell or application, the panes will remain.",
24+
"Use tmux command `:kill-pane` to remove the pane.",
25+
"Use tmux command `:respawn-pane` to restart the shell in the pane.",
26+
"Use <Escape> and then `:q!` to get out of this vim window. :-)"
27+
]
28+
},
29+
{
30+
"shell_command": [
31+
"print('Hello World 2')"
32+
]
33+
},
34+
{
35+
"shell": "/usr/bin/top"
36+
}
37+
]
38+
}
39+
]
40+
}

examples/pane-shell.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
session_name: Pane shell example
2+
windows:
3+
- window_name: first
4+
window_shell: /usr/bin/python2
5+
layout: even-vertical
6+
suppress_history: false
7+
options:
8+
remain-on-exit: true
9+
panes:
10+
- shell: /usr/bin/python3
11+
shell_command:
12+
- print('This is python 3')
13+
- shell: /usr/bin/vim -u none
14+
shell_command:
15+
- iAll panes have the `remain-on-exit` setting on.
16+
- When you exit out of the shell or application, the panes will remain.
17+
- Use tmux command `:kill-pane` to remove the pane.
18+
- Use tmux command `:respawn-pane` to restart the shell in the pane.
19+
- Use <Escape> and then `:q!` to get out of this vim window. :-)
20+
- shell_command:
21+
- print('Hello World 2')
22+
- shell: /usr/bin/top

tmuxp/workspacebuilder.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ def iter_create_windows(self, session, append=False):
265265
else:
266266
ws = None
267267

268+
# If the first pane specifies a shell, use that instead.
269+
try:
270+
if wconf['panes'][0]['shell'] != '':
271+
ws = wconf['panes'][0]['shell']
272+
except (KeyError, IndexError):
273+
pass
274+
268275
w = session.new_window(
269276
window_name=window_name,
270277
start_directory=sd,
@@ -328,8 +335,20 @@ def get_pane_start_directory():
328335
else:
329336
return None
330337

338+
def get_pane_shell():
339+
340+
if 'shell' in pconf:
341+
return pconf['shell']
342+
elif 'window_shell' in wconf:
343+
return wconf['window_shell']
344+
else:
345+
return None
346+
331347
p = w.split_window(
332-
attach=True, start_directory=get_pane_start_directory(), target=p.id
348+
attach=True,
349+
start_directory=get_pane_start_directory(),
350+
shell=get_pane_shell(),
351+
target=p.id
333352
)
334353

335354
assert isinstance(p, Pane)

0 commit comments

Comments
 (0)