1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00

rofi-emoji: add various updates

This commit is contained in:
Joe Groocock 2018-04-12 03:20:08 +01:00
parent 5bb7c53519
commit 223034a3ea
Signed by: frebib
GPG Key ID: E0B16BEACFBB6A86

View File

@ -4,7 +4,7 @@
# century is about apparently... # century is about apparently...
# #
# Requirements: # Requirements:
# rofi, xsel, xdotool, curl, xmllint # rofi, xclip, xdotool, curl, xmllint
# #
# Usage: # Usage:
# 1. Download all emoji # 1. Download all emoji
@ -21,10 +21,9 @@
# #
# Where to save the emojis file. # Where to save the emojis file.
EMOJI_FILE="$HOME/.cache/emojis.txt" EMOJI_FILE="${XDG_CACHE_DIR:-$HOME/.cache}/emojis.txt"
# Urls of emoji to download. # Urls of emoji to download.
# You can remove what you don't need.
URLS=( URLS=(
'https://emojipedia.org/people/' 'https://emojipedia.org/people/'
'https://emojipedia.org/nature/' 'https://emojipedia.org/nature/'
@ -39,7 +38,9 @@ URLS=(
function download() { function download() {
echo "" > "$EMOJI_FILE" notify "$(basename "$0")" 'Downloading all emoji for your pleasure'
echo -n > "$EMOJI_FILE"
for url in "${URLS[@]}"; do for url in "${URLS[@]}"; do
echo "Downloading: $url" echo "Downloading: $url"
@ -58,20 +59,51 @@ function download() {
echo "$emojis" >> "$EMOJI_FILE" echo "$emojis" >> "$EMOJI_FILE"
done done
notify "$(basename "$0")" "We're all set!"
} }
function toclip() {
xclip -i -selection primary
xclip -o -selection primary | xclip -i -selection clipboard
}
function repeat() {
local rplc str="$1" count="$2"
rplc="$(printf "%${count}s")"
echo "${rplc// /"$str"}"
}
function notify() {
if which notify-send 1>/dev/null 2>/dev/null; then
notify-send "$1" "$2"
fi
}
function display() { function display() {
emoji=$(cat "$EMOJI_FILE" | grep -v '#' | grep -v '^[[:space:]]*$') emoji=$(cat "$EMOJI_FILE" | grep -v '#' | grep -v '^[[:space:]]*$')
line=$(echo "$emoji" | rofi -dmenu -i -p emoji -kb-custom-1 Ctrl+c $@) update="⏫ Update emoji cache"
emoji=$(printf "$emoji\n$update")
line=$(echo "$emoji" | rofi -dmenu -i -p emoji -kb-custom-1 Ctrl+c -kb-row-tab '' -kb-row-select Tab $@)
exit_code=$? exit_code=$?
if [ "${line[@]}" == "$update" ]; then
download
exit 0
fi
line=($line) line=($line)
last=${line[${#line[@]}-1]}
quantifier="${last:${#last}-1:1}"
echo "$quantifier" | egrep -q '^[0-9]+$' || quantifier=1
emoijs="$(repeat "${line[0]}" "$quantifier")"
if [ $exit_code == 0 ]; then if [ $exit_code == 0 ]; then
xdotool type --clearmodifiers "${line[0]}" xdotool type --clearmodifiers "$emoijs"
echo -n "$emoijs" | xclip -i
elif [ $exit_code == 10 ]; then elif [ $exit_code == 10 ]; then
echo -n "${line[0]}" | xsel -i -b echo -n "$emoijs" | xclip -i
fi fi
} }