Add a new shortcut

def action_add(self):
        """
        Add a new shortcut
        """

        # prepare values for new shortcut
        path = self.args['--workdir'] or os.getcwd()
        name = self.args['<name>']
        cmd = self.args['<command>']

        overwrite = self.args['--force']

        # check for conflicts in DB
        if not overwrite and self.shortcut_exists(name):
            print_err('The shortcut "%s" already exists.' % name)
            return

        # if cmd has arguments, extract the command only
        cmd_parts = [x.strip() for x in cmd.split(' ')]
        cmd_real = cmd_parts[0]
        cmd_tail = ' '.join(cmd_parts[1:])

        # if cmd_real starts with ./, remove that
        if cmd_real.startswith('./'):
            cmd_real = cmd_real[2:]

        # path to the file (if it's in the folder)
        localfile = os.path.abspath(os.path.join(path, cmd_real))

        # check if the file is present at the path given
        if os.path.isfile(localfile):

            # file extension
            ext = os.path.splitext(cmd_real)[1]

            # check for exacutable bit
            # jar is executable, but cannot be run directly
            if os.access(localfile, os.X_OK) and not ext == '.jar':
                # file is executable
                cmd = ''

                if not cmd_real.startswith('/'):
                    cmd = './'

                cmd = cmd + cmd_real + ' ' + cmd_tail

            else:
                # not executable
                # try to find interpreter for the file

                interpreter = {
                    '.py': 'python',
                    '.rb': 'ruby',
                    '.js': 'node',
                    '.pl': 'perl',
                    '.sh': 'sh',
                    '.php': 'php',
                    '.jar': 'java -jar',
                }.get(ext, None)

                # check if interpreter was found
                if interpreter is None:

                    msg = ('Could not make a shortcut to "%s":'
                           + '\n - not executable & unknown extension.') % localfile

                    print_err(msg)
                    return

                cmd = str(interpreter) + ' ' + \
                    str(cmd_real) + ' ' + str(cmd_tail)
        else:
            # use cmd, as given.
            pass

        if overwrite:
            self.db_exec('''
                    DELETE FROM shortcuts WHERE name=?
                    ''', (name,))
        # save to DB
        self.db_exec('''
            INSERT INTO shortcuts (name, path, command)
            VALUES (?, ?, ?)
            ''', (str(name), str(path), str(cmd)))

        # show OK message
        msg = ('Shortcut "%s" has been created.\n'
               + self.shortcut_str(path, cmd)) % name

        print_msg(msg)