diff options
| author | Mattias Andrée <maandree@operamail.com> | 2012-10-28 23:49:16 +0100 | 
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2012-10-28 23:49:16 +0100 | 
| commit | c58ebcb65c0ae5d7b5cf1627e8a458808f59b7ff (patch) | |
| tree | 0313e7f84b3053acddaf77f3a04e7c16e8fccd9c | |
| parent | bash generator implemented, except it does not know how to parse suggestion functions (diff) | |
| download | auto-auto-complete-c58ebcb65c0ae5d7b5cf1627e8a458808f59b7ff.tar.gz auto-auto-complete-c58ebcb65c0ae5d7b5cf1627e8a458808f59b7ff.tar.bz2 auto-auto-complete-c58ebcb65c0ae5d7b5cf1627e8a458808f59b7ff.tar.xz | |
I think bash completion works
| -rwxr-xr-x | auto-auto-complete.py | 53 | ||||
| -rw-r--r-- | example | 6 | 
2 files changed, 54 insertions, 5 deletions
| diff --git a/auto-auto-complete.py b/auto-auto-complete.py index c48f676..e4cfadc 100755 --- a/auto-auto-complete.py +++ b/auto-auto-complete.py @@ -241,6 +241,33 @@ class GeneratorBASH:              else:                  indenticals[_suggester][1].append(option) +        def verb(text): +            temp = text +            for char in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-+=/@:\'': +                temp = temp.replace(char, '') +            if len(temp) == 0: +                return text +            return '\'' + text.replace('\'', '\'\\\'\'') + '\'' +         +        def makeexec(functionType, function): +            if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or'): +                elems = [(' %s ' % makeexec(item[0], item[1:]) if isinstance(item, list) else verb(item)) for item in function] +                if functionType == 'exec': +                    return ' "$( %s )" ' % (' '.join(elems)) +                if functionType == 'pipe': +                    return ' ( %s ) ' % (' | '.join(elems)) +                if functionType == 'fullpipe': +                    return ' ( %s ) ' % (' |% '.join(elems)) +                if functionType == 'cat': +                    return ' ( %s ) ' % (' ; '.join(elems)) +                if functionType == 'and': +                    return ' ( %s ) ' % (' && '.join(elems)) +                if functionType == 'or': +                    return ' ( %s ) ' % (' || '.join(elems)) +            if functionType in ('params', 'verbatim'): +                return ' '.join([verb(item) for item in function]) +            return ' '.join([verb(functionType)] + [verb(item) for item in function]) +                  index = 0          for _suggester in indenticals:              (suggester, options) = indenticals[_suggester] @@ -248,8 +275,30 @@ class GeneratorBASH:              for option in options:                  conds.append('[ $prev = "%s" ]' % option)              buf += '    %s %s; then\n' % ('if' if index == 0 else 'elif', ' || '.join(conds)) -            buf += '        : suggestions=%s\n' % str(suggester) -            buf += '        : COMPREPLY=( $( compgen -W "$suggestions" -- "$cur" ) )\n' +            suggestion = ''; +            for function in suggester: +                functionType = function[0] +                function = function[1:] +                if functionType == 'verbatim': +                    suggestion += '" %s"' % (' '.join([verb(item) for item in function])) +                elif functionType == 'ls': +                    filter = '' +                    if len(function) > 1: +                        filter = ' | grep -v \\/%s\\$ | grep %s\\$' % (function[1], function[1]) +                    suggestion += '" $(ls -1 --color=no %s%s)"' % (function[0], filter) +                elif functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or'): +                    suggestion += ('" %s"' if functionType == 'exec' else '" $(%s)"') % makeexec(functionType, function) +                elif functionType == 'calc': +                    expression = [] +                    for item in function: +                        if isinstance(item, list): +                            expression.append(('%s' if item[0] == 'exec' else '$(%s)') % makeexec(item[0], item[1:])) +                        else: +                            expression.append(verb(item)) +                    suggestion += '" $(( %s ))"' % (' '.join(expression)) +            if len(suggestion) > 0: +                buf += '        suggestions=%s\n' % str(suggestion) +                buf += '        COMPREPLY=( $( compgen -W "$suggestions" -- "$cur" ) )\n'              index += 1          if index > 0: @@ -49,11 +49,11 @@  		    	    (no-exec ls "'/usr/share/ponysay/balloons'" (case (ponysay .say) (ponythink .think)))  	)  	(suggestion wrap    (verbatim none inhertit 100 60) -		    	    (calc (pipe (exec stty size) -			    	  	(exec cut -d ' ' -f 2) +		    	    (calc (pipe (stty size) +			    	  	(cut -d ' ' -f 2)  				  ) - 10  			    )  	) -	; in addition to `pipe` to following are also possible `fullpipe` `exec` `cat` `and` `or` +	; in addition to `pipe`(|) to following are also possible `fullpipe`(|&) `cat`(;) `and`(&&) `or`(||)  ) | 
