- java.lang.Object
-
- org.jline.shell.impl.DefaultLineExpander
-
- All Implemented Interfaces:
LineExpander
public class DefaultLineExpander extends java.lang.Object implements LineExpander
Default implementation ofLineExpanderthat 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:
LineExpander
-
-
Constructor Summary
Constructors Constructor Description DefaultLineExpander()Creates a new DefaultLineExpander.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringexpand(java.lang.String line, CommandSession session)Expands variables and expressions in the given command line.protected java.lang.StringexpandBracedExpression(java.lang.String expr, CommandSession session)Expands a braced expression such asVAR,VAR:-default,VAR:=default,VAR:+alt, orVAR:?error.protected java.lang.Stringresolve(java.lang.String name, CommandSession session)Resolves a variable name to its value.
-
-
-
Method Detail
-
expand
public java.lang.String expand(java.lang.String line, CommandSession session)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
protected java.lang.String expandBracedExpression(java.lang.String expr, CommandSession session)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
protected java.lang.String resolve(java.lang.String name, CommandSession session)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
-
-