Package org.jline.shell.impl
Class DefaultLineExpander
java.lang.Object
org.jline.shell.impl.DefaultLineExpander
- All Implemented Interfaces:
LineExpander
Default implementation of
LineExpander that provides sane defaults
for variable expansion.
Supported expansions:
$VARand${VAR}— variable expansion from session variables, thenSystem.getenv()~at word start — expands touser.homesystem property- Single-quoted regions (
'...') are not expanded - Double-quoted regions (
"...") expand variables
Advanced braced forms:
${VAR:-default}— use default if VAR is unset or empty${VAR:=default}— assign default if VAR is unset or empty${VAR:+alt}— use alt if VAR is set and non-empty${VAR:?error}— error if VAR is unset or empty
Deliberately not included (subclass for these):
${VAR//pattern/replacement}— pattern substitution- Glob expansion (
*,?)
Subclasses can override resolve(String, CommandSession) to customize
how variable names are resolved.
- Since:
- 4.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexpand(String line, CommandSession session) Expands variables and expressions in the given command line.protected StringexpandBracedExpression(String expr, CommandSession session) Expands a braced expression such asVAR,VAR:-default,VAR:=default,VAR:+alt, orVAR:?error.protected Stringresolve(String name, CommandSession session) Resolves a variable name to its value.
-
Constructor Details
-
DefaultLineExpander
public DefaultLineExpander()Creates a new DefaultLineExpander.
-
-
Method Details
-
expand
Description copied from interface:LineExpanderExpands variables and expressions in the given command line.- Specified by:
expandin interfaceLineExpander- Parameters:
line- the command line to expandsession- the current command session (for variable lookup)- Returns:
- the expanded command line
-
expandBracedExpression
Expands a braced expression such asVAR,VAR:-default,VAR:=default,VAR:+alt, orVAR:?error.- Parameters:
expr- the expression inside the braces (without${ })session- the command session- Returns:
- the expanded value, or null if the variable is unknown and no modifier applies
-
resolve
Resolves a variable name to its value.The default implementation checks session variables first, then falls back to
System.getenv().Subclasses can override this to provide custom resolution (e.g., Groovy evaluation, default values).
- Parameters:
name- the variable namesession- the current command session- Returns:
- the resolved value as a string, or null if not found
-