Skip to content

Add shell-configuration to pane layer #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ without `window_index` will use the lowest available window index.

```

## Shell per pane

Every pane can have its own shell or application started. This allows for usage
of the ``remain-on-exit`` setting to be used properly, but also to have
different shells on different panes.

### YAML

```{literalinclude} ../examples/pane-shell.yaml
:language: yaml

```

### JSON

```{literalinclude} ../examples/pane-shell.json
:language: json

```

## Set tmux options

Works with global (server-wide) options, session options
Expand Down
40 changes: 40 additions & 0 deletions examples/pane-shell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"session_name": "Pane shell example",
"windows": [
{
"window_name": "first",
"window_shell": "/usr/bin/python2",
"layout": "even-vertical",
"suppress_history": false,
"options": {
"remain-on-exit": true
},
"panes": [
{
"shell": "/usr/bin/python3",
"shell_command": [
"print('This is python 3')"
]
},
{
"shell": "/usr/bin/vim -u none",
"shell_command": [
"iAll panes have the `remain-on-exit` setting on.",
"When you exit out of the shell or application, the panes will remain.",
"Use tmux command `:kill-pane` to remove the pane.",
"Use tmux command `:respawn-pane` to restart the shell in the pane.",
"Use <Escape> and then `:q!` to get out of this vim window. :-)"
]
},
{
"shell_command": [
"print('Hello World 2')"
]
},
{
"shell": "/usr/bin/top"
}
]
}
]
}
22 changes: 22 additions & 0 deletions examples/pane-shell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
session_name: Pane shell example
windows:
- window_name: first
window_shell: /usr/bin/python2
layout: even-vertical
suppress_history: false
options:
remain-on-exit: true
panes:
- shell: /usr/bin/python3
shell_command:
- print('This is python 3')
- shell: /usr/bin/vim -u none
shell_command:
- iAll panes have the `remain-on-exit` setting on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- iAll panes have the `remain-on-exit` setting on.
- All panes have the `remain-on-exit` setting on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. I'm wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

Copy link
Member

@tony tony Jan 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i... Insert

I've been in vim every day for 15+ years and this got past me

- When you exit out of the shell or application, the panes will remain.
- Use tmux command `:kill-pane` to remove the pane.
- Use tmux command `:respawn-pane` to restart the shell in the pane.
- Use <Escape> and then `:q!` to get out of this vim window. :-)
- shell_command:
- print('Hello World 2')
- shell: /usr/bin/top
21 changes: 20 additions & 1 deletion tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ def iter_create_windows(self, session, append=False):
else:
ws = None

# If the first pane specifies a shell, use that instead.
try:
if wconf['panes'][0]['shell'] != '':
ws = wconf['panes'][0]['shell']
except (KeyError, IndexError):
pass

w = session.new_window(
window_name=window_name,
start_directory=sd,
Expand Down Expand Up @@ -328,8 +335,20 @@ def get_pane_start_directory():
else:
return None

def get_pane_shell():

if 'shell' in pconf:
return pconf['shell']
elif 'window_shell' in wconf:
return wconf['window_shell']
else:
return None

p = w.split_window(
attach=True, start_directory=get_pane_start_directory(), target=p.id
attach=True,
start_directory=get_pane_start_directory(),
shell=get_pane_shell(),
target=p.id
)

assert isinstance(p, Pane)
Expand Down