Skip to content

Instantly share code, notes, and snippets.

@coolreader18
Last active Jun 17, 2020
Embed
What would you like to do?
#!/bin/bash
INFO_LINES=4
dir=.
while getopts "d:" opt; do
case "$opt" in
d)
dir=$OPTARG
;;
esac
done
cd "$dir" 2>/dev/null || {
>&2 echo "Provided dir option '$dir' is not a valid directory."
exit 1
}
HOME=$(tput home; tput rmso)
SC=$(tput sc)
RC=$(tput rc)
CLEARTOP=$(
tput rmso
for i in 0..$INFO_LINES; do
tput cup $i 0
tput el
done
)
CLEARREST=$(tput ed)
CLEARLINE=$(tput el)
tput smcup
tput clear
cleanup() {
pkill -P $$
tput rmcup
exit 0
}
trap cleanup SIGINT EXIT
while true; do
output=$(termux-media-player info)
echo -n "$SC$CLEARTOP$HOME$output$RC"
done &
INPUT=$(tput cup $INFO_LINES 0; tput smso)
OUTPUT=$(tput cup $((INFO_LINES+1)) 0; tput rmso)
echo -n "$INPUT$CLEARLINE"
while true; do
read -a cmd
case "${cmd[0]}" in
vol) output=$(termux-volume music "${cmd[1]}") ;;
q|quit) exit 0 ;;
*) output=$(termux-media-player ${cmd[@]}) ;;
esac
echo -n "$OUTPUT$CLEARREST$output$INPUT$CLEARLINE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment