Skip to content

feat: implement alias and unalias builtins with tab completion support - #9

Merged
podlLev merged 5 commits into
mainfrom
feature/aliases
Jul 8, 2026
Merged

podlLev merged 5 commits into
mainfrom
feature/aliases

Conversation

@podlLev

@podlLev podlLev commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Implements alias and unalias builtins with recursive alias expansion,
self-reference protection, and tab completion integration.

Changes

AliasManager

  • Add AliasManager to store aliases in insertion-order LinkedHashMap
  • Recursive alias expansion with depth limit of 10 to prevent infinite loops
  • Self-referencing aliases handled correctly (alias ls='ls --color' doesn't recurse)
  • Add AliasManager to Environment as shared shell state

alias Builtin

  • alias — list all aliases in alias name='value' format
  • alias name=value — set a new alias
  • alias name — print specific alias
  • Strip surrounding quotes from alias values
  • Error on unknown alias name

unalias Builtin

  • unalias name — remove specific alias
  • unalias -a — remove all aliases
  • Error on unknown alias name

Shell Integration

  • Expand aliases in Shell.handleInput before tokenizing
  • Save original input to history, not expanded form
  • Alias expansion happens after VAR=value detection

Tab Completion

  • Alias names complete at word index 0 alongside builtins and PATH binaries

Testing

Manually verified:

  • alias ll='ls' then ll lists directory correctly
  • alias say='echo' then say hello world prints hello world
  • Recursive alias alias a='echo hello'; alias b='a'; b prints hello
  • Self-referencing alias ls='ls --color' doesn't cause infinite loop
  • unalias ll removes alias
  • unalias -a removes all aliases
  • Tab completes alias names
  • Aliases persist across commands in same session

podlLev added 5 commits July 8, 2026 09:53
- Add AliasManager with set, get, remove, clear and getAll methods
- Implement recursive alias expansion with depth limit of 10
- Prevent infinite recursion for self-referencing aliases (e.g. alias ls='ls --color')
- Use LinkedHashMap to preserve insertion order for listing
- Add AliasManager to Environment as shared shell state
- Add AliasBuiltin to set aliases via alias name=value
- List all aliases with alias output format when no args given
- Print specific alias with alias name
- Strip surrounding single and double quotes from alias values
- Report error for unknown alias names
- Register as environment-dependent builtin in BuiltinFactory
- Add UnaliasBuiltin to remove aliases by name
- Support -a flag to remove all aliases at once
- Report error for unknown alias names
- Register as environment-dependent builtin in BuiltinFactory
- Call AliasManager.expand() on input before history expansion
- Save original input to history, not the expanded form
- Alias expansion happens after VAR=value detection
- Add aliasCompleter as StringsCompleter from AliasManager keys
- Complete alias names at word index 0 alongside builtins and binaries
- Update CandidateCollector.of() factory to accept and wire alias completer
@podlLev podlLev self-assigned this Jul 8, 2026
@podlLev podlLev added the enhancement New feature or request label Jul 8, 2026
@podlLev
podlLev merged commit c20c2ad into main Jul 8, 2026
@podlLev
podlLev deleted the feature/aliases branch July 8, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant