diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-04 12:50:22 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-04 12:50:22 +0200 |
commit | b3bd23dd0a5f287bbdfe3ed5b7423a8134417cc4 (patch) | |
tree | 0f2021202825d2b6a2fefacce25ae2c60cb5e823 /src | |
parent | escape text in description for zsh (diff) | |
download | auto-auto-complete-b3bd23dd0a5f287bbdfe3ed5b7423a8134417cc4.tar.gz auto-auto-complete-b3bd23dd0a5f287bbdfe3ed5b7423a8134417cc4.tar.bz2 auto-auto-complete-b3bd23dd0a5f287bbdfe3ed5b7423a8134417cc4.tar.xz |
add file descriptor redirection7
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rwxr-xr-x | src/auto-auto-complete.py | 96 |
1 files changed, 93 insertions, 3 deletions
diff --git a/src/auto-auto-complete.py b/src/auto-auto-complete.py index da8d56f..f883b36 100755 --- a/src/auto-auto-complete.py +++ b/src/auto-auto-complete.py @@ -266,7 +266,7 @@ class GeneratorBASH: return '\'' + text.replace('\'', '\'\\\'\'') + '\'' def makeexec(functionType, function): - if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or'): + if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or', 'stdin', 'stdout', 'stderr', 'stdin-fd', 'stdout-fd', 'stderr-fd', 'fd', 'fd-fd'): 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)) @@ -280,6 +280,36 @@ class GeneratorBASH: return ' ( %s ) ' % (' && '.join(elems)) if functionType == 'or': return ' ( %s ) ' % (' || '.join(elems)) + if functionType == 'stdin': + if len(elems) == 0: + return 0 + [command, redirection] = elems + return ' %s < %s ' % (command, redirection) + if functionType == 'stdout': + if len(elems) == 0: + return 1 + [command, redirection] = elems + return ' %s > %s ' % (command, redirection) + if functionType == 'stderr': + if len(elems) == 0: + return 2 + [command, redirection] = elems + return ' %s 2> %s ' % (command, redirection) + if functionType == 'stdin-fd': + [command, redirection] = elems + return ' %s <&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stdout-fd': + [command, redirection] = elems + return ' %s >&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stderr-fd': + [command, redirection] = elems + return ' %s 2>&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'fd': + [command, fd, redirection] = elems + return ' %s %s<> %s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection) + if functionType == 'fd-fd': + [command, fd, redirection] = elems + return ' %s %s<>&%s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection.replace('\'', '').replace(' ', '')) if functionType in ('params', 'verbatim'): return ' '.join([verb(item) for item in function]) return ' '.join([verb(functionType)] + [verb(item) for item in function]) @@ -462,7 +492,7 @@ class GeneratorFISH: return '\'' + text.replace('\'', '\'\\\'\'') + '\'' def makeexec(functionType, function): - if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or'): + if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or', 'stdin', 'stdout', 'stderr', 'stdin-fd', 'stdout-fd', 'stderr-fd', 'fd', 'fd-fd'): 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)) @@ -476,6 +506,36 @@ class GeneratorFISH: return ' ( %s ) ' % (' && '.join(elems)) if functionType == 'or': return ' ( %s ) ' % (' || '.join(elems)) + if functionType == 'stdin': + if len(elems) == 0: + return 0 + [command, redirection] = elems + return ' %s < %s ' % (command, redirection) + if functionType == 'stdout': + if len(elems) == 0: + return 1 + [command, redirection] = elems + return ' %s > %s ' % (command, redirection) + if functionType == 'stderr': + if len(elems) == 0: + return 2 + [command, redirection] = elems + return ' %s 2> %s ' % (command, redirection) + if functionType == 'stdin-fd': + [command, redirection] = elems + return ' %s <&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stdout-fd': + [command, redirection] = elems + return ' %s >&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stderr-fd': + [command, redirection] = elems + return ' %s 2>&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'fd': + [command, fd, redirection] = elems + return ' %s %s<> %s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection) + if functionType == 'fd-fd': + [command, fd, redirection] = elems + return ' %s %s<>&%s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection.replace('\'', '').replace(' ', '')) if functionType in ('params', 'verbatim'): return ' '.join([verb(item) for item in function]) return ' '.join([verb(functionType)] + [verb(item) for item in function]) @@ -656,7 +716,7 @@ class GeneratorZSH: return '\'' + text.replace('\'', '\'\\\'\'') + '\'' def makeexec(functionType, function): - if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or'): + if functionType in ('exec', 'pipe', 'fullpipe', 'cat', 'and', 'or', 'stdin', 'stdout', 'stderr', 'stdin-fd', 'stdout-fd', 'stderr-fd', 'fd', 'fd-fd'): 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)) @@ -670,6 +730,36 @@ class GeneratorZSH: return ' ( %s ) ' % (' && '.join(elems)) if functionType == 'or': return ' ( %s ) ' % (' || '.join(elems)) + if functionType == 'stdin': + if len(elems) == 0: + return 0 + [command, redirection] = elems + return ' %s < %s ' % (command, redirection) + if functionType == 'stdout': + if len(elems) == 0: + return 1 + [command, redirection] = elems + return ' %s > %s ' % (command, redirection) + if functionType == 'stderr': + if len(elems) == 0: + return 2 + [command, redirection] = elems + return ' %s 2> %s ' % (command, redirection) + if functionType == 'stdin-fd': + [command, redirection] = elems + return ' %s <&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stdout-fd': + [command, redirection] = elems + return ' %s >&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'stderr-fd': + [command, redirection] = elems + return ' %s 2>&%s ' % (command, redirection.replace('\'', '').replace(' ', '')) + if functionType == 'fd': + [command, fd, redirection] = elems + return ' %s %s<> %s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection) + if functionType == 'fd-fd': + [command, fd, redirection] = elems + return ' %s %s<>&%s ' % (command, fd.replace('\'', '').replace(' ', ''), redirection.replace('\'', '').replace(' ', '')) if functionType in ('params', 'verbatim'): return ' '.join([verb(item) for item in function]) return ' '.join([verb(functionType)] + [verb(item) for item in function]) |