dotfiles/bin/choose-emoji-menu

31 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-01-13 17:10:01 +00:00
#!/usr/bin/env bash
2020-01-20 09:18:40 +00:00
# Simply create a universal emoji selection list.
# The emoji list should be the following file:
# https://unicode.org/Public/emoji/13.0/emoji-test.txt
2020-01-20 09:18:40 +00:00
# Dependencies:
2020-01-20 09:18:40 +00:00
# * mktemp - GNU coreutils 8.31
2020-11-02 14:46:43 +00:00
# * wget - GNU Wget 1.20.3
2020-01-20 09:18:40 +00:00
# * sed - GNU sed 4.8
# * awk - GNU Awk 5.0.1
# * rofi - Version: 1.5.4
# * xclip - version 0.13
2021-01-13 17:10:01 +00:00
emoji_file="${XDG_DATA_HOME:-$HOME/.local/share}/emoji-list.txt"
# Checks if the emoji file is non-existent or past its modification date of at least 30 days ago (2592000 seconds).
if [[ ! -f $emoji_file ]] || test $(expr $(date "+%s") - $(date --reference="$emoji_file" "+%s")) -gt 2592000; then
notify-send "Downloading the emoji data file."
wget --output-document "$emoji_file" https://unicode.org/Public/emoji/latest/emoji-test.txt
touch $emoji_file
fi
2020-05-01 14:45:31 +00:00
selection=$(awk 'match($0, /([0-9A-F ]+)\s+; fully-qualified\s+# (\S+) E[[:digit:]]+.[[:digit:]]+ (.+)$/, a){print a[2], a[3]}' "$emoji_file" \
2020-11-02 14:46:43 +00:00
| rofi -dmenu -i -matching fuzzy -p "Choose an emoji to copy." \
| awk '{print $1}')
if [ -n "$selection" ]; then
printf "%s" "$selection" | xclip -selection clipboard && notify-send "'$(xclip -o -selection clipboard)' has been copied to clipboard."
fi