diff --git a/docs/examples.md b/docs/examples.md index 83b0c67c577..48880e80c06 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -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 diff --git a/examples/pane-shell.json b/examples/pane-shell.json new file mode 100644 index 00000000000..1a4b6af487c --- /dev/null +++ b/examples/pane-shell.json @@ -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 and then `:q!` to get out of this vim window. :-)" + ] + }, + { + "shell_command": [ + "print('Hello World 2')" + ] + }, + { + "shell": "/usr/bin/top" + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/pane-shell.yaml b/examples/pane-shell.yaml new file mode 100644 index 00000000000..0fee4fdea62 --- /dev/null +++ b/examples/pane-shell.yaml @@ -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. + - 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 and then `:q!` to get out of this vim window. :-) + - shell_command: + - print('Hello World 2') + - shell: /usr/bin/top diff --git a/tmuxp/workspacebuilder.py b/tmuxp/workspacebuilder.py index 3263342a2e1..16ab6e90a1a 100644 --- a/tmuxp/workspacebuilder.py +++ b/tmuxp/workspacebuilder.py @@ -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, @@ -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)