Source

rerun / rerun

Full commit
#!/usr/bin/env python

import sys, subprocess
import readline
from string import lowercase, uppercase

readline.parse_and_bind("tab: complete")
commands = {}

def _get_key():
    used = commands.keys()

    for c in lowercase + uppercase:
        if c not in used:
            return c

    return None


def run(key):
    try:
        subprocess.check_call(commands[key], shell=True, stdout=sys.stdout, stderr=sys.stderr)
    except subprocess.CalledProcessError:
        return False

    return True

def add(choice):
    parts = choice.split(' ', 1)

    if len(parts) > 1:
        cmd = parts[-1]
    else:
        cmd = raw_input('Enter command: ')

    if cmd not in commands.values():
        commands[_get_key()] = cmd

def delete(choice):
    parts = choice.split(' ', 1)

    if len(parts) > 1:
        key = parts[-1]
    else:
        key = raw_input('Which command? ')

    del commands[key]

def copy():
    # TODO
    pass

def halp():
    print "(/a)dd [command]"
    print "(/d)elete [key]"
    print "(/h)elp"
    print "(/q)uit"


def _print_list():
    print
    for cmd in sorted(commands.items()):
        print '[%s] %s' % cmd

def loop():
    _print_list()
    choice = raw_input('> ')

    if choice.startswith('/d'):
        delete(choice)
    elif choice.startswith('/a'):
        add(choice)
    elif choice.startswith('/c'):
        copy(choice)
    elif choice.startswith('/h'):
        halp()
    elif choice.startswith('/q'):
        return False
    elif not choice.strip():
        pass
    elif choice in commands.keys():
        run(choice)
    else:
        print 'Derp?'

    return True


if __name__ == '__main__':
    try:
        while loop():
            pass
    except EOFError:
        pass