Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This can/should co-exist with alias-tips #47

Closed
sagarkar10 opened this issue Dec 18, 2021 · 6 comments
Closed

This can/should co-exist with alias-tips #47

sagarkar10 opened this issue Dec 18, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@sagarkar10
Copy link

sagarkar10 commented Dec 18, 2021

That would be awesome if we can skip alias-tips repo suggestions if the command is coming from zsh-abbr
Does it make sense to use both? Thoughts?

@olets
Copy link
Owner

olets commented Dec 20, 2021

Thanks for the idea!

alias-tips has an excludes array (https://github.com/djui/alias-tips#exclude-some-aliases). If for every abbreviation you have an alias with the same short form (for example, alias x="my command" and abbr x="my command") then adding this snippet to your .zshrc should automatically exclude all abbreviations when the shell initializes:

export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="${(f)$(abbr l)}"

(that is, a single string from abbr l's multi-line output). If you're already excluding things,

export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="myalias ${(f)$(abbr l)}"

After adding a new abbreviation, open a new terminal and/or refresh open terminals (source ~/.zshrc or, preferably, exec zsh) to exclude the newly added abbreviation.

Does that meet your need?

@sagarkar10
Copy link
Author

Yes, that's exactly what I needed! Feeling stupid, didn't figure out myself!
Thanks a lot!

@sagarkar10
Copy link
Author

Also, a 2nd thought, we should auto sync alias and abbr in-case people are using both and transitioning!

@olets
Copy link
Owner

olets commented Dec 20, 2021

I've chosen to not support auto syncing because it would require letting abbr write and possibly first parse .zshrc. Have you tried abbr export-aliases and abbr import-aliases? See https://github.com/olets/zsh-abbr#commands for documentation.

You could do something like

  1. run abbr import-aliases once

  2. add to the end of your .zshrc

    abbr export-aliases > $HOME/aliases-from-abbr
    source $HOME/aliases-from-abbr

Putting it at the very end of your .zshrc will keep the aliases from breaking other parts of your shell initialization.

//

Another approach: run

abbr import-aliases

once and then delete as many aliases as possible. That's my personal recommendation. It would probably even obviate your alias-tips problem. If you decide to switch back to aliases, run abbr export-aliases once, and copy and paste that into your shell config.

@sagarkar10
Copy link
Author

I understand both the workarounds you proposed!
But I wanted to suggest something different
Assuming all the aliases are present in .zsh-aliases which is sourced in .zshrc

Someone might want to use both abbr and alias interchangeably.

What I suggest is

  • we create a hook that runs abbr export-aliases to .zsh-aliases file at session end (or on-demand)
  • Another hook that clears (abbr clear-all) abbr and then add abbr import-aliases

Let me know if that makes sense, I can add a PR, or we can discuss in more details about the implementation!

@olets
Copy link
Owner

olets commented Dec 21, 2021

Interesting idea! For now, it doesn't feel to me like syncing abbreviations and aliases is something zsh-abbr should take on — it's sort of a meta responsibility. But let's keep thinking it through.

//

abbr clear-all

Now and then I consider making a "delete all abbreviations" function… But I'm afraid if it existed I'd run it by mistake! The easiest way to roll your own will be

echo > $ABBR_USER_ABBREVIATIONS_FILE
abbr load

at session end

I'm not aware of a way to do this, but sounds cool. Are you?

//

What if you invert my previous idea, letting aliases be the source of truth

# .zshrc

source .zsh-aliases
# load zsh-abbr and then
abbr import-aliases --quiet

and to add an alias and an abbreviation use

% echo alias x=y > .zsh-aliases && exec zsh

(Could make a function for that, and abbralias x=y.) Or am I still not seeing your use case?

Repository owner locked and limited conversation to collaborators Dec 21, 2021
@olets olets converted this issue into discussion #51 Dec 21, 2021
@olets olets added the enhancement New feature or request label Jul 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants