Closed rrotter closed 4 months ago
I'd propose the following:
brew alias
guessing at what the "alias" does and printing that out, but the symlink creation should depend only on the filename and ignore the script parse.brew alias foo=whatever
and brew alias --edit foo
should write/edit the scripts. brew alias
needs to write to the bin
dir to fix missing links but should not be writing anything to ~/.brew-aliases/
.@rrotter Yes, this sounds reasonable. Could you open a PR? What, if anything, would this change for users using brew alias
in terms of behaviour/flow changes? Feel free to put this in the PR instead of here.
The only possibly desirable behavior this would change is that the description line (last comment line in the script) would not be "corrected" by brew alias
when the symlink is recreated (this only happens if you rm /opt/homebrew/bin/brew-myalias
). That's arguably a bug anyway, and it's hard to imagine anyone was depending upon this.
I will submit a PR for this. One question since you wrote it, @MikeMcQuaid. This bug seems to be caused by the misuse of existing_alias.write override: true
here
https://github.com/Homebrew/homebrew-aliases/blob/70e51cc954558b91cebb6f1cf925af3e5a744e98/lib/aliases.rb#L62
and I can't figure out why :override
or the opts
hash even exist here:
https://github.com/Homebrew/homebrew-aliases/blob/70e51cc954558b91cebb6f1cf925af3e5a744e98/lib/alias.rb#L43-L47
Was there previously a brew alias --override
flag that was perhaps broken in the move to AbstractCommand? I checked out fcf9dfc1, but brew has changed enough that it's no longer possible to run such an old version of homebrew-aliases.
Was there previously a
brew alias --override
flag that was perhaps broken in the move to AbstractCommand?
Yes, potentially. You could check the git log -p
output in the repository.
I don't use homebrew-aliases so honestly I defer to you here.
homebrew-aliases seems to support editing alias files (there is the
brew alias --edit
command). But, some edits that result in otherwise working scripts can confuse thealias
command leading to nonsensical output, useless files written to disk, and with the addition of the user deleting the symlink at$HOMEBREW_PREFIX/bin/brew-*
, causesbrew alias
to overwrite user created alias scripts with corrupted data.The following is shell output demonstrating all of the issues mentioned above. For the sake of brevity I didn't include the alias scripts, but they should be reproducible bit-for-bit using the
brew alias
andsed
commands below.I'm not saying that these exact scripts are useful, they aren't, but rather these are the minimal steps to reproduce issues I had with actual scripts I wrote.
It's pretty reasonable if these types of edits aren't supported, but
brew alias
should fail a little more gracefully if it can't parse a script. I found all of this by accident, and in one case was lucky that my dotfiles are in a git repo.