From cec24e59c04b635481665b01a84f1c93815603b7 Mon Sep 17 00:00:00 2001 From: Gerhard Hellmann Date: Sat, 27 Feb 2021 23:16:29 +0100 Subject: [PATCH 1/3] 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. --- tmuxp/workspacebuilder.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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) From ca320565080f3269829967fc3606060c3327ff18 Mon Sep 17 00:00:00 2001 From: Gerhard Hellmann Date: Wed, 3 Mar 2021 22:06:23 +0100 Subject: [PATCH 2/3] Added an example for the pane-shell configuration. --- examples/pane-shell.json | 40 ++++++++++++++++++++++++++++++++++++++++ examples/pane-shell.yaml | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 examples/pane-shell.json create mode 100644 examples/pane-shell.yaml 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 From 2ad5f96122f52440c777715c3c882ef76c8688c5 Mon Sep 17 00:00:00 2001 From: Gerhard Hellmann Date: Sat, 24 Jul 2021 22:12:33 +0200 Subject: [PATCH 3/3] Added the documentation to the example.md file instead. As the examples.rst files was replaced by the md-files in the main line. --- docs/examples.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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