File: scheme.py

package info (click to toggle)
uzbl 0.0.0~git.20100403-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 760 kB
  • ctags: 783
  • sloc: ansic: 3,952; python: 3,082; sh: 353; makefile: 127
file content (24 lines) | stat: -rwxr-xr-x 843 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python

import os, subprocess, sys, urlparse

def detach_open(cmd):
    # 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)
    print 'USED'

if __name__ == '__main__':
    uri = sys.argv[8]
    u = urlparse.urlparse(uri)
    if u.scheme == 'mailto':
        detach_open(['xterm', '-e', 'mail', 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], cwd=os.path.expanduser('~/src'))