Closed mortenscheel closed 3 years ago
By the way, substitutions containing newlines and other special characters seem to be escaped properly.
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
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
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
.
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?
@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!
@all-contributors please add @mortenscheel for code. (#37)
@olets
I've put up a pull request to add @mortenscheel! :tada:
I've tried my best to implement the suggestions mentioned in #35 but you're welcome to suggest further changes.