Skip to content
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

Add guide to register macOS substitutions #37

Merged
merged 2 commits into from
May 2, 2021
Merged

Add guide to register macOS substitutions #37

merged 2 commits into from
May 2, 2021

Conversation

mortenscheel
Copy link
Contributor

I've tried my best to implement the suggestions mentioned in #35 but you're welcome to suggest further changes.

@mortenscheel
Copy link
Contributor Author

By the way, substitutions containing newlines and other special characters seem to be escaped properly.

@mortenscheel
Copy link
Contributor Author

Regarding performance, is there a reason why your zinit example isn't using turbo mode?

This is how I load the plugin and register the substitutions without any impact to shell startup time:

_register_mac_text_substitutions() {
    for substitution in ${(@f)"$(defaults read ~/Library/Preferences/.GlobalPreferences.plist NSUserDictionaryReplacementItems | plutil -convert json -o - - | jq -r "map({ (.replace): .with}) | add | to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]")"}; do
        abbr add --session --global --quiet "$substitution"
    done
}

zinit ice wait lucid atload'_register_mac_text_replacements'
zinit light olets/zsh-abbr

@olets
Copy link
Owner

olets commented Feb 27, 2021

Sorry for the long silence @mortenscheel!

Two ideas for changes:

  • I played with jq a little today. I think it can be shorter… but I also don't use system text substitutions much, so please double check! Does this work? h/t https://stackoverflow.com/a/34227629

    ${(f)"$(defaults read ~/Library/Preferences/.GlobalPreferences.plist NSUserDictionaryReplacementItems | plutil -convert json -o - - | jq -r 'to_entries[] | "\(.value.replace)=\"\(.value.with)\""')"}
  • How about instead of --session --global --quiet we simply say [options]. (Fwiw, because I don't change my system text substitutions, I personally would run this on the command line without --session. Then it will be saved, and won't have to process in every new terminal. But we don't need to get into that detail in the readme)

is there a reason why your zinit example isn't using turbo mode?

I don't use turbo mode for this plugin just in case something is slow. I don't want to open a new terminal, type some commands, then look at the window and see abbreviations! (And in the Performance section I don't use it because I want to show that even the slowest possibility is not slow.) But there's nothing wrong with using turbo mode. If it works for you that's great

@mortenscheel
Copy link
Contributor Author

No problem :)
The shorter jq command works great. Personally I don't want the replacement text wrapped in double quotes so I've removed them. Let me know if you want me to add them back in.

I've also replaced the options with [options], and removed the suggestion about adding the snippet to .zshrc.

Copy link
Owner

@olets olets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience. One inline question. I've also started wondering… should this be in the readme or should it be supported, just like importing aliases? What do you think?


```shell
for substitution in ${(f)"$(defaults read ~/Library/Preferences/.GlobalPreferences.plist NSUserDictionaryReplacementItems | plutil -convert json -o - - | jq -r 'to_entries[] | "\(.value.replace)=\(.value.with)"')"}; do
abbr add [options] "$substitution"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

Suggested change
abbr add [options] "$substitution"
abbr add [options] $substitution

There may be an edge case I'm not thinking of.

@mortenscheel
Copy link
Contributor Author

Sorry, I missed your comment.

I don't have a clue how many people will find this feature useful. Maybe just put it in the readme, and see if anyone asks for a command to import them?

@olets olets merged commit 99af045 into olets:main May 2, 2021
@olets
Copy link
Owner

olets commented May 2, 2021

@mortenscheel this is in main! Thanks again for your patience —lots going on over on here in the last couple months— and for the contribution!

@olets
Copy link
Owner

olets commented May 27, 2023

@all-contributors please add @mortenscheel for code. (#37)

@allcontributors
Copy link
Contributor

@olets

I've put up a pull request to add @mortenscheel! 🎉

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.

None yet

2 participants