Skip to content

Commit

Permalink
Remote terminal nemo action
Browse files Browse the repository at this point in the history
"Open in remote terminal" option was missing in nemo context menu.
Added the option by creating a new in-built action in
/usr/share/nemo/actions which runs a python script to invoke ssh in
terminal. More detailed benefits can be found in #2824
  • Loading branch information
hsbasu committed Dec 16, 2021
1 parent 33bae1f commit 068d1bd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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
31 changes: 31 additions & 0 deletions files/usr/share/nemo/actions/remote_terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# On linux-systems, root an sftp location is mounted at:
# /run/user/<uid>/gvfs/sftp:host=<host-ip>

import os
import sys
import subprocess

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

# remote uri
uri = sys.argv[1]
print(uri)
# remote user
remote_user = os.environ['USER']

host_full_path = uri.split('sftp:', 1)[1]

ssh_args = {}
ssh_args['remote_user'] = remote_user
remote_host, sep, ssh_args['remote_path'] = host_full_path.partition('/')

name, sep, remote_ip = remote_host.partition('=')
ssh_args['remote_ip'] = remote_ip

# 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)

0 comments on commit 068d1bd

Please sign in to comment.