Skip to content

Commit

Permalink
Groovy REPL: highlight shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Nov 19, 2021
1 parent 35379cf commit 4010953
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion demo/src/main/java/org/jline/demo/Repl.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ public static void main(String[] args) {
systemRegistry.addCompleter(scriptEngine.getScriptCompleter());
systemRegistry.setScriptDescription(scriptEngine::scriptDescription);
//
// LineReader
// Command line highlighter
//
Path jnanorc = configPath.getConfig("jnanorc");
SyntaxHighlighter commandHighlighter = SyntaxHighlighter.build(jnanorc,"COMMAND");
SyntaxHighlighter argsHighlighter = SyntaxHighlighter.build(jnanorc,"ARGS");
SyntaxHighlighter groovyHighlighter = SyntaxHighlighter.build(jnanorc,"Groovy");
SystemHighlighter highlighter = new SystemHighlighter(commandHighlighter, argsHighlighter, groovyHighlighter);
if (!OSUtils.IS_WINDOWS) {
highlighter.setSpecificHighlighter("!", Nano.SyntaxHighlighter.build(jnanorc, "SH-REPL"));
}
highlighter.addFileHighlight("nano", "less", "slurp");
highlighter.addFileHighlight("groovy", "classloader", Arrays.asList("-a", "--add"));
//
// LineReader
//
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.completer(systemRegistry.completer())
Expand Down
19 changes: 19 additions & 0 deletions demo/src/main/scripts/sh-repl.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Groovy REPL sh commands highlight.
##
syntax "SH-REPL"

## keywords:
color green "\<(case|do|done|elif|else|esac|fi|for|function|if|in|select|then|time|until|while)\>"
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
color green "-[Lldefgrtuwx]+\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
## builtins:
color brightblue "\<(alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|compopt|continue|declare|dirs|disown|echo|enable|eval|exec|exit|export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|local|logout|mapfile|popd|printf|pushd|pwd|read|readarray|readonly|return|set|shift|shopt|source|suspend|test|times|trap|true|type|typeset|ulimit|umask|unalias|unset|wait)\>"
## not buitins:
color brightblue "\<(cat|chmod|chown|cp|env|grep|install|ln|make|mkdir|mv|rm|sed|tar|touch|ls)\>"
icolor brightgreen "^\s+[0-9A-Z_]+\s+\(\)"
icolor brightred "\$\{?[0-9A-Z_!@#$*?-]+\}?"
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
color cyan "^([[:space:]])*#.*$"
color cyan start="/\*" end="\*/"
# color ,green "[[:space:]]+$"

0 comments on commit 4010953

Please sign in to comment.