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:
    DefaultAliasManager
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.lang.String> aliases()
      Returns all defined aliases.
      java.lang.String expand​(java.lang.String line)
      Expands aliases in a command line string.
      java.lang.String getAlias​(java.lang.String name)
      Returns the expansion for an alias.
      default void load()
      Loads aliases from persistent storage.
      boolean removeAlias​(java.lang.String name)
      Removes an alias.
      default void save()
      Saves aliases to persistent storage.
      void setAlias​(java.lang.String name, java.lang.String expansion)
      Defines or redefines an alias.
    • Method Detail

      • setAlias

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

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

        java.lang.String getAlias​(java.lang.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

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

        java.lang.String expand​(java.lang.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 java.io.IOException
        Loads aliases from persistent storage.

        The default implementation does nothing.

        Throws:
        java.io.IOException - if loading fails
      • save

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

        The default implementation does nothing.

        Throws:
        java.io.IOException - if saving fails