aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xauto-auto-complete.py53
-rw-r--r--example6
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:
diff --git a/example b/example
index b825641..79151ec 100644
--- a/example
+++ b/example
@@ -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`(||)
)