Class DefaultLineExpander

java.lang.Object
org.jline.shell.impl.DefaultLineExpander
All Implemented Interfaces:
LineExpander

public class DefaultLineExpander extends Object implements LineExpander
Default implementation of LineExpander that provides sane defaults for variable expansion.

Supported expansions:

  • $VAR and ${VAR} ? variable expansion from session variables, then System.getenv()
  • ~ at word start ? expands to user.home system 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 Details

    • DefaultLineExpander

      public DefaultLineExpander()
      Creates a new DefaultLineExpander.
  • Method Details

    • expand

      public String expand(String line, CommandSession session)
      Description copied from interface: LineExpander
      Expands variables and expressions in the given command line.
      Specified by:
      expand in interface LineExpander
      Parameters:
      line - the command line to expand
      session - the current command session (for variable lookup)
      Returns:
      the expanded command line
    • expandBracedExpression

      protected String expandBracedExpression(String expr, CommandSession session)
      Expands a braced expression such as VAR, VAR:-default, VAR:=default, VAR:+alt, or VAR:?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 String resolve(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 name
      session - the current command session
      Returns:
      the resolved value as a string, or null if not found