Exemplo n.º 1
0
    def smash_matcher(self, shell, event):
        completion_log.info('completing event: {0}'.format(event.__dict__))
        line = event.line

        if not line.strip():
            raise TryNext()
        first_word = line.split()[0]
        # NB: cannot use event.symbol here, it splits on '$'
        last_word = event.text_until_cursor.split()
        last_word = last_word[-1] if last_word else ''
        completion_log.info("first-word, last-word: {0}".format(
            [first_word, last_word]))
        if last_word.startswith('$'):
            return smash_env_complete(last_word)
        magic_command_alias = first_word.startswith('%') and \
            have_command_alias(first_word[1:])
        naked_command_alias = have_command_alias(first_word)
        results = []
        if naked_command_alias:
            completion_log.info('naked command alias detected')
            results += smash_bash_complete(line)[:self.MAX_MATCH]
        elif magic_command_alias:
            completion_log.info('magic command alias detected')
            results += smash_bash_complete(line[1:])[:self.MAX_MATCH]

        # can't do anything smarter? look for file matches.
        # this works by default if the last word contains os.path.sep,
        # but this doesn't necessarily work with the special "ed" alias
        # unless this sectiion is executed
        if not results:
            completion_log.info(('no results for completion, looking for '
                                 'file matches with "{0}"'.format(last_word)))
            results = self.smash.shell.Completer.file_matches(last_word)

        if results:
            completion_log.info("returning: {0}".format(results))
            return results
        else:
            completion_log.info("no results so far, raising trynext ")
            raise TryNext()
Exemplo n.º 2
0
""" smashlib.plugins.env_command
"""
import os
from smashlib import get_smash
from smashlib.plugins import Plugin
from smashlib.patches.base import PatchMagic
from smashlib.completion import smash_env_complete

env_completer = lambda himself, event: smash_env_complete(event.symbol)
env_regex = r'env [A-Za-z0-9_]+$'

class PatchEnv(PatchMagic):
    """
        Patches builtin "env" command to add support for wildcard queries.

        Example:

            smash$ env XTERM*


            { 'XTERM_LOCALE': 'en_US.UTF-8',
              'XTERM_SHELL': '/bin/bash',
              'XTERM_VERSION': 'XTerm(297)' }

    """

    name = 'env'

    def __call__(self, parameter_s=''):
        split = '=' if '=' in parameter_s else ' '
        bits = parameter_s.split(split)