Skip to content

Instantly share code, notes, and snippets.

@otherwiseguy
Last active May 18, 2017 22:47
Show Gist options
  • Save otherwiseguy/fa4605d07176fbf5468338c0cd43520c to your computer and use it in GitHub Desktop.
Save otherwiseguy/fa4605d07176fbf5468338c0cd43520c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import logging
import re
import subprocess
import sys
logging.basicConfig()
LOG = logging.getLogger()
try:
r = re.compile(r'(?P<proto>\w+)://\[?(?P<addr>.*?)\]?:?(?P<port>\d+)?/?$')
m = r.search(sys.argv[1]).groupdict()
proto_map = {
'telnet': ('telnet', m['addr'], m['port'] or '23'),
'gopher': ('gopher', m['proto'] + '://' + m['addr'],
m['port'] or '70'),
}
subprocess.call(proto_map[m['proto']])
except Exception as e:
LOG.exception(e)
input("Press Enter to continue...")
[Desktop Entry]
Version=1.0
Name=Telnet
GenericName=Telnet
Comment=Telnet Client
Exec=/home/terry/bin/runproto.py %U
Terminal=true
Type=Application
Categories=TerminalEmulator;Network;Telnet;Internet;BBS;
MimeType=x-scheme/telnet
X-KDE-Protocols=telnet
Keywords=Terminal;Emulator;Network;Internet;BBS;Telnet;Client;
@otherwiseguy
Copy link
Author

telnet.desktop goes in ~/.local/share/applications then run:

$ xdg-mime default telnet.desktop x-scheme-handler/telnet

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