Skip to content

Commit

Permalink
Updates for latest emoji-db
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer committed Dec 31, 2019
1 parent c85b891 commit 142264a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 80 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# FIND DAT EMOJI: Emoji search for Alfred
# Alfred Emoji Picker

Neat!
1. Install the latest version of this extension from the Releases page.
2. Type `emoji [thing you want to find]`

## Skin tone modifier support

By default, emoji that support skin tone (fitzpatrick) modifiers will default to no modifier. To pick an emoji with fitzpatrick modifier, add `-t[1-5]` to the end of your query. For emoji that accept more than one fitzpatrick modifier, you can specify multiple digits:

![GIF example of Fitzpatrick modifier support](assets/fitzpatrick-preview.gif)
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ task :default do
'emoji.rb',
'icon.png',
'emoji-db/emoji-db.json',
'emoji-db/emoji-img/',
'emoji-db/images/',
].each do |f|
dir_name = File.dirname(f)
mkdir_p(DestDir.join dir_name) if dir_name != '.'
Expand Down
Binary file added assets/fitzpatrick-preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion emoji-db
Submodule emoji-db updated 3580 files
122 changes: 63 additions & 59 deletions emoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ def to_unicode
end

class Array
def to_ruby
self.map(&:to_i).int_to_hex.map {|d| "\\u{#{d}}"}.join('')
end

def int_to_hex
self.map {|item| item.is_a?(Numeric) ? item.to_unicode : item.to_s}
end

def to_emoji
self.map(&:to_i).pack('U*') + "\ufe0f"
def to_codepoint_string
self.map {|item| item.is_a?(Numeric) ? '0x' + item.to_unicode : item.to_s}.join(', ')
end
end

PWD = Pathname.new File.expand_path(File.dirname(__FILE__))
EMOJI_DB_PATH = PWD.join('./emoji-db/')
MARSHAL_TMP_FILE = File.expand_path('./alfred-emoji-marshal-cache', Dir.tmpdir)
MARSHAL_TMP_FILE = File.expand_path('./alfred-emoji-workflow-cache', Dir.tmpdir)

STDERR.puts '===='
STDERR.puts "ARGV: `#{ARGV}`"
Expand All @@ -42,8 +34,12 @@ def to_emoji
opts.summary_indent = " "
opts.summary_width = 20

opts.on("-t", "--tone [1-5]", ['1','2','3','4','5'], "Include skin tone") do |t|
$skin_tone = t.to_i
opts.on("-t", "--tone [number]", /^\d+$/, "Include skin tone") do |t|
if t.to_i % 11 == 0
$skin_tone = (t.to_i / 11).to_s
else
$skin_tone = t
end
end

opts.on("-d", "--debug", "Run in debug mode (no cache)") do |_o|
Expand All @@ -60,6 +56,8 @@ def reset_marshal_cache
}

fc['db'].each do |k, v|
puts [k, v]

