From 173d95d8000a47992afbc6cc3d5c961e43377d2f Mon Sep 17 00:00:00 2001 From: Jes Olson Date: Tue, 4 Oct 2022 19:11:32 -0500 Subject: [PATCH] simplfy several vars, add depends func --- shmoji | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/shmoji b/shmoji index cd7363b..70488c3 100755 --- a/shmoji +++ b/shmoji @@ -11,45 +11,49 @@ set -e cmd="$1" -emojidb="$HOME/.local/share/shmoji" -emojifile="$emojidb/emojis.txt" +emojidir="$HOME/.local/share/shmoji" +emojifile="$emojidir/emojis.txt" die() { printf "%s\n" "$1" exit 1 } +depends() { + for dep in "$@"; do + command -v "$dep" > /dev/null || die "$dep not found" + done +} + emojicheck() { [ -f "$emojifile" ] || die "emojis not found. try 'shmoji download'" } case "$cmd" in download) - command -v curl > /dev/null || die 'curl not found' - mkdir -p "$emojidb" + depends curl + mkdir -p "$emojidir" # $ wc -l /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) emojicheck - command -v bemenu > /dev/null || die 'bemenu not found' - command -v wtype > /dev/null || die 'wtype not found' - emoji=$(cat "$emojidb/emojis.txt" | bemenu -c -W 0.2 -l 20) + depends bemenu wtype + emoji=$(cat "$emojifile" | bemenu -c -W 0.2 -l 20) printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n' | wtype - ;; rofi) emojicheck - command -v rofi > /dev/null || die 'rofi not found' - command -v xdotool > /dev/null || die 'xdotool not found' + depends rofi xdotool 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 ;; fzf) emojicheck - command -v fzf > /dev/null || die 'fzf not found' - emoji=$(cat "$emojidb/emojis.txt" | fzf) + depends fzf + emoji=$(cat "$emojifile" | fzf) printf "%s" "$emoji" | cut -d " " -f 1 | tr -d '\n' ;; *)