- macOS, Linux badge and AI suggestions showcase in README - Update user guide and docs for development
1.7 KiB
1.7 KiB
Command specification & lookup engine (spec/)
The spec module is the language parser of Iris. It understands the relationship between commands, subcommands, and flags.
Data structures
Spec: Top-level command definition (e.g.git).Subcommand: Recursively defined children (e.g.commitundergit).Generator: A function providing dynamic content (e.g. file paths, docker IDs).
The Lookup algorithm
The core path-traversal function:
- Tokenization: Splits
"git commit -m"into["git", "commit", "-m"]. Empty tokens (from trailing space) indicate the user is ready for the next suggestion level. - Tree walking: Starts at the root node (
git) and matches each token against available subcommands. - Context identification: When traversal stops (partial word or option prefix), it defines:
prefix: the path already traversed.partial: the word currently being typed.
- Result collection: Gathers all subcommands and options matching the
partialprefix.
Example
Input: git com
- Tokens:
["git", "com"]. - Walk: root is
git. - Next token
comdoesn't matchcommitexactly. - Stop.
partial = "com". - Suggestions: subcommands of
gitstarting withcom. - Return:
git commit.
Shell aliases & priority
- Dynamic alias parsing: Scans shell config files (
.bashrc,.zshrc) for defined aliases. - Highest priority: Aliases appear above spec and system command suggestions.
- Token injection: When a root command is an alias (e.g.
grforgo run), Iris injects expanded tokens into the lookup engine for accurate subcommand suggestions. - Display: Shows the expanded command (e.g.
tmux a -t) with the alias name in the description (e.g.alias: ta).