Share your useful shell scripts!

pleure
2018-08-17T22:52:18Z

Disclaimer: Don't run scripts offered to you by randos unless you trust them or review it yourself

I use this constantly, it just plays music by file name, specifically matching *NAME* with case-insensitivity. Requires bash 4.something.

# play -ln SONGS ...
# -l don't shuffle
# -n dry run
mpv_args="--no-audio-display --no-resume-playback \
          --msg-level=all=status --term-osd-bar"
shopt -s globstar nullglob nocaseglob

shuffle=true
dry=false
while [[ "$1" == -* ]]; do
    if [[ "$1" == "-l" ]]; then
        shuffle=false
    elif [[ "$1" == "-n" ]]; then
        dry=true
    fi

    shift 1
done

if [[ "$shuffle" == true ]]; then
    mpv_args="--shuffle $mpv_args"
fi

songs=()
while [[ "$#" != 0 ]]; do
    songs+=( ~/music/**/**/*"$1"*.* ) # change this to match your music directory layout
    shift 1                                               # could probably use find instead
done

if [[ "$dry" == true ]]; then
    if [[ "$shuffle" == true ]]; then
        printf "Shuffle mode is on\n"
    fi

    for song in "${songs[@]}"; do
        printf "$song\n"
    done

    exit
fi

if [[ ${#songs[@]} != 0 ]]; then
    mpv $mpv_args "${songs[@]}"
fi

I make no claims to the quality of this but it works!

Comments URL: https://tildes.net/~comp/55y/share_your_useful_shell_scripts

Votes: 36

Comments: 13