Skip to content

Instantly share code, notes, and snippets.

@coolreader18
Last active June 17, 2020 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolreader18/17faf265b849f2e14fa6eef83b826441 to your computer and use it in GitHub Desktop.
Save coolreader18/17faf265b849f2e14fa6eef83b826441 to your computer and use it in GitHub Desktop.
#!/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