Ejemplo n.º 1
0
def add_service_actions(wf, service_name):
    wf.add_item(
        'Run Service',
        'Run the service formula without registering to launch at login (or boot).',
        autocomplete='services %s run' % service_name,
        arg='brew services run %s' % service_name,
        valid=True,
        icon=helpers.get_icon(wf, 'chevron-right'))
    wf.add_item(
        'Stop Service',
        'Stop the service formula immediately and unregister it from launching at login (or boot).',
        autocomplete='services %s stop' % service_name,
        arg='brew services stop %s' % service_name,
        valid=True,
        icon=helpers.get_icon(wf, 'chevron-right'))
    wf.add_item(
        'Start Service',
        'Start the service formula immediately and register it to launch at login (or boot).',
        autocomplete='services %s start' % service_name,
        arg='brew services start %s' % service_name,
        valid=True,
        icon=helpers.get_icon(wf, 'chevron-right'))
    wf.add_item(
        'Restart Service',
        'Stop (if necessary) and start the service formula immediately and register it to launch '
        'at login (or boot).',
        autocomplete='services %s restart' % service_name,
        arg='brew services restart %s' % service_name,
        valid=True,
        icon=helpers.get_icon(wf, 'chevron-right'))
Ejemplo n.º 2
0
def main(wf):
    # The Workflow instance will be passed to the function
    # you call from `Workflow.run`

    # Your imports here if you want to catch import errors
    # import somemodule
    # import anothermodule

    # Get args from Workflow as normalized Unicode
    args = wf.args

    # Set `query` if a value was passed (it may be an empty string)
    if len(wf.args):
        query = wf.args[0]

    with open(CONFIG) as json_data:
        json_list = json.load(json_data)

    items = json_list  # Load data from blah

    if query:  # Only call `filter()` if there's a `query`
        items = wf.filter(query, json_list, keys_for_search)

    # Show error if there are no results. Otherwise, Alfred will show
    # its fallback searches (i.e. "Search Google for 'XYZ'")
    if not items:
        wf.add_item(title='Command not found!',
                    icon=helpers.get_icon(wf, 'info'))

    # Generate list of results. If `items` is an empty list,
    # nothing will happen

    for item in items:
        summary = u'' + item['comment']
        full_text = u'' + item['cmd'] + ' ' + item['comment']

        wf.add_item(
            title=item['cmd'],
            subtitle=summary,
            # modifier_subtitles={
            #     u'shift': item['cmd'],
            #     # u'fn': u'Subtext when fn is pressed',
            #     u'ctrl': item['cmd'],
            #     u'alt': item['cmd'],
            #     u'cmd': item['cmd']
            # },
            autocomplete=item['cmd'],
            arg=item['cmd'],
            copytext=item['cmd'],
            valid=True,
            icon=helpers.get_icon(wf, 'bash'))


# Send output to Alfred
    wf.send_feedback()
