olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~13,000 unique cloners as of May '24, 580+ Homebrew installs 6/23-6/24
https://zsh-abbr.olets.dev
Other
510 stars 18 forks source link

Add guide to register macOS substitutions #37

Closed mortenscheel closed 3 years ago

mortenscheel commented 3 years ago

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

mortenscheel commented 3 years ago

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

mortenscheel commented 3 years ago

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 commented 3 years ago

Sorry for the long silence @mortenscheel!

Two ideas for changes:

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 commented 3 years ago

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.

mortenscheel commented 3 years ago

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 commented 3 years ago

@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 commented 1 year ago

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

allcontributors[bot] commented 1 year ago

@olets

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