fc['db'][k]['name'] = fc['db'][k]['name'] || ''
fc['search_strings'][k] = [
'',
Expand All @@ -77,7 +75,9 @@ def reset_marshal_cache
end

if fc['db'][k]['fitz']
fc['db'][k]['fitz'].map! {|p| EMOJI_DB_PATH.join(p)}
fc['db'][k]['fitz'].each do |k, v|
v.merge!({ 'image' => EMOJI_DB_PATH.join(v['image']) })
end
end
end
f.rewind
Expand All @@ -94,7 +94,6 @@ def reset_marshal_cache
puts JSON.pretty_generate({
:items => [
{
# :arg => unicode_txt,
:uid => '__debug__',
:title => "Debug \u{1f41b}",
:subtitle => "Emoji database has been reset",
Expand Down Expand Up @@ -136,68 +135,73 @@ def reset_marshal_cache
end
end

items = (exact_matches + matches).map do |emojilib_key|
STDERR.puts "CODEPOINT: `#{emojilib_key}`"
emoji = EMOJI_OBJ['db'][emojilib_key]
STDERR.puts JSON.pretty_generate(ENV.to_h)

path = emoji['image']
codepoints = [emoji['codepoints']]

fitz = if $skin_tone && emoji['fitz']
[
nil,
0x1f3fb,
0x1f3fc,
0x1f3fd,
0x1f3fe,
0x1f3ff,
][$skin_tone]
items = (exact_matches + matches).map do |emoji_key|
STDERR.puts "CODEPOINT: `#{emoji_key}`"
emoji = EMOJI_OBJ['db'][emoji_key]

if $skin_tone && emoji['fitz'] && emoji['fitz'][$skin_tone]
emoji = emoji['fitz'][$skin_tone]
end

path = emoji['fitz'][$skin_tone - 1] if fitz
path = emoji['image']
codepoints = emoji['codepoints']

STDERR.puts "KEYWORDS: `#{EMOJI_OBJ['search_strings'][emojilib_key]}`"
STDERR.puts "KEYWORDS: `#{EMOJI_OBJ['search_strings'][emoji_key]}`"
STDERR.puts path

codepoints = [*emoji['codepoints'], fitz].compact

emojilib_name = emoji['emojilib_name'] ? ":#{emoji['emojilib_name']}:" : ''

unicode_txt = codepoints.to_emoji
ruby_txt = codepoints.to_ruby
unicode_txt = codepoints.pack('U*')
codepoint_txt = codepoints.to_codepoint_string

subtitle = "Copy #{unicode_txt} to clipboard"
mods = {
:ctrl => {
:valid => true,
:arg => emoji_key,
:subtitle => "Copy #{emoji_key} to clipboard",
:variables => {
:active_key => 'ctrl'
},
},
:shift => {
:valid => !!emoji['emojilib_name'],
:arg => emoji['emojilib_name'],
:subtitle => emoji['emojilib_name'] ? "Copy #{emojilib_name} to clipboard" : "No emojilib name :..(",
:variables => {
:active_key => 'shift'
},
},
:alt => {
:valid => true,
:arg => codepoint_txt,
:subtitle => "Copy '#{codepoint_txt}' to clipboard",
},
:cmd => {
:valid => true,
:arg => path,
:subtitle => "Reveal image for #{unicode_txt} in Finder",
:variables => {
:active_key => 'cmd'
},
},
}

{
:arg => unicode_txt,
:uid => emojilib_key,
:uid => emoji_key,
:variables => {},
:icon => {
:path => path,
},
# :type => 'file:skipcheck',
:title => emoji['name'],
:quicklookurl => path,
:subtitle => "Copy #{unicode_txt} to clipboard",
:mods => {
:alt => {
:valid => true,
:arg => ruby_txt,
:subtitle => "Copy #{ruby_txt} to clipboard"
},
:ctrl => {
:valid => true,
:arg => emojilib_key,
:subtitle => "Copy #{emojilib_key} to clipboard"
},
:shift => {
:valid => !!emoji['emojilib_name'],
:arg => emoji['emojilib_name'],
:subtitle => emoji['emojilib_name'] ? "Copy #{emojilib_name} to clipboard" : "No emojilib name :..("
},
:cmd => {
:valid => true,
:arg => path,
:subtitle => "Reveal image for #{unicode_txt} in Finder"
}
}
:subtitle => subtitle,
:mods => mods,
}
end

Expand Down
38 changes: 21 additions & 17 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,32 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<false/>
<key>clipboardtext</key>
<string>{query}</string>
<key>transient</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>2404AE08-D4CF-4265-B7BB-44043DD356DD</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
Expand Down Expand Up @@ -162,23 +183,6 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<false/>
<key>clipboardtext</key>
<string>{query}</string>
<key>transient</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>2404AE08-D4CF-4265-B7BB-44043DD356DD</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>type</key>
<string>alfred.workflow.utility.junction</string>
Expand Down

0 comments on commit 142264a

Please sign in to comment.