7286703f62a5fe868f629eae07434e1c852856fa
[uzbl-mobile] / examples / data / uzbl / scripts / scheme.py
1 #!/usr/bin/env python
2
3 import os, subprocess, sys, urlparse
4
5 def detach_open(cmd):
6     # Thanks to the vast knowledge of Laurence Withers (lwithers) and this message:
7     # http://mail.python.org/pipermail/python-list/2006-November/587523.html
8     if not os.fork():
9         null = os.open(os.devnull,os.O_WRONLY)
10         for i in range(3): os.dup2(null,i)
11         os.close(null)
12         subprocess.Popen(cmd)
13     print 'USED'
14
15 if __name__ == '__main__':
16     uri = sys.argv[8]
17     u = urlparse.urlparse(uri)
18     if u.scheme == 'mailto':
19         detach_open(['xterm', '-e', 'mail %s' % u.path])
20     elif u.scheme == 'xmpp':
21         detach_open(['gajim-remote', 'open_chat', uri])
22     elif u.scheme == 'git':
23         detach_open(['git', 'clone', uri], cwd=os.path.expanduser('~/src'))