Ejemplo n.º 3
0
def main(wf):
    if wf.update_available:
        wf.add_item('An update is available!',
                    autocomplete='workflow:update',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    if len(wf.cached_data('brew_outdated_formulae',
                          get_outdated_formulae,
                          max_age=3600)) > 0:
        wf.add_item('Some of your formulae are outdated!',
                    autocomplete='outdated ',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    if not brew_installed():
        wf.add_item('Brew does not seem to be installed!',
                    'Hit enter to see what you need to do...',
                    arg='open http://brew.sh/#install && exit',
                    valid=True)
        wf.add_item('I trust this workflow',
                    'Hit enter to install brew...',
                    arg='ruby -e "$(curl -fsSL %s)"' % BREW_INSTALL_URL,
                    valid=True)
    else:
        # extract query
        query = wf.args[0] if len(wf.args) else None

        if query and query.startswith('install'):
            for formula in filter_all_formulae(wf, query):
                wf.add_item(formula, 'Install formula.',
                            arg='brew install %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('search'):
            for formula in filter_all_formulae(wf, query):
                wf.add_item(formula, 'Open formula on GitHub.',
                            arg=get_open_link_command(formula),
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('uninstall'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Uninstall formula.',
                            arg='brew uninstall %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('list'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Open formula on GitHub.',
                            arg=get_open_link_command(name),
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('pin'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Pin formula.',
                            arg='brew pin %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
                # delete cached file
                wf.cache_data('brew_pinned_formulae', None)
        elif query and query.startswith('unpin'):
            for formula in filter_pinned_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Unpin formula.',
                            arg='brew unpin %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
                # delete cached file
                wf.cache_data('brew_pinned_formulae', None)
        elif query and query.startswith('cat'):
            for formula in filter_all_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Display the source to this formula.',
                            arg='brew cat %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('outdated'):
            for formula in filter_outdated_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula, 'Update formula.',
                            arg='upgrade %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('info'):
            wf.add_item(get_info(),
                        autocomplete='',
                        icon=helpers.get_icon(wf, 'info'))
        elif query and query.startswith('commands'):
            for command in get_commands(wf, query):
                wf.add_item(command, 'Run this command.',
                            arg='brew %s' % command,
                            valid=True,
                            icon=helpers.get_icon(wf, 'chevron-right'))
        else:
            actions = brew_actions.ACTIONS
            if len(wf.cached_data('brew_pinned_formulae',
                                  get_pinned_formulae,
                                  max_age=3600)) > 0:
                actions.append({
                    'name': 'Unpin',
                    'description': 'Unpin formula.',
                    'autocomplete': 'unpin ',
                    'arg': '',
                    'valid': False,
                })
            # filter actions by query
            if query:
                actions = wf.filter(query, actions,
                                    key=helpers.search_key_for_action,
                                    match_on=MATCH_SUBSTRING)

            if len(actions) > 0:
                for action in actions:
                    wf.add_item(action['name'], action['description'],
                                uid=action['name'],
                                autocomplete=action['autocomplete'],
                                arg=action['arg'],
                                valid=action['valid'],
                                icon=helpers.get_icon(wf, 'chevron-right'))
            else:
                wf.add_item('No action found for "%s"' % query,
                            autocomplete='',
                            icon=helpers.get_icon(wf, 'info'))

        if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

    wf.send_feedback()

    # refresh cache
    cmd = ['/usr/bin/python', wf.workflowfile('brew_refresh.py')]
    run_in_background('brew_refresh', cmd)
Ejemplo n.º 4
0
def main(wf):
    if wf.update_available:
        wf.add_item('An update is available!',
                    autocomplete='workflow:update',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    def _cask_installed():
        return cask_installed(wf)

    def _cask_configured():
        return cask_configured(wf)

    if not wf.cached_data('cask_installed', _cask_installed, max_age=0):
        wf.add_item('Cask does not seem to be installed!',
                    'Hit enter to see what you need to do...',
                    arg='open http://caskroom.io/ && exit',
                    valid=True,
                    icon='cask.png')
        wf.add_item('I trust this workflow',
                    'Hit enter to run `brew tap caskroom/cask` to get cask...',
                    arg='brew tap caskroom/cask',
                    valid=True,
                    icon='cask.png')
        # delete cached file
        wf.cache_data('cask_installed', None)
    elif not wf.cached_data('cask_configured', _cask_configured, max_age=0):
        wf.add_item('Cask does not seem to be properly configured!',
                    'Hit enter to see what you need to do...',
                    arg=OPEN_HELP,
                    valid=True,
                    icon='cask.png')

        config = next(a for a in cask_actions.ACTIONS if a.name == 'config')
        wf.add_item(config['name'],
                    config['description'],
                    uid=config['name'],
                    autocomplete=config['autocomplete'],
                    arg=config['arg'],
                    valid=config['valid'],
                    icon=helpers.get_icon(wf, 'chevron-right'))

        query = wf.args[0] if len(wf.args) else None
        if query and query.startswith('config'):
            edit_settings(wf)
        # delete cached file
        wf.cache_data('cask_configured', None)
    else:
        # extract query
        query = wf.args[0] if len(wf.args) else None

        if (not query and len(
                wf.cached_data('cask_outdated_casks',
                               get_outdated_casks,
                               max_age=3600)) > 0):
            wf.add_item('Some of your casks are outdated!',
                        autocomplete='outdated ',
                        valid=False,
                        icon=helpers.get_icon(wf, 'cloud-download'))

        if query and query.startswith('install'):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula,
                            'Install cask',
                            arg='brew cask install %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and any(query.startswith(x) for x in ['search', 'home']):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula,
                            'Open homepage',
                            arg='brew cask home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('uninstall'):
            for formula in filter_installed_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula,
                            'Uninstall cask',
                            arg='brew cask uninstall %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('list'):
            for formula in filter_installed_casks(wf, query):
                wf.add_item(formula,
                            'Open homepage',
                            arg='brew cask home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('outdated'):
            for formula in filter_outdated_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula,
                            'Upgrade cask',
                            arg='brew cask upgrade %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('config'):
            edit_settings(wf)
            wf.add_item('`settings.json` has been opened.',
                        autocomplete='',
                        icon=helpers.get_icon(wf, 'info'))
        else:
            actions = cask_actions.ACTIONS
            # filter actions by query
            if query:
                actions = wf.filter(query,
                                    actions,
                                    key=helpers.search_key_for_action,
                                    match_on=MATCH_SUBSTRING)

            if len(actions) > 0:
                for action in actions:
                    wf.add_item(action['name'],
                                action['description'],
                                uid=action['name'],
                                autocomplete=action['autocomplete'],
                                arg=action['arg'],
                                valid=action['valid'],
                                icon=helpers.get_icon(wf, 'chevron-right'))
            else:
                wf.add_item('No action found for "%s"' % query,
                            autocomplete='',
                            icon=helpers.get_icon(wf, 'info'))

        if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

    wf.send_feedback()

    # refresh cache
    cmd = ['/usr/bin/python', wf.workflowfile('cask_refresh.py')]
    run_in_background('cask_refresh', cmd)
Ejemplo n.º 5
0
def main(wf):
    if wf.update_available:
        wf.add_item('An update is available!',
                    autocomplete='workflow:update',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    if not helpers.brew_installed():
        helpers.brew_installation_instructions(wf)
    else:
        # extract query
        query = wf.args[0] if len(wf.args) else None

        if (not query and len(
                wf.cached_data('brew_outdated_formulae',
                               get_outdated_formulae,
                               max_age=3600)) > 0):
            wf.add_item('Some of your formulae are outdated!',
                        autocomplete='outdated ',
                        valid=False,
                        icon=helpers.get_icon(wf, 'cloud-download'))

        if query and query.startswith('install'):
            for formula in filter_all_formulae(wf, query):
                wf.add_item(formula,
                            'Install formula.',
                            arg='brew install %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('search'):
            for formula in filter_all_formulae(wf, query):
                wf.add_item(formula,
                            'Open formula on GitHub.',
                            arg='brew info --github %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('uninstall'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Uninstall formula.',
                            arg='brew uninstall %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('list'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Open formula on GitHub.',
                            arg='brew info --github %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('pin'):
            for formula in filter_installed_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Pin formula.',
                            arg='brew pin %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
                # delete cached file
                wf.cache_data('brew_pinned_formulae', None)
        elif query and query.startswith('unpin'):
            for formula in filter_pinned_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Unpin formula.',
                            arg='brew unpin %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
                # delete cached file
                wf.cache_data('brew_pinned_formulae', None)
        elif query and query.startswith('cat'):
            for formula in filter_all_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Display the source to this formula.',
                            arg='brew cat %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('outdated'):
            for formula in filter_outdated_formulae(wf, query):
                name = formula.rsplit()[0]
                wf.add_item(formula,
                            'Upgrade formula.',
                            arg='brew upgrade %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('info'):
            wf.add_item(get_info(),
                        autocomplete='',
                        icon=helpers.get_icon(wf, 'info'))
        elif query and query.startswith('commands'):
            for command in get_commands(wf, query):
                wf.add_item(command,
                            'Run this command.',
                            arg='brew %s' % command,
                            valid=True,
                            icon=helpers.get_icon(wf, 'chevron-right'))
        else:
            actions = brew_actions.ACTIONS
            if len(
                    wf.cached_data('brew_pinned_formulae',
                                   get_pinned_formulae,
                                   max_age=3600)) > 0:
                actions.append({
                    'name': 'Unpin',
                    'description': 'Unpin formula.',
                    'autocomplete': 'unpin ',
                    'arg': '',
                    'valid': False,
                })
            # filter actions by query
            if query:
                actions = wf.filter(query,
                                    actions,
                                    key=helpers.search_key_for_action,
                                    match_on=MATCH_SUBSTRING)

            if len(actions) > 0:
                for action in actions:
                    wf.add_item(action['name'],
                                action['description'],
                                uid=action['name'],
                                autocomplete=action['autocomplete'],
                                arg=action['arg'],
                                valid=action['valid'],
                                icon=helpers.get_icon(wf, 'chevron-right'))
            else:
                wf.add_item('No action found for "%s"' % query,
                            autocomplete='',
                            icon=helpers.get_icon(wf, 'info'))

        if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

    wf.send_feedback()

    # refresh cache
    cmd = ['/usr/bin/python', wf.workflowfile('brew_refresh.py')]
    run_in_background('brew_refresh', cmd)
Ejemplo n.º 6
0
def main(wf):
    if wf.update_available:
        wf.add_item('An update is available!',
                    autocomplete='workflow:update',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    def _cask_installed():
        return cask_installed(wf)

    def _cask_configured():
        return cask_configured(wf)

    if not wf.cached_data('cask_installed', _cask_installed, max_age=0):
        wf.add_item('Cask does not seem to be installed!',
                    'Hit enter to see what you need to do...',
                    arg='open http://caskroom.io/ && exit',
                    valid=True,
                    icon='cask.png')
        wf.add_item('I trust this workflow',
                    'Hit enter to run `brew tap caskroom/cask` to get cask...',
                    arg='brew tap caskroom/cask',
                    valid=True,
                    icon='cask.png')
        # delete cached file
        wf.cache_data('cask_installed', None)
    elif not wf.cached_data('cask_configured', _cask_configured, max_age=0):
        wf.add_item('Cask does not seem to be properly configured!',
                    'Hit enter to see what you need to do...',
                    arg=OPEN_HELP,
                    valid=True,
                    icon='cask.png')

        config = next(a for a in cask_actions.ACTIONS if a.name == 'config')
        wf.add_item(config['name'], config['description'],
                    uid=config['name'],
                    autocomplete=config['autocomplete'],
                    arg=config['arg'],
                    valid=config['valid'],
                    icon=helpers.get_icon(wf, 'chevron-right'))

        query = wf.args[0] if len(wf.args) else None
        if query and query.startswith('config'):
            edit_settings(wf)
        # delete cached file
        wf.cache_data('cask_configured', None)
    else:
        # extract query
        query = wf.args[0] if len(wf.args) else None

        if (not query and
                len(wf.cached_data('cask_outdated_casks',
                                   get_outdated_casks,
                                   max_age=3600)) > 0):
            wf.add_item('Some of your casks are outdated!',
                        autocomplete='outdated ',
                        valid=False,
                        icon=helpers.get_icon(wf, 'cloud-download'))

        if query and query.startswith('install'):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula, 'Install cask',
                            arg='brew cask install %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and any(query.startswith(x) for x in ['search', 'home']):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula, 'Open homepage',
                            arg='brew cask home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('uninstall'):
            for formula in filter_installed_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula, 'Uninstall cask',
                            arg='brew cask uninstall %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('list'):
            for formula in filter_installed_casks(wf, query):
                wf.add_item(formula, 'Open homepage',
                            arg='brew cask home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('outdated'):
            for formula in filter_outdated_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula, 'Upgrade cask',
                            arg='brew cask upgrade %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('config'):
            edit_settings(wf)
            wf.add_item('`settings.json` has been opened.',
                        autocomplete='',
                        icon=helpers.get_icon(wf, 'info'))
        else:
            actions = cask_actions.ACTIONS
            # filter actions by query
            if query:
                actions = wf.filter(query, actions,
                                    key=helpers.search_key_for_action,
                                    match_on=MATCH_SUBSTRING)

            if len(actions) > 0:
                for action in actions:
                    wf.add_item(action['name'], action['description'],
                                uid=action['name'],
                                autocomplete=action['autocomplete'],
                                arg=action['arg'],
                                valid=action['valid'],
                                icon=helpers.get_icon(wf, 'chevron-right'))
            else:
                wf.add_item('No action found for "%s"' % query,
                            autocomplete='',
                            icon=helpers.get_icon(wf, 'info'))

        if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

    wf.send_feedback()

    # refresh cache
    cmd = ['/usr/bin/python', wf.workflowfile('cask_refresh.py')]
    run_in_background('cask_refresh', cmd)
Ejemplo n.º 7
0
def main(wf):
    if wf.update_available:
        wf.add_item('An update is available!',
                    autocomplete='workflow:update',
                    valid=False,
                    icon=helpers.get_icon(wf, 'cloud-download'))

    if not helpers.brew_installed():
        helpers.brew_installation_instructions(wf)
    else:
        # extract query
        query = wf.args[0] if len(wf.args) else None

        if (not query and
                len(wf.cached_data('cask_outdated_casks',
                                   get_outdated_casks,
                                   max_age=3600)) > 0):
            wf.add_item('Some of your casks are outdated!',
                        autocomplete='outdated ',
                        valid=False,
                        icon=helpers.get_icon(wf, 'cloud-download'))

        if query and query.startswith('install'):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula, 'Install cask',
                            arg='brew cask install %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and any(query.startswith(x) for x in ['search', 'home']):
            for formula in filter_all_casks(wf, query):
                wf.add_item(formula, 'Open homepage',
                            arg='brew home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('uninstall'):
            for formula in filter_installed_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula, 'Uninstall cask',
                            arg='brew cask uninstall %s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('list'):
            for formula in filter_installed_casks(wf, query):
                wf.add_item(formula, 'Open homepage',
                            arg='brew home %s' % formula,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('outdated'):
            for formula in filter_outdated_casks(wf, query):
                name = formula.split(' ')[0]
                wf.add_item(formula, 'Upgrade cask',
                            arg='brew upgrade homebrew/cask/%s' % name,
                            valid=True,
                            icon=helpers.get_icon(wf, 'package'))
        elif query and query.startswith('config'):
            edit_settings(wf)
            wf.add_item('`settings.json` has been opened.',
                        autocomplete='',
                        icon=helpers.get_icon(wf, 'info'))
        else:
            actions = cask_actions.ACTIONS
            # filter actions by query
            if query:
                actions = wf.filter(query, actions,
                                    key=helpers.search_key_for_action,
                                    match_on=MATCH_SUBSTRING)

            if len(actions) > 0:
                for action in actions:
                    wf.add_item(action['name'], action['description'],
                                uid=action['name'],
                                autocomplete=action['autocomplete'],
                                arg=action['arg'],
                                valid=action['valid'],
                                icon=helpers.get_icon(wf, 'chevron-right'))
            else:
                wf.add_item('No action found for "%s"' % query,
                            autocomplete='',
                            icon=helpers.get_icon(wf, 'info'))

        if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

    wf.send_feedback()

    # refresh cache
    cmd = ['/usr/bin/python', wf.workflowfile('cask_refresh.py')]
    run_in_background('cask_refresh', cmd)
Ejemplo n.º 8
0
def main(wf):
  import zebra_actions

  query = wf.args[0] if len(wf.args) else None

  if not(config):
    wf.add_item('Configuration missing or incomplete',
                'Please check your configuration file',
                valid=False)
  else:
    if wf.update_available:
      wf.add_item('An update is available!',
                  autocomplete='workflow:update',
                  valid=False,
                  icon=helpers.get_icon(wf, 'cloud-download'))

    if query and query.startswith('project'):
      for project in filter_all_projects(wf, query):
        title = u'{} ({})'.format(project['name'], project['id'])
        autocomplete = u'project {}'.format(project['name'])
        url = config['web_url'] + 'project/' + project['id']
        arg = 'open "{}"'.format(url)
        wf.add_item(title, project['description'],
                    uid=project['id'],
                    arg=arg,
                    valid=True,
                    icon=helpers.get_icon(wf, 'project'))
    elif query and query.startswith('alias'):
      for activity in filter_aliased_activities(wf, query):
        title = u'{} [{}]'.format(activity['name'], activity['alias'])
        description = u'Project: {}'.format(activity['project']['name'])
        arg = 'echo -n "{}" | pbcopy'.format(activity['alias'])
        wf.add_item(title, description,
                    uid=activity['alias'],
                    arg=arg,
                    valid=True,
                    icon=helpers.get_icon(wf, 'activity'))
    else:
      actions = zebra_actions.ACTIONS

      if query:
        actions = wf.filter(query, actions,
                            key=helpers.search_key_for_action,
                            match_on=MATCH_SUBSTRING)

      if len(actions) > 0:
        for action in actions:
          wf.add_item(action['name'], action['description'],
                      uid=action['name'],
                      autocomplete=action['autocomplete'],
                      arg=action['arg'],
                      valid=action['valid'],
                      icon=helpers.get_icon(wf, 'chevron-right'))

    if len(wf._items) == 0:
            query_name = query[query.find(' ') + 1:]
            wf.add_item('No formula found for "%s"' % query_name,
                        autocomplete='%s ' % query[:query.find(' ')],
                        icon=helpers.get_icon(wf, 'info'))

  wf.send_feedback()

  cmd = ['/usr/bin/python', wf.workflowfile('zebra_refresh.py')]
  run_in_background('zebra_refresh', cmd)