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

Integration with MacOS global text replacements #35

Closed
mortenscheel opened this issue Feb 4, 2021 · 2 comments
Closed

Integration with MacOS global text replacements #35

mortenscheel opened this issue Feb 4, 2021 · 2 comments
Labels
docs enhancement New feature or request

Comments

@mortenscheel
Copy link
Contributor

mortenscheel commented Feb 4, 2021

Hi, thanks for a great plugin!

Yesterday I came across this post on Reddit: Is there a way to get the macOS Text Substitutes feature working in Terminal?

It was a fun challenge, and this is what I ended up with:

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

I have no idea if this is just a fun gimmick, or something a lot of Mac users would like to have. I just thought I'd share it here and let you decide.

Also, I haven't really used plutil or jq before, so there's probably cleaner ways of massaging the plist entries into a usable format.

@olets
Copy link
Owner

olets commented Feb 4, 2021

That’s cool, thanks for sharing!

I’m also not an expert in those, but that’s about what I expect jq to look like and I’ve confirmed it works for my system text substitutions.

I’d be happy to include this in the README if you wanted to make a PR. Maybe down by “highlighting” and “vi”?

Instead of read I prefer zsh’s nice syntax for creating an array from multi-line output:

typeset -a my_array=( ${(f)”$(my_cmd)”} )

will read each line of my_cmd’s output into the array my_array. If each item can be more than one line (might be relevant here - I haven’t tested what happens if you have a text substitution where the substitution has line breaks) instead of (f) you can do (ps|thedelimiter|) (can use a different character instead of pipes). Then iterate over that array. You can find some examples in zsh-abbr.zsh - for example in _abbr:import_fish() and _ abbr:import_git_aliases()

@olets
Copy link
Owner

olets commented May 10, 2021

Closed by PR #37. Thanks!

@olets olets closed this as completed May 10, 2021
@olets olets added enhancement New feature or request docs labels Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants