Class DefaultAliasManager

java.lang.Object
org.jline.shell.impl.DefaultAliasManager
All Implemented Interfaces:
AliasManager

public class DefaultAliasManager extends Object implements AliasManager
Default in-memory implementation of AliasManager with optional file persistence.

Aliases are stored in a LinkedHashMap to preserve insertion order. When a persistFile is provided, aliases can be loaded from and saved to a simple name=expansion format (one alias per line).

The expand(String) method supports parameter substitution in alias expansions using $1, $2, etc. for positional parameters, and $@ for all remaining arguments. A recursion guard prevents infinite alias expansion loops.

Since:
4.0
  • Constructor Details

    • DefaultAliasManager

      public DefaultAliasManager()
      Creates an in-memory alias manager with no persistence.
    • DefaultAliasManager

      public DefaultAliasManager(Path persistFile)
      Creates an alias manager with optional file persistence.

      The persistence file uses a simple name=expansion format, one alias per line. Lines starting with # are treated as comments.

      Parameters:
      persistFile - the file to persist aliases to, or null for in-memory only
  • Method Details

    • setAlias

      public void setAlias(String name, String expansion)
      Description copied from interface: AliasManager
      Defines or redefines an alias.
      Specified by:
      setAlias in interface AliasManager
      Parameters:
      name - the alias name
      expansion - the expansion text
    • removeAlias

      public boolean removeAlias(String name)
      Description copied from interface: AliasManager
      Removes an alias.
      Specified by:
      removeAlias in interface AliasManager
      Parameters:
      name - the alias name
      Returns:
      true if the alias existed and was removed
    • getAlias

      public String getAlias(String name)
      Description copied from interface: AliasManager
      Returns the expansion for an alias.
      Specified by:
      getAlias in interface AliasManager
      Parameters:
      name - the alias name
      Returns:
      the expansion, or null if no alias with that name exists
    • aliases

      public Map<String,String> aliases()
      Description copied from interface: AliasManager
      Returns all defined aliases.
      Specified by:
      aliases in interface AliasManager
      Returns:
      an unmodifiable map of alias name to expansion
    • expand

      public String expand(String line)
      Description copied from interface: AliasManager
      Expands aliases in a command line string.

      The first word of the line is checked against defined aliases. If it matches, the alias expansion is substituted. Supports parameter markers ($1, $2, $@) in expansions. Includes a recursion guard to prevent infinite expansion.

      Specified by:
      expand in interface AliasManager
      Parameters:
      line - the command line to expand
      Returns:
      the expanded command line
    • load

      public void load() throws IOException
      Description copied from interface: AliasManager
      Loads aliases from persistent storage.

      The default implementation does nothing.

      Specified by:
      load in interface AliasManager
      Throws:
      IOException - if loading fails
    • save

      public void save() throws IOException
      Description copied from interface: AliasManager
      Saves aliases to persistent storage.

      The default implementation does nothing.

      Specified by:
      save in interface AliasManager
      Throws:
      IOException - if saving fails