Last active
September 25, 2020 11:52
-
-
Save tiennou/d58a30307fd45eb7b889b2dbc3a10e06 to your computer and use it in GitHub Desktop.
Quick-'n-dirty TextExpander to espanso converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'plist' | |
require 'optimist' | |
require 'yaml' | |
opts = Optimist::options do | |
version "0.1.0" | |
banner <<-EOS | |
espando-convert converts a TextExpander snippet file to espando's YML syntax | |
Usage: | |
espando-convert <filename> | |
EOS | |
end | |
file = ARGV.shift | |
raise ArgumentError.new "missing input file" unless file | |
data = Plist.parse_xml(file) | |
package = {} | |
package['name'] = data['groupInfo']['groupName'] | |
package['name'] ||= "untitled" | |
package['matches'] = [] | |
data['snippetsTE3'].each do |snippet| | |
match = {} | |
match['trigger'] = snippet['abbreviation'] | |
match['replace'] = snippet['plainText'] | |
next if match['trigger'].empty? or match['replace'].empty? | |
package['matches'] << match | |
end | |
puts YAML.dump(package) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment