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

Plugin ssh-host: implement copy ip to clipboard action ? #169

Closed
khurshid-alam opened this issue Jul 17, 2023 · 1 comment
Closed

Plugin ssh-host: implement copy ip to clipboard action ? #169

khurshid-alam opened this issue Jul 17, 2023 · 1 comment

Comments

@khurshid-alam
Copy link

khurshid-alam commented Jul 17, 2023

My ssh hosts includes something like, (note, it has aliases for small letter since gvfs doesn't support capital letter in Host).

 Host Jammy-Dev jammy-dev
	User vncuser
	HostName 95.219.x.x
	Port 22
	ProxyCommand ssh -W %h:%p SecureServer

Sometimes I need quickly need the ip address of my server. My attempt is so far is a hack to find ip with command-line tool,

class CopyIP (Action):
    # rank down since it applies everywhere
    #rank_adjust = -2
    action_accelerator = "c"
    def __init__(self):
        Action.__init__(self, _("Copy Host IP Address"))

    def activate(self, leaf):
        cmd = "ssh -G " + leaf[HOST_ADDRESS_KEY] + " | grep -E '^hostname' | awk -F ' '  '{{print $2}}' | tr -d '\n'"
        proc = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=None)
        ip_addr = (proc.communicate()[0]).decode("utf-8")
        clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        clip.set_text(ip_addr, -1)

    def item_types(self):
        yield HostLeaf

    def valid_for_item(self, item):
        if item.check_key(HOST_SERVICE_NAME_KEY):
            return item[HOST_SERVICE_NAME_KEY] == 'ssh'
        return False

    def get_description(self):
        return _("Copy Host IP Address")

    def get_icon_name(self):
        return "edit-paste"

However this doesn't have to be the case. Host object already contains,

HOST_NAME_KEY = "HOST_NAME"
HOST_ADDRESS_KEY = "HOST_ADDRESS"

and so far the plugin is using name for both in SSHSource. So it can pull and while ssh-connect can use leaf[HOST_NAME_KEY], copy-ip can use leaf[HOST_ADDRESS_KEY]

(There will be some edge cases which needs to be handled.)

Edit: I saw the new beta, I haven't tested this. but perhaps it better to implement in beta.

Environment

Kupfer Version: V320
Window Manager: Unity/Compiz
Desktop Environment: Unity
Linux Distribution: Ubuntu 22.04

@KarolBedkowski Thoughts ?

@KarolBedkowski
Copy link
Contributor

I think this may be useful as long this action will be global - for all HostLeaves, not only for ssh.
Of course SSHSource need modification and maybe other sources.

I'll look at it in next free moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants