Created
September 4, 2015 22:11
-
-
Save yousefamar/ad5edbb5adb65b588625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import os, subprocess, sys, urlparse | |
def detach_open(cmd, cwd=None): | |
# Thanks to the vast knowledge of Laurence Withers (lwithers) and this message: | |
# http://mail.python.org/pipermail/python-list/2006-November/587523.html | |
if not os.fork(): | |
null = os.open(os.devnull,os.O_WRONLY) | |
for i in range(3): os.dup2(null,i) | |
os.close(null) | |
subprocess.Popen(cmd, cwd=cwd) | |
print 'USED' | |
if __name__ == '__main__': | |
uri = sys.argv[1] | |
u = urlparse.urlparse(uri) | |
if u.scheme == 'mailto': | |
detach_open(['uzbl-browser', 'https://mail.google.com/mail/?view=cm&fs=1&to='+u.path]) | |
elif u.scheme == 'xmpp': | |
# Someone check for safe arguments to gajim-remote | |
detach_open(['gajim-remote', 'open_chat', uri]) | |
elif u.scheme == 'git': | |
detach_open(['git', 'clone', '--', uri], os.path.expanduser('~/src')) | |
elif u.scheme == 'magnet': | |
detach_open(['evilvte', '-title', 'rTorrent', '-e', 'rtorrent', uri]) | |
elif u.netloc in ['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtu.be']: | |
detach_open(['vlc', '-I dummy', '--quiet', '--play-and-exit', uri]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment