Blog entries

  • Petit raccourci pratique avec ion3

    2008/05/27 by Arthur Lutz

    Un petit raccourci pratique pour ion3, qui permet, sur la combinaison de touches de son choix, de prendre le texte actuellement sélectionné (surligné) dans sa session X11, et, en fonction de son contenu :

    • d'ouvrir un onglet Firefox avec l'url sélectionnée,
    • d'ouvrir un xpdf si c'est une URL de fichier PDF,
    • lancer si c'est un fichier OOo,
    • ouvrir le fichier dans emacs si c'est un .py, .po, etc.
    • etc.

    Pour cela, il faut le script magique ci-dessous, et configurer ion pour appeler ce script sur la bonne combinaison de touches. Par ex. ajouter dans votre ~/.ion3/cfg_ion.lua les lignes

    defbindings("WMPlex.toplevel", {
      bdoc("Automagically view the selected string"),
             "ioncore.exec_on(_, '/home/user/bin/view')"),

    Ici, j'ai mappé "Meta+F7", et le script est /home/user/bin/view

    #!/usr/bin/env python
    from mimetypes import guess_type
    import sys
    from os.path import abspath
    from os import system, popen
    import re
    RGX = re.compile
    EMACS = 'emacsclient --no-wait %(uri)s'
    EMACS_WITH_LINE = 'emacsclient --no-wait +%(lineno)s %(uri)s'
    FIREFOX = 'firefox -remote "openURL(%(uri)s, new-tab)"'
    WGET = 'cd /home/adim/tmp && wget %(uri)s & '
    commands = [
        ('text/html', FIREFOX),
        ('application/xml', EMACS),
        ('text', EMACS),
        ('image', 'display %(uri)s &'),
        ('application/pdf', 'xpdf %(uri)s &'),
        ('application/postcript', 'gv %(uri)s &'),
        ('application/vnd.sun.xml', 'ooffice %(uri)s &'), # matches writer, impress, etc.
        ('application/vnd.oasis.opendocument', 'ooffice %(uri)s &'),
        ('application/msword', 'ooffice %(uri)s &'),
        ('application/', 'ooffice %(uri)s &'),
    patterns = [
        (RGX(r'https?://.*?(zip|gz|pdf|ods|doc|odt|ppt|sxw|sxi)$'), WGET),
        (RGX(r'.*(?P<uri>https?://[^ ()]*)( .*)?'), FIREFOX),
        (RGX('.*?\.conf$'), EMACS),
        (RGX('.*?\.po$'), EMACS),
        (RGX('.*?\.xslt$'), EMACS),
        (RGX('.*?\.pot$'), EMACS),
        (RGX(r'\s*F?i?l?e? ?"?(?P<uri>.*?\.py)", line (?P<lineno>\d+)[a-zA-Z_:-]*'), EMACS_WITH_LINE),
        (RGX('.*?(readme|changelog|depends|manifest|makefile)(\.in|\.gz|\.bz2)?$', re.I), EMACS),
        # others might come here ...
    def find_command(selection):
        for rgx, cmd in patterns:
            m = rgx.match(selection)
            if m:
                args = m.groupdict() or {'uri' : selection}
                return cmd, args
        mimetype, encoding = guess_type(selection)
        # XXX: encodings like zip, or gz could be handled
        if mimetype is not None:
            selection = abspath(selection)
            for registered_type, cmd in commands:
                if mimetype.startswith(registered_type):
                    return cmd, {'uri' : selection}
        raise ValueError('nothing matched')
    if len(sys.argv)>1:
        selected = ' '.join(sys.argv[1:])
        selected = popen('xclip -o').read()
    if selected:
            cmd, args = find_command(selected)
        except ValueError:
            # system('wmiijabber error viewing %s' % ' '.join(sys.argv[1:]))
            # XXX print a message in wmii status bar ?
            #print "yooo =>", repr(cmd), repr(args)
            system(cmd % args)

    Pour que cela fonctionne, il ne faut pas oublier d'installer xclip (sous debian, apt-get install xclip).

    -- écrit par David Douard sur un script de Adrien diMascio

  • ion, dock and screen configuration

    2008/07/04 by David Douard

    I have a laptop I use at work (with a docking station), in the train and at home (with an external display), on which my environment is ion3.

    As I use suspend-to-RAM all the time, I have added some keybindings to automatically reconfigure my screen when I plug/unplug an external display (on the dock as well as direct VGA connection).

    The lua code to paste in your .ion3/cfg_ion.lua for the bindings looks like:

    function autoscreen_on()
            local f = io.popen('/home/david/bin/autoscreen -c', 'r')
          if not f then
          local s = f:read('*a')
    function autoscreen_off()
            local f = io.popen('/home/david/bin/autoscreen -d', 'r')
          if not f then
          local s = f:read('*a')
    defbindings("WMPlex.toplevel", {
        bdoc("Turn on any external display and tell ion to reconfigure itself"),
    defbindings("WMPlex.toplevel", {
        bdoc("Turn off any external display and tell ion to reconfigure itself"),

    It makes use of the following python script (named /home/david/bin/autoscreen in the lua code above):

    #!/usr/bin/env python
    import sys
    import os
    import re
    from subprocess import Popen, PIPE
    import optparse
    parser = optparse.OptionParser("A simple automatic screen configurator (using xrandr)")
    parser.add_option('-c', '--connect', action="store_true",
                      help="configure every connected screens")
    parser.add_option('-d', '--disconnect', action="store_true",
                      help="unconfigure every connected screens other than LVDS (laptop screen)")
    parser.add_option('', '--main-display',
                      help="main display identifier (typically, the laptop LCD screen; defaults to LVDS)")
    options, args = parser.parse_args()
    if int(options.connect) + int(options.disconnect) > 1:
        print "ERROR: only one option -c or -d at a time"
    xrandr = Popen("xrandr", shell=True, bufsize=0, stdout=PIPE)
    connected = re.findall(r'([a-zA-Z0-9-]*) connected', xrandr)
    connected = [c for c in connected if c != options.maindisplay]
    cmd = "xrandr --output %s %s"
    if options.connect or options.disconnect:
        for c in connected:
            if options.connect:
                action = "--auto"
            elif options.disconnect:
                action = "--off"
            p = Popen(cmd % (c, action), shell=True)
            sts = os.waitpid(, 0)

  • simpled - Simple Desktop project started !

    2008/08/11 by Nicolas Chauvat

    I bought last week a new laptop computer that can drive a 24" LCD monitor, which means I do not need my desktop computer any more. In the process of setting up that new laptop, I did what I have been wanting to do for years without finding the time: spending time on my ion3 config to make it more generic and create a small python setup utility that can regenerate it from a template file and a keyboard layout.

    The simpled project was born!

    If you take a look at the list of pending tickets, you will guess that I am using a limited number of pieces of software during my work day and tried to configure them so that they share common action/shortcuts. This is what simpled is about: given a keyboard layout generate the config files for the common tools so that action/shortcuts are always on the same key.

    I use ion3, xterm+bash, emacs, mutt, firefox, gajim. Common actions are: open, save, close, move up/down/left/right, new frame or tab, close frame or tab, move to previous or next tab, etc.

    I will give news in this blog from time to time and announce it on mailing lists when version 0.1 will be out. If you want to give it a try, get the code from the mercurial repository.