Interface AliasManager

All Known Implementing Classes:
DefaultAliasManager

public interface AliasManager
Manages command aliases for the shell.

An alias maps a short name to a longer command expansion. When the shell encounters an alias name as the first word of a command line, it substitutes the alias expansion before executing.

Implementations may optionally support persistence via load() and save().

Since:
4.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns all defined aliases.
    expand(String line)
    Expands aliases in a command line string.
    Returns the expansion for an alias.
    default void
    Loads aliases from persistent storage.
    boolean
    Removes an alias.
    default void
    Saves aliases to persistent storage.
    void
    setAlias(String name, String expansion)
    Defines or redefines an alias.
  • Method Details

    • setAlias

      void setAlias(String name, String expansion)
      Defines or redefines an alias.
      Parameters:
      name - the alias name
      expansion - the expansion text
    • removeAlias

      boolean removeAlias(String name)
      Removes an alias.
      Parameters:
      name - the alias name
      Returns:
      true if the alias existed and was removed
    • getAlias

      String getAlias(String name)
      Returns the expansion for an alias.
      Parameters:
      name - the alias name
      Returns:
      the expansion, or null if no alias with that name exists
    • aliases

      Map<String,String> aliases()
      Returns all defined aliases.
      Returns:
      an unmodifiable map of alias name to expansion
    • expand

      String expand(String line)
      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.

      Parameters:
      line - the command line to expand
      Returns:
      the expanded command line
    • load

      default void load() throws IOException
      Loads aliases from persistent storage.

      The default implementation does nothing.

      Throws:
      IOException - if loading fails
    • save

      default void save() throws IOException
      Saves aliases to persistent storage.

      The default implementation does nothing.

      Throws:
      IOException - if saving fails