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

[WIP] Remote terminal nemo action #2895

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions files/usr/share/nemo/actions/remote_terminal.nemo_action
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Nemo Action]
Name=Open in Remote Terminal
Comment=Open a remote terminal in the active remote folder
Exec=<remote_terminal.py %F>
Icon-Name=utilities-terminal-symbolic
Selection=any
Extensions=dir;
# conditions=exec <remote_terminal.py %U>;
Dependencies=ssh;
UriScheme=sftp
64 changes: 64 additions & 0 deletions files/usr/share/nemo/actions/remote_terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# On linux-systems, root of an sftp location is usually mounted at:
# /run/user/<uid>/gvfs/sftp:host=<host-ip>

import os
import sys
import subprocess
print("")

def call_remote(uri):
remote_address = uri.split('sftp:', 1)[1]
# print(remote_address)

if "," in remote_address:
# in case "/run/user/<uid>/gvfs/sftp:host=<ip>,user=<username>/path"
# is passed
remote_host, sep, remote_userpath = remote_address.partition(',')
# print(remote_address.partition(','))

# remote path
remote_user, sep, remote_path = remote_userpath.partition('/')
# print(remote_userpath.partition('/'))

# remote user
# print(remote_user.partition('='))
key, sep, remote_user = remote_user.partition('=')

# remote ip
key, sep, remote_ip = remote_host.partition('=')
# print(remote_host.partition('='))
else:
# in case "/run/user/<uid>/gvfs/sftp:host=<ip>/path" is passed
# remote path
remote_host, sep, remote_path = remote_address.partition('/')
# print(remote_address.partition('/'))

# remote user
remote_user = os.environ['USER']

# remote ip
key, sep, remote_ip = remote_host.partition('=')
# print(remote_host.partition('='))

ssh_args = {}
ssh_args['remote_user'] = remote_user
ssh_args['remote_ip'] = remote_ip
ssh_args['remote_path'] = remote_path

# run ssh command
remote_cmd = [terminal, '-e',
'ssh %(remote_user)s@%(remote_ip)s -t "cd /%(remote_path)s; $SHELL"' % ssh_args]
subprocess.call(remote_cmd)


# terminal application
terminal="x-terminal-emulator"

# remote uri
uris = sys.argv[1:]
# print(uris)
for uri in uris:
# print(uri)
call_remote(uri)