Skip to content
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

Add plugin to clone ssh and container sessions when terminal is split #924

Merged
merged 3 commits into from
Jun 23, 2024
Merged

Add plugin to clone ssh and container sessions when terminal is split #924

merged 3 commits into from
Jun 23, 2024

Conversation

asifamin13
Copy link
Contributor

Remote Plugin

A Terminator plugin which adds features for ssh and docker/podman to the context menu.

Self contained and only relies on psutil.

From the terminator docs online

Probably the most useful thing would be something to help customise Terminator for heavy ssh users

Alt Text

Clone Horizontally/Vertically

This will clone your current SSH/container session into a newly spawned terminal

Heavily inspired by terminator_plugins which is no longer maintained. My version doesn't need to subclass Terminal and only needs vte.feed_child

Profile Host Matching

When you clone a remote session, you can apply a terminator profile based on host or container name

Inspired by TerminatorHostWatch which does this via regex matching a PS1. Instead of using a regex my version uses the process info provided via psutil

Configuration

Plugin section in ~/.config/terminator/config :

[plugins]
  [[Remote]]
    # Automatically clone when you split a terminal with a remote session
    auto_clone = False

    # When a terminal with a remote session is cloned, attempt to parse the
    # current working directory via the PS1 and 'cd' into it
    infer_cwd = True

    # Optional default profile for all SSH sessions
    ssh_default_profile = common_ssh_profile

    # Optional default profile for all container sessions
    container_default_profile = common_docker_profile

    # You can override above defaults by specifing a host with a profile key
    # ex:
    [[[foo]]]
      profile = foo_profile

@mattrose
Copy link
Member

At first glance this looks like something that would be really great. I'm going to pull it down and play with it for a bit just to see how to use it, but I can't see any reason not to merge it. I'm very impressed that you were able to do this all within the plugin system.

@asifamin13
Copy link
Contributor Author

@mattrose thanks! let me know if you have any suggestions or improvements

@mattrose
Copy link
Member

I'm getting this error when I try to clone with split.

Traceback (most recent call last):
  File "/Users/mattrose/Code/terminator/terminatorlib/plugins/remote.py", line 680, in _split_axis
    self.remote_cwd = self._get_cwd_from_lines(terminal)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mattrose/Code/terminator/terminatorlib/plugins/remote.py", line 499, in _get_cwd_from_lines
    matches = list(self.cwd_regex.finditer(lines))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

and the prompt is just
mattrose@fiesole:~$

Maybe it's having trouble interpreting the ~ ?

@mattrose
Copy link
Member

Nope, it's another VTE Deprecation. vte.get_text_range() starts returning null in 0.76, and you have to use the new as of 0.72 vte.get_text_range_format(), call.
Which means that we have to detect which version of vte the user is running and make the right method call.
I have some idea on how to do this but I haven't coded it yet. Would you like me to continue, or do you want to code this up?

@mattrose
Copy link
Member

Either way, I'm keeping this, this is a great feature, coded very well, thank you.

@asifamin13
Copy link
Contributor Author

Ahh good catch! You can go ahead and patch it if you feel up to it. When I get back home tonight I can fix it also

@mattrose
Copy link
Member

easier if you do it, then you can just push the new changes to your branch and they should get automatically added to the PR.

@asifamin13
Copy link
Contributor Author

@mattrose just pushed the patch. It will check if vte >= 0.72 and call get_text_range_format appropriately. I tested this on Ubuntu 24 and 22 and works as expected either way.

Let me know what you think!

@mattrose
Copy link
Member

That patch looks great, pulling it in now.

@mattrose mattrose merged commit e42d8b6 into gnome-terminator:master Jun 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants