From 041d3b774e32e3b28d9b0564359e6876578a9c05 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Wed, 21 Jun 2017 16:03:51 +0200 Subject: [PATCH] nux-runner: Improved REPL command support. Signed-off-by: Tony Tkacik --- inc/nux-runner.inc.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/inc/nux-runner.inc.sh b/inc/nux-runner.inc.sh index 758d15d..169a3c3 100644 --- a/inc/nux-runner.inc.sh +++ b/inc/nux-runner.inc.sh @@ -79,6 +79,15 @@ nuxr.repl.process() { fi } +nuxr.repl.expose() { + # FIXME: Figure different way of exposing direct functions without wrapping + for cmd in "$@"; do + eval """function repl.command.$cmd { + $cmd "\$@" + } + """ + done +} ## ## repl.command.:: ## fallback command which does nothing if user just presses enter. @@ -112,6 +121,13 @@ nuxr.tasks.runtime.search() { | cut -d"(" -f1 } +nuxr.repl.commands.search() { + set | grep -E "^((repl\\.command)|(task))\\.$1.* ()" \ + | sed -re 's/^((repl\.command)|(task))\.//gi' \ + | cut -d"(" -f1 | sort | uniq + +} + nuxr.repl.completer.help() { nux.log debug "Help completer" nux.log debug "current_pos $current_pos" @@ -148,7 +164,7 @@ nuxr.repl.completer() { fi local result=""; if [ $current_pos -le 1 ] ; then - result=$(nuxr.tasks.runtime.search $current_word | grep -v "help\\.") + result=$(nuxr.repl.commands.search $current_word | grep -v "help\\.") elif [ $current_pos -ge 2 ]; then command=${words[0]} nux.log debug "Trying to use completer for '$command'"