aboutsummaryrefslogblamecommitdiff
path: root/damb
blob: 02eea34f160eb7b5deaa9ed821b79c81dea9b428 (plain) (tree)
1
2
3
4
5
6
7
8
9
         
 

                                  
                        
                               
            
 
     
 






                                                

 
           
 







                                                                   

 
         
 

                                                                         
 


                                                    




                                             
                                                                                                           


                                          






















































                                                                                                     
#!/bin/sh

# dir where audio files are stored
amb_dir="$HOME/.local/share/damb"
pid_file="/tmp/damb.pid"
config_dir="$HOME/.config/damb"
menu="dmenu"

die()
{
	: "${1:?}"

	command -v notify-send > /dev/null &&
		notify-send " damb" "$1"

	printf "\033[31;1merr: %b\033[0m\n" "$1"
	exit "${2:-1}"
}

dep_check()
{
	: "${1:?}"

	for dep; do
		command -v "$dep" 1>/dev/null ||
			die "$dep not found, please install it" 127
	done

	unset dep
}

get_opt()
{
        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 | "$menu" -p "  " -l 25)" |
                cut -d '=' -f2 | tr -d ' '
}

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