-
Notifications
You must be signed in to change notification settings - Fork 0
/
e
executable file
·76 lines (64 loc) · 1.55 KB
/
e
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
#!/usr/bin/env bash
url="https://www.unicode.org/Public/emoji/latest/emoji-test.txt"
db="${HOME}/.emoji/emoji.txt"
export LC_ALL=en_US.UTF-8
function init() {
[ ! -f "${db}" ] \
&& mkdir -p "$(dirname "${db}")" \
&& update
}
function http_get() {
curl -sS "${url}"
}
function http_head() {
curl -sS --HEAD "${url}" \
| grep -i "Last-Modified" \
| cut -f 2- -d " "
}
function outdated() {
echo -n "local: " && cat "${db}.head"
echo -n "remote: " && http_head
}
function update() {
http_get \
| grep "^..... " | grep ";" | grep "fully-qualified" \
| sed "s,# ,#," | cut -f 2- -d "#" | cut -c 1 > "${db}" \
&& http_head > "${db}.head" \
&& cat "${db}" | wc -l | tr -d " " > "${db}.lines"
}
function shuffle() {
lines="$(cat "${db}.lines")"
line="$((${RANDOM} % ${lines} + 1))"
cat "${db}" | head -n "${line}" | tail -n 1
}
function copy() {
case "${OSTYPE}" in
darwin*)
pbcopy
;;
linux*)
xclip -selection clipboard
;;
cygwin*)
cat > /dev/clipboard
;;
*)
cat
return 1
esac
return 0
}
function clipboard() {
read emoji
echo -n "${emoji}" | copy \
&& echo "${emoji} copied to clipboard." >&2 \
|| echo -e "\nERROR: Clipboard not supported on ${OSTYPE}, use 'emoji shuffle' instead." >&2
}
init
case "${1}" in
outdated|update|shuffle)
"${1}"
;;
*)
shuffle | clipboard
esac