-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemoji
executable file
·103 lines (84 loc) · 2.36 KB
/
emoji
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# coding=utf-8
import os
import platform
import subprocess
import sys
ALIASES = {
'fliptable': 'flip',
'table': 'flip',
}
ALL_EMOJI = {
'unimpressed': 'ಠ_ಠ',
'shrug': '¯\_(ツ)_/¯',
'flip': '(╯°□°)╯︵ ┻━┻',
'tm': '™',
'cat': '(^._.^)ノ',
'catface': '(^人^)',
'sideeye': '(¬_¬)',
'o_O': 'ミ●﹏☉ミ',
'o_O2': '(⊙_◎)',
'o_O3': '(⊙﹏⊙✿)',
'dance1': '┌(・。・)┘♪',
'dance2': '└(・。・)┐♪',
'dance3': '♪┌(˘⌣˘)ʃ',
'scared': '(´・_・`)',
'flowerhappy': '(✿◠‿◠)',
'hug': '⊂((・▽・))⊃',
'facepalm': '(>_<)',
}
def has_clipboard_capability():
host_os = platform.system()
if host_os == 'Darwin':
return True
elif host_os == 'Linux':
if os.path.exists('/usr/bin/xclip'):
return True
else:
return False
else:
sys.stderr.write('warning: unknown OS %r\n' % host_os)
return False
def clipboard_copy(text):
host_os = platform.system()
if host_os == 'Darwin':
return clipboard_copy_mac(text)
elif host_os == 'Linux':
return clipboard_copy_linux(text)
else:
sys.stderr.write('warning: unknown OS %r\n' % host_os)
return False
def clipboard_copy_mac(text):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
return p.communicate(text)
def clipboard_copy_linux(text):
p = subprocess.Popen(['xclip', '-silent', '-selection', 'clipboard'],
stdin=subprocess.PIPE)
return p.communicate(text)
def emoji_for(word):
word = ALIASES.get(word, word)
return ALL_EMOJI[word]
def main(args):
if len(args) >= 1:
word = args[0]
try:
emoji = emoji_for(word)
except KeyError:
sys.stderr.write('Unknown emoji: %r\n' % word)
return 1
print emoji
if USE_CLIPBOARD:
clipboard_copy(emoji)
sys.stderr.write('(copied to clipboard)\n')
else:
for name, emoji in ALL_EMOJI.iteritems():
print name + ':', emoji
return 0
USE_CLIPBOARD = False
if 'CLIPBOARD' in os.environ:
USE_CLIPBOARD = os.environ['CLIPBOARD']
else:
if has_clipboard_capability():
USE_CLIPBOARD = True
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))