From b3bd23dd0a5f287bbdfe3ed5b7423a8134417cc4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 4 Apr 2015 12:50:22 +0200 Subject: add file descriptor redirection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/auto-auto-complete.py | 96 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) (limited to 'src') 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]) -- cgit v1.2.3-70-g09d2