GiselleSerate / myaliases

Useful shell aliases and functions.
6 stars 1 forks source link

what do you do if the alias already exists? oh noes #38

Closed GiselleSerate closed 6 years ago

GiselleSerate commented 6 years ago

It's easy for the aliases in the file we wrote. What about other aliases? I think the alias command would be helpful here, but parsing might be sketchy.

GiselleSerate commented 6 years ago

Create a temp file, pipe in the output from the alias command and grep through it for alias \""$1" at the beginning of each line?

aryarm commented 6 years ago

Maybe this will help? It says you can use the unalias command.

GiselleSerate commented 6 years ago

I reverse engineered this basically xD thanks though, useful suggestions

GiselleSerate commented 6 years ago

Most relevantly: what should the behavior be in this edge case? Should we:

aryarm commented 6 years ago

Since this command is all about convenience, I would have it override the old alias and not reject the new command. I would also check the generated file and delete if necessary. I'm also generally a fan of doing things silently, but we could echo out a statement telling the user that their old alias has been overridden if you want. However, if you do that, you might only want to do it when it's from our generated file so that we can stay true to the original behavior of alias in case any other programs assume that it won't print anything.

GiselleSerate commented 6 years ago

Oooh, that sounds like a great way to handle it. Currently I have it failing verbosely, but that shouldn't be terrible to implement. (side note for future me: will involve grep, probably, and a little bit of ed. and much regex.)

GiselleSerate commented 6 years ago

Currently deletes the old alias silently from .usr_aliases and does nothing otherwise. This seems to work for for all cases quite well; I'd probably only be worried about order if they try to override a name that someone is already using. Because then inclusion in how things get called from the .bashrc matters a lot as far as what actually gets defined.

GiselleSerate commented 6 years ago

This happens when I leave projects for a long time; I forget why I haven't closed issues. I'm going to close this, because my previous comments sound pretty resolvey to me?