simplfy several vars, add depends func

This commit is contained in:
Jes Olson 2022-10-04 19:11:32 -05:00
parent 8dbea28ca6
commit 173d95d800

30
shmoji
View file

@ -11,45 +11,49 @@
set -e set -e
cmd="$1" cmd="$1"
emojidb="$HOME/.local/share/shmoji" emojidir="$HOME/.local/share/shmoji"
emojifile="$emojidb/emojis.txt" emojifile="$emojidir/emojis.txt"
die() { die() {
printf "%s\n" "$1" printf "%s\n" "$1"
exit 1 exit 1
} }
depends() {
for dep in "$@"; do
command -v "$dep" > /dev/null || die "$dep not found"
done
}
emojicheck() { emojicheck() {
[ -f "$emojifile" ] || die "emojis not found. try 'shmoji download'" [ -f "$emojifile" ] || die "emojis not found. try 'shmoji download'"
} }
case "$cmd" in case "$cmd" in
download) download)
command -v curl > /dev/null || die 'curl not found' depends curl
mkdir -p "$emojidb" mkdir -p "$emojidir"
# $ wc -l /var/www/trash.j3s.sh/emojis.txt # $ wc -l /var/www/trash.j3s.sh/emojis.txt
# 3570 /var/www/trash.j3s.sh/emojis.txt # 3570 /var/www/trash.j3s.sh/emojis.txt
curl 'https://trash.j3s.sh/emojis.txt' >"$emojidb/emojis.txt" curl 'https://trash.j3s.sh/emojis.txt' >"$emojifile"
;; ;;
bemenu) bemenu)
emojicheck emojicheck
command -v bemenu > /dev/null || die 'bemenu not found' depends bemenu wtype
command -v wtype > /dev/null || die 'wtype not found' emoji=$(cat "$emojifile" | bemenu -c -W 0.2 -l 20)
emoji=$(cat "$emojidb/emojis.txt" | bemenu -c -W 0.2 -l 20)
printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n' | wtype - printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n' | wtype -
;; ;;
rofi) rofi)
emojicheck emojicheck
command -v rofi > /dev/null || die 'rofi not found' depends rofi xdotool
command -v xdotool > /dev/null || die 'xdotool not found'
win=$(xdotool getactivewindow) win=$(xdotool getactivewindow)
emoji=$(cat "$emojidb/emojis.txt" | rofi -dmenu | cut -d " " -f 1 | tr -d '\n') emoji=$(cat "$emojifile" | rofi -dmenu | cut -d " " -f 1 | tr -d '\n')
[ "$emoji" ] && xdotool windowactivate --sync $win type --clearmodifiers $emoji [ "$emoji" ] && xdotool windowactivate --sync $win type --clearmodifiers $emoji
;; ;;
fzf) fzf)
emojicheck emojicheck
command -v fzf > /dev/null || die 'fzf not found' depends fzf
emoji=$(cat "$emojidb/emojis.txt" | fzf) emoji=$(cat "$emojifile" | fzf)
printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n' printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n'
;; ;;
*) *)