-
Notifications
You must be signed in to change notification settings - Fork 1
/
emoji-picker
executable file
·75 lines (65 loc) · 2.5 KB
/
emoji-picker
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
#! /bin/bash
EMOJI_DIR=$XDG_DATA_HOME/emoji
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
cat <<EOF
$ emoji
Pick and insert emoji from the list.
Auto-updates emoji list upon available updates.
EOF
exit
fi
command -v jq >/dev/null || { echo "jq is not installed" 1>&2; exit 127; }
command -v curl >/dev/null || { echo "curl is not installed" 1>&2; exit 127; }
command -v wget >/dev/null || { echo "wget is not installed" 1>&2; exit 127; }
command -v rofi >/dev/null || { echo "rofi is not installed" 1>&2; exit 127; }
command -v find >/dev/null || { echo "find is not installed" 1>&2; exit 127; }
command -v i3-msg >/dev/null || { echo "i3-msg is not installed" 1>&2; exit 127; }
command -v tmux >/dev/null || { echo "tmux is not installed" 1>&2; exit 127; }
get_installed_emoji_version() {
find $EMOJI_DIR -name "*.txt" 2>/dev/null | sort -V | tail -n1 | rev | cut -d/ -f1 | cut -d. -f2- | rev
}
get_latest_emoji_version() {
curl -s "https://registry.npmjs.org/emoji-datasource" | grep -Po '"version":"\K[0-9]+\.[0-9]+' | tail -n1
}
extract_emoji_from_json() {
version=$1
jq '.[] | {unified, short_name} | [values[]] | join(" ")' -r $EMOJI_DIR/$version.json \
| grep -vFe"keycap_star" -e"hash" -e"zero" -e"one" -e"two" -e"three" -e"four" -e"five" -e"six" -e"seven" -e"eight" -e"nine" \
| while read -a line; do
emoji="$(echo -e "\U${line[0]}" | sed 's/-.*$//')"
name=":${line[1]}:"
echo $emoji $name
done
}
update_emoji_data() {
mkdir -p "$EMOJI_DIR"
current="$1"
version=$(get_latest_emoji_version)
if [ "$latest" != "$current" ]; then
wget -nc "https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji_pretty.json" -O $EMOJI_DIR/$version.json --quiet
extract_emoji_from_json $version >$EMOJI_DIR/$version.txt
fi
}
is_on_blog() {
if [ `i3-msg -t get_workspaces | jq ".[] | select(.focused == true) | .num"` = "1" ] \
&& tmux list-sessions | grep "(attached)" | grep -e web >/dev/null; then
true
else
false
fi
}
emoji_version=$(get_installed_emoji_version)
update_emoji_data $emoji_version &
if [ -z "$emoji_version" ]; then
exit 1
fi
choice="$(tac $EMOJI_DIR/$emoji_version.txt | rofi rofi -dmenu -i -lines 15 -eh 1 -p emoji)"
if [ -n "$choice" ]; then
if is_on_blog; then
echo -e $choice | cut -d\ -f2 |
sed 's/y/z/g; s/:/Ö/g; s/_/?/g' | # because I use a german keyboard layout
xargs xdotool type --clearmodifiers # :name:
else
echo -e $choice | cut -d\ -f1 | xargs xdotool type # unicode symbol
fi
fi