fix: correct alias matching, portable prompts, and exit codes - #12
Merged
Conversation
- Match names pair-wise in _excute/_remove via new _find helper so a command line that equals another alias name can no longer execute the wrong entry or corrupt the store on removal - Replace bash-only read -rep/-pr prompts (broken under zsh, and al rm with no args errored in both shells) with portable printf + read -r - Propagate real exit codes: al <name> returns the command's status and unknown names return 1 - Reject duplicate and empty names in al add - Declare function variables local and use IFS= on read loops so sourcing no longer clobbers shell variables Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several verified correctness bugs in
aliasme.sh, found during a code review pass. All fixes were verified by reproduction in both bash and zsh; the existing test suite passes.Wrong-command execution / data corruption (pair-wise matching)
_excuteand_removecompared every line of~/.aliasme/cmdagainst the given name — including command lines. With aliasesx -> deployanddeploy -> echo deploying:al rm deploymatchedx's command line, deleted the wrong pair, and left the file corrupted soal xsilently ran the wrong command.evala name line.Both now step through the file in name/command pairs (like
_listalready did), via a new_findhelper.Interactive prompts broken (both shells)
al rmwith no argument usedread -pr, which errors in bash (not a valid identifier) and zsh (no coprocess).al addwith no arguments usedread -rep, a bashism that fails under zsh (-p: no coprocess), storing aliases with empty names.Replaced with portable
printf+read -r.Exit codes
alpreviously returned 0 on every path. Now:al <unknown>printsnot found: <name>and returns 1al <name>propagates the executed command's exit status, soal foo && ...chains workStore hygiene
al addrejects duplicate names (previously appended silently; execution used the first entry whilelsshowed both) and empty names/commandslocal, so sourcing the script no longer clobbers$name,$cmd,$line,$optsin the user's interactive shellIFS=on all read loops so whitespace round-tripsTest plan
test/aliastest.shpasses (4/4)🤖 Generated with Claude Code