aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2023-03-08 15:15:25 +0530
committersinanmohd <pcmsinan@gmail.com>2023-03-11 19:05:05 +0530
commitb46c3bca9dd291b04d8af9f62d845a29616b8e33 (patch)
treec9af917cfe74717f1214a39c0b5ac0a4e5eba520
parentffcf654084c70df62319131c91e8e65a189176f2 (diff)
damb: wayland support, more appropriate dependency check
-rwxr-xr-xdamb117
1 files changed, 80 insertions, 37 deletions
diff --git a/damb b/damb
index 8a7548b..02eea34 100755
--- a/damb
+++ b/damb
@@ -1,60 +1,103 @@
#!/bin/sh
-# https://sinanmohd.com
-####################
-## user variables ##
-####################
# dir where audio files are stored
amb_dir="$HOME/.local/share/damb"
-# pid file location
pid_file="/tmp/damb.pid"
-# dir where config files are stored
config_dir="$HOME/.config/damb"
+menu="dmenu"
-get_opt()
+die()
{
- printf "select\nlinks\nrandom\nstream\nstop" | dmenu -p "הּ "
+ : "${1:?}"
+
+ command -v notify-send > /dev/null &&
+ notify-send " damb" "$1"
+
+ printf "\033[31;1merr: %b\033[0m\n" "$1"
+ exit "${2:-1}"
}
-get_ambs()
+dep_check()
{
- find "$amb_dir" -type f -exec basename {} \;
+ : "${1:?}"
+
+ for dep; do
+ command -v "$dep" 1>/dev/null ||
+ die "$dep not found, please install it" 127
+ done
+
+ unset dep
}
-send_err()
+get_opt()
{
- printf "error: %s\n" "$1"
- notify-send " damb" "error, $1"
+ printf "select\nlinks\nrandom\nstream\nstop" | "$menu" -p "הּ "
+}
+get_ambs()
+{
+ find "$amb_dir" -type f -exec basename {} \;
}
get_link()
{
grep -v "^#.*$" "$config_dir"/links |
- grep "$(grep -v "^#.*$" "$config_dir"/links | cut -d '=' -f1 | dmenu -p " " -l 25)" |
+ grep "$(grep -v "^#.*$" "$config_dir"/links | cut -d '=' -f1 | "$menu" -p " " -l 25)" |
cut -d '=' -f2 | tr -d ' '
}
-case "$(get_opt)" in
- select) ffplay -volume 20 -nodisp -loop 0 "$amb_dir/$(get_ambs | dmenu -p " " -l 25)" &
- echo "$!" >> "$pid_file"
- ;;
- links) mpv --no-video --no-resume-playback "$(get_link)" &
- echo "$!" >> "$pid_file"
- ;;
- random) ffplay -volume 20 -nodisp -loop 0 "$amb_dir/$(get_ambs | shuf -n1)" &
- echo "$!" >> "$pid_file"
- ;;
- stop) while IFS= read -r process
- do
- kill -2 "$process"
- done < "$pid_file"
-
- rm "$pid_file"
- ;;
- stream) mpv --no-video "$(xclip -o -sel clip)" &
- echo "$!" >> "$pid_file"
- ;;
- "") ;; # stay quiet when user quits the program during selection
- *) send_err "option not implemented";;
-esac
+main()
+{
+ [ -z "$DISPLAY" ] &&
+ menu="bemenu"
+
+ dep_check "$menu"
+
+ case "$(get_opt)" in
+ select)
+ dep_check "ffplay"
+ ffplay -volume 20 -nodisp -loop 0 "$amb_dir/$(get_ambs | "$menu" -p " " -l 25)" &
+ echo "$!" >> "$pid_file"
+ ;;
+ links)
+ dep_check "mpv"
+ mpv --no-video --no-resume-playback "$(get_link)" &
+ echo "$!" >> "$pid_file"
+ ;;
+ random)
+ dep_check "ffplay"
+ ffplay -volume 20 -nodisp -loop 0 "$amb_dir/$(get_ambs | shuf -n1)" &
+ echo "$!" >> "$pid_file"
+ ;;
+ stop)
+ while read -r process
+ do
+ kill -2 "$process"
+ done < "$pid_file"
+
+ rm "$pid_file"
+ ;;
+ stream)
+ paste=
+ dep_check "mpv"
+
+ if [ -z "$DISPLAY" ]
+ then
+ dep_check "wl-paste"
+ paste="$(wl-paste)"
+ else
+ dep_check "xclip"
+ paste="$(xclip -o -sel clip)"
+ fi
+
+ mpv --no-video "$paste" &
+ echo "$!" >> "$pid_file"
+ ;;
+ "")
+ ;; # stay quiet when user quits the program during selection
+ *)
+ "option not implemented";;
+ esac
+}
+
+main