command-line-argumentsfzfmpv

Formatting fzf multi-select output for mpv


The following works:

# play file1 and then file 2:
mpv "file1" "file 2"

# use fzf to select a file and play that file:
mpv "$(fdfind . /path/to/Music | fzf)" 

Now fzf -m allows for multi-select. However the following doesn't work:

mpv "$(fdfind . /path/to/Music | fzf -m)" #select at least 2 files here

At first I thought the problem is that fzf -m returns the selections separated by newline, such as:

file1
file 2

So I tried some sed/ awk stuff:

fdfind . /path/to/Music | fzf -m |
    sed 's/^/"/;s/$/"/' | #double quotes every line
    awk 1 ORS=' ' | #replace newline with ' '
    head -c -1 | #delete the last ' '

To format it as:

"file1" "file 2"

This also doesn't work. So I also tried kdialog with the following:

mpv "$(kdialog --getopenfilename --multiple /path/to/Music/)" #select at least 2 files here

And it doesn't work. However the kdialog-open-files.lua user-script works fine for me!

I think I am making a mistake in how I am passing the arguments to mpv, as the following (obviously) works:

mpv "$(fdfind . /path/to/Music | fzf)" "$(fdfind . /path/to/Music | fzf)"

Solution

  • Found it from this stack-overflow post:

    fdfind . Music/ | fzf -m | xargs -d "\n" mpv
    

    You can also pass command line arguments to mpv this way:

    fdfind . Music/ | fzf -m | xargs -d "\n" mpv --volume=50 --loop-playlist=inf
    

    etc.