Skip to content

Commit 142264a

Browse files
committed
Updates for latest emoji-db
1 parent c85b891 commit 142264a

File tree

6 files changed

+95
-80
lines changed

6 files changed

+95
-80
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
# FIND DAT EMOJI: Emoji search for Alfred
1+
# Alfred Emoji Picker
22

3-
Neat!
3+
1. Install the latest version of this extension from the Releases page.
4+
2. Type `emoji [thing you want to find]`
5+
6+
## Skin tone modifier support
7+
8+
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:
9+
10+
![GIF example of Fitzpatrick modifier support](assets/fitzpatrick-preview.gif)

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ task :default do
1616
'emoji.rb',
1717
'icon.png',
1818
'emoji-db/emoji-db.json',
19-
'emoji-db/emoji-img/',
19+
'emoji-db/images/',
2020
].each do |f|
2121
dir_name = File.dirname(f)
2222
mkdir_p(DestDir.join dir_name) if dir_name != '.'

assets/fitzpatrick-preview.gif

265 KB
Loading

emoji-db

Submodule emoji-db updated 3580 files

emoji.rb

+63-59
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@ def to_unicode
1414
end
1515

1616
class Array
17-
def to_ruby
18-
self.map(&:to_i).int_to_hex.map {|d| "\\u{#{d}}"}.join('')
19-
end
20-
21-
def int_to_hex
22-
self.map {|item| item.is_a?(Numeric) ? item.to_unicode : item.to_s}
23-
end
24-
25-
def to_emoji
26-
self.map(&:to_i).pack('U*') + "\ufe0f"
17+
def to_codepoint_string
18+
self.map {|item| item.is_a?(Numeric) ? '0x' + item.to_unicode : item.to_s}.join(', ')
2719
end
2820
end
2921

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

3426
STDERR.puts '===='
3527
STDERR.puts "ARGV: `#{ARGV}`"
@@ -42,8 +34,12 @@ def to_emoji
4234
opts.summary_indent = " "
4335
opts.summary_width = 20
4436

45-
opts.on("-t", "--tone [1-5]", ['1','2','3','4','5'], "Include skin tone") do |t|
46-
$skin_tone = t.to_i
37+
opts.on("-t", "--tone [number]", /^\d+$/, "Include skin tone") do |t|
38+
if t.to_i % 11 == 0
39+
$skin_tone = (t.to_i / 11).to_s
40+
else
41+
$skin_tone = t
42+
end
4743
end
4844

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

6258
fc['db'].each do |k, v|
59+
puts [k, v]
60+
6361
fc['db'][k]['name'] = fc['db'][k]['name'] || ''
6462
fc['search_strings'][k] = [
6563
'',
@@ -77,7 +75,9 @@ def reset_marshal_cache
7775
end
7876

7977
if fc['db'][k]['fitz']
80-
fc['db'][k]['fitz'].map! {|p| EMOJI_DB_PATH.join(p)}
78+
fc['db'][k]['fitz'].each do |k, v|
79+
v.merge!({ 'image' => EMOJI_DB_PATH.join(v['image']) })
80+
end
8181
end
8282
end
8383
f.rewind
@@ -94,7 +94,6 @@ def reset_marshal_cache
9494
puts JSON.pretty_generate({
9595
:items => [
9696
{
97-
# :arg => unicode_txt,
9897
:uid => '__debug__',
9998
:title => "Debug \u{1f41b}",
10099
:subtitle => "Emoji database has been reset",
@@ -136,68 +135,73 @@ def reset_marshal_cache
136135
end
137136
end
138137

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

143-
path = emoji['image']
144-
codepoints = [emoji['codepoints']]
145-
146-
fitz = if $skin_tone && emoji['fitz']
147-
[
148-
nil,
149-
0x1f3fb,
150-
0x1f3fc,
151-
0x1f3fd,
152-
0x1f3fe,
153-
0x1f3ff,
154-
][$skin_tone]
140+
items = (exact_matches + matches).map do |emoji_key|
141+
STDERR.puts "CODEPOINT: `#{emoji_key}`"
142+
emoji = EMOJI_OBJ['db'][emoji_key]
143+
144+
if $skin_tone && emoji['fitz'] && emoji['fitz'][$skin_tone]
145+
emoji = emoji['fitz'][$skin_tone]
155146
end
156147

157-
path = emoji['fitz'][$skin_tone - 1] if fitz
148+
path = emoji['image']
149+
codepoints = emoji['codepoints']
158150

159-
STDERR.puts "KEYWORDS: `#{EMOJI_OBJ['search_strings'][emojilib_key]}`"
151+
STDERR.puts "KEYWORDS: `#{EMOJI_OBJ['search_strings'][emoji_key]}`"
160152
STDERR.puts path
161153

162-
codepoints = [*emoji['codepoints'], fitz].compact
163154

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

166-
unicode_txt = codepoints.to_emoji
167-
ruby_txt = codepoints.to_ruby
157+
unicode_txt = codepoints.pack('U*')
158+
codepoint_txt = codepoints.to_codepoint_string
159+
160+
subtitle = "Copy #{unicode_txt} to clipboard"
161+
mods = {
162+
:ctrl => {
163+
:valid => true,
164+
:arg => emoji_key,
165+
:subtitle => "Copy #{emoji_key} to clipboard",
166+
:variables => {
167+
:active_key => 'ctrl'
168+
},
169+
},
170+
:shift => {
171+
:valid => !!emoji['emojilib_name'],
172+
:arg => emoji['emojilib_name'],
173+
:subtitle => emoji['emojilib_name'] ? "Copy #{emojilib_name} to clipboard" : "No emojilib name :..(",
174+
:variables => {
175+
:active_key => 'shift'
176+
},
177+
},
178+
:alt => {
179+
:valid => true,
180+
:arg => codepoint_txt,
181+
:subtitle => "Copy '#{codepoint_txt}' to clipboard",
182+
},
183+
:cmd => {
184+
:valid => true,
185+
:arg => path,
186+
:subtitle => "Reveal image for #{unicode_txt} in Finder",
187+
:variables => {
188+
:active_key => 'cmd'
189+
},
190+
},
191+
}
168192

169193
{
170194
:arg => unicode_txt,
171-
:uid => emojilib_key,
195+
:uid => emoji_key,
196+
:variables => {},
172197
:icon => {
173198
:path => path,
174199
},
175200
# :type => 'file:skipcheck',
176201
:title => emoji['name'],
177202
:quicklookurl => path,
178-
:subtitle => "Copy #{unicode_txt} to clipboard",
179-
:mods => {
180-
:alt => {
181-
:valid => true,
182-
:arg => ruby_txt,
183-
:subtitle => "Copy #{ruby_txt} to clipboard"
184-
},
185-
:ctrl => {
186-
:valid => true,
187-
:arg => emojilib_key,
188-
:subtitle => "Copy #{emojilib_key} to clipboard"
189-
},
190-
:shift => {
191-
:valid => !!emoji['emojilib_name'],
192-
:arg => emoji['emojilib_name'],
193-
:subtitle => emoji['emojilib_name'] ? "Copy #{emojilib_name} to clipboard" : "No emojilib name :..("
194-
},
195-
:cmd => {
196-
:valid => true,
197-
:arg => path,
198-
:subtitle => "Reveal image for #{unicode_txt} in Finder"
199-
}
200-
}
203+
:subtitle => subtitle,
204+
:mods => mods,
201205
}
202206
end
203207

info.plist

+21-17
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,32 @@
119119
<key>version</key>
120120
<integer>1</integer>
121121
</dict>
122+
<dict>
123+
<key>config</key>
124+
<dict>
125+
<key>autopaste</key>
126+
<false/>
127+
<key>clipboardtext</key>
128+
<string>{query}</string>
129+
<key>transient</key>
130+
<true/>
131+
</dict>
132+
<key>type</key>
133+
<string>alfred.workflow.output.clipboard</string>
134+
<key>uid</key>
135+
<string>2404AE08-D4CF-4265-B7BB-44043DD356DD</string>
136+
<key>version</key>
137+
<integer>2</integer>
138+
</dict>
122139
<dict>
123140
<key>config</key>
124141
<dict>
125142
<key>alfredfiltersresults</key>
126143
<false/>
144+
<key>alfredfiltersresultsmatchmode</key>
145+
<integer>0</integer>
146+
<key>argumenttrimmode</key>
147+
<integer>0</integer>
127148
<key>argumenttype</key>
128149
<integer>1</integer>
129150
<key>escaping</key>
@@ -162,23 +183,6 @@
162183
<key>version</key>
163184
<integer>2</integer>
164185
</dict>
165-
<dict>
166-
<key>config</key>
167-
<dict>
168-
<key>autopaste</key>
169-
<false/>
170-
<key>clipboardtext</key>
171-
<string>{query}</string>
172-
<key>transient</key>
173-
<true/>
174-
</dict>
175-
<key>type</key>
176-
<string>alfred.workflow.output.clipboard</string>
177-
<key>uid</key>
178-
<string>2404AE08-D4CF-4265-B7BB-44043DD356DD</string>
179-
<key>version</key>
180-
<integer>2</integer>
181-
</dict>
182186
<dict>
183187
<key>type</key>
184188
<string>alfred.workflow.utility.junction</string>

0 commit comments

Comments
 (0)