Skip to content

fix: correct alias matching, portable prompts, and exit codes - #12

Merged
Jintin merged 1 commit into
masterfrom
fix-correctness
Aug 2, 2026
Merged

fix: correct alias matching, portable prompts, and exit codes#12
Jintin merged 1 commit into
masterfrom
fix-correctness

Conversation

@Jintin

@Jintin Jintin commented Aug 2, 2026

Copy link
Copy Markdown
Owner

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)

_excute and _remove compared every line of ~/.aliasme/cmd against the given name — including command lines. With aliases x -> deploy and deploy -> echo deploying:

  • al rm deploy matched x's command line, deleted the wrong pair, and left the file corrupted so al x silently ran the wrong command.
  • Similarly, execution could match a command line and eval a name line.

Both now step through the file in name/command pairs (like _list already did), via a new _find helper.

Interactive prompts broken (both shells)

  • al rm with no argument used read -pr, which errors in bash (not a valid identifier) and zsh (no coprocess).
  • al add with no arguments used read -rep, a bashism that fails under zsh (-p: no coprocess), storing aliases with empty names.

Replaced with portable printf + read -r.

Exit codes

al previously returned 0 on every path. Now:

  • al <unknown> prints not found: <name> and returns 1
  • al <name> propagates the executed command's exit status, so al foo && ... chains work

Store hygiene

  • al add rejects duplicate names (previously appended silently; execution used the first entry while ls showed both) and empty names/commands
  • All function variables are local, so sourcing the script no longer clobbers $name, $cmd, $line, $opts in the user's interactive shell
  • IFS= on all read loops so whitespace round-trips

Test plan

  • test/aliastest.sh passes (4/4)
  • Manual verification in bash and zsh: pair-collision execute/remove scenarios, interactive add/rm via stdin, duplicate rejection, exit-code propagation

🤖 Generated with Claude Code

- 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>
@Jintin
Jintin merged commit e6564d5 into master Aug 2, 2026
2 checks passed
@Jintin
Jintin deleted the fix-correctness branch August 2, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant