~ $ type mp
mp is a function with definition
function mp
mpv --input-ipc-server=/tmp/mpvsocket --shuffle --no-video /home/xk/Music/
end
~ $ type trash
trash is a function with definition
function trash
kioclient move (echo $argv | sed 's/^-\w\+//') trash:/
end
function nextSong
set song (echo '{ "command": ["get_property", "path"] }' | socat - /tmp/mpvsocket | jq .data | sed -e 's/^"//' -e 's/"$//')
echo 'playlist_next' | socat - /tmp/mpvsocket
incrFileSuffix $song
end
function incrFileSuffix
for file in $argv
set match (string match -e -r '(.+)\.(\d+)\.([^.]+)' $file)
if test $status -eq 0
set root $match[-3]
set n (math $match[-2] + 1)
set ext $match[-1]
else
set match (string match -e -r '(.+)\.([^.]+)' $file)
if test $status -ne 0
# file does not have a dot. what to do?
return
end
set root $match[-2]
set n 1
set ext $match[-1]
end
if test $n -gt 30
trash $file
else
mv -iv $file $root.$n.$ext
end
end
end
function playSomething -a genre manyMult
set many (default $manyMult 1)
cd ~/Music/
set files (filesDeep | fileTypeAudio | shuf -n (math "100*$many") | filterByGenre $genre)
mpv --input-ipc-server=/tmp/mpvsocket --shuffle --no-audio-display $files
end
function default
for val in $argv
if test "$val" != ""
echo $val
break
end
end
end
function filesDeep
find . -not -type d -exec du -h {} + | sort -h $argv | cut -f2
end
function filterByGenre
while read file
if ffprobe "$file" 2>&1 | sed -E -n 's/^ *GENRE *: (.*)/\1/p' | grep -q "$argv"
echo "$file"
else
end
end
end
function fileTypeAudio
grep -E 'flac$|mp3$|m4a$|wav$|ogg$|oga$|opus$'
end
thanks to glenn jackman:
https://stackoverflow.com/questions/61265691/conditionally-rename-files-based-on-regex
https://stackoverflow.com/questions/61473464/iterate-over-stdin-fish-context-filter-music-files-by-genre-grep