From 495b534afb1e0c7dbfb7780869a424c62d44fd7b Mon Sep 17 00:00:00 2001 From: mattirn Date: Sun, 15 Nov 2020 09:06:11 +0100 Subject: [PATCH] ConsoleEngineImpl: exclude pipe name aliases from command completion --- .../org/jline/console/impl/ConsoleEngineImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java b/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java index af0307051..69e56f109 100644 --- a/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java +++ b/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java @@ -23,6 +23,7 @@ import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.jline.builtins.Completers.FilesCompleter; import org.jline.builtins.Completers.OptDesc; @@ -186,10 +187,19 @@ public List scriptCompleters() { , this::commandOptions , 1) )); - out.add(new ArgumentCompleter(new StringsCompleter(aliases::keySet), NullCompleter.INSTANCE)); + out.add(new ArgumentCompleter(new StringsCompleter(this::commandAliasNames) + , NullCompleter.INSTANCE)); return out; } + private Set commandAliasNames() { + Set opers = pipes.keySet().stream().filter(p -> !p.matches("\\w+")).collect(Collectors.toSet()); + opers.addAll(systemRegistry.getPipeNames()); + return aliases.entrySet().stream() + .filter(e -> !opers.contains(e.getValue().split(" ")[0])) + .map(Map.Entry::getKey).collect(Collectors.toSet()); + } + private Set scriptNames() { return scripts().keySet(); }