Lf: Can't open video files with "complex" filenames

Created on 24 Aug 2020  路  6Comments  路  Source: gokcehan/lf

I updated lf from version 14 to 16 and now I can't open videos with filenames containing spaces. For example: "this-file.mp4" or "this_file.mp4" will work wihout problem but "this file will not gonna work.mp4" won't open. Btw I'm using MPV 1:0.32.0 in Arch Linux to open videos. Thanks in advance!

question

Most helpful comment

@davidarrieta I tried your config with r14 from the releases page and with r16, and it doesn't work in both versions. This is to be expected since your command calls mpv foo bar.mp4 when $f is on a file named foo bar.mp4 which is condered two separate files named foo and bar.mp4 when it's parsed in shell so it fails.

You can either use quotes around $f (i.e. mpv --audio-display=no "$f"), or just set ifs "\n". This is described in "Shell Commands" section in the doc.

By the way, it's not related, but you don't need true or false in boolean options (e.g. it should be set preview instead of set preview true). See the doc for more info.

All 6 comments

@davidarrieta Can you paste the command/binding you used for opening these files? Do you set ifs option or quote the filename variable?

Nevermind, I found out the problem was this little script I was using. Is there any way to fix it so that it works with recent versions of lf or should I remove it completely?

cmd open ${{
    case $(file --mime-type $f -b) in
    image/vnd.djvu|application/pdf|application/octet-stream) setsid -f zathura $fx >/dev/null 2>&1 ;;
        text/*) $EDITOR $fx;;
    image/x-xcf|image/svg+xml) setsid -f gimp $f >/dev/null 2>&1 ;;
    image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|tif\)\(_large\)*$" | sxiv -aio 2>/dev/null | lf-select ;;
    audio/*) mpv --audio-display=no $f ;;
    video/*) setsid -f mpv $fx -quiet >/dev/null 2>&1 ;;
    application/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
        *) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
   esac
}}

@davidarrieta This command works for me. And I don't remember any relevant changes about this. Do you actually try this with r14 and r16 and confirm that it works in r14 but not r16? Also, do you use the ifs option?

Yes, it worked flawlessly in r14.
I don't know if I'm using ifs option, I'm gonna paste you my whole lfrc if that helps

## David's lf settings

set previewer ~/.config/lf/preview

## Basic Settings
set preview true
set ignorecase true
set shell sh
set color256
set icons

# Custom Functions
#cmd open ${{
#    case $(file --mime-type $f -b) in
#   image/vnd.djvu|application/pdf|application/octet-stream) setsid -f zathura $fx >/dev/null 2>&1 ;;
#        text/*) $EDITOR $fx;;
#   image/x-xcf|image/svg+xml) setsid -f gimp $f >/dev/null 2>&1 ;;
#   image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|tif\)\(_large\)*$" | sxiv -aio 2>/dev/null | lf-select ;;
#   audio/*) mpv --audio-display=no $f ;;
#   video/*) setsid -f mpv $fx -quiet >/dev/null 2>&1 ;;
#   application/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
#        *) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
#    esac
#}}

cmd mkdir ${{
  printf "Directory Name: "
  read ans
  mkdir $ans
}}

cmd mkfile ${{
  printf "File Name: "
  read ans
  $EDITOR $ans
}}

cmd chmod ${{
  printf "Mode Bits: "
  read ans

  for file in "$fx"
  do
    chmod $ans $file
  done

  lf -remote 'send reload'
}}

cmd sudomkfile ${{
  printf "File Name: "
  read ans
  sudo $EDITOR $ans
}}

cmd fzf_jump ${{
  res="$(find . -maxdepth 3 | fzf --reverse --header='Jump to location')"
  if [ -f "$res" ]; then
    cmd="select"
  elif [ -d "$res" ]; then
    cmd="cd"
  fi
  lf -remote "send $id $cmd \"$res\""
}}

# Bindings

cmd dragon %dragon-drag-and-drop -a -x $fx
cmd dragon-stay %dragon-drag-and-drop -a "$fx"
cmd dragon-individual %dragon-drag-and-drop $fx
cmd cpdragon %cpdragon
cmd mvdragon %mvdragon

cmd dlfile %dlfile

cmd yank-dirname ${{
    dirname -- "$f" | tr -d '\n' | xclip -i -selection clipboard
}}

cmd yank-path ${{
    echo "$fx" | xclip -i -selection clipboard
}}

cmd yank-basename ${{
    echo "$fx" |
      xargs -r -d '\n' basename -a -- |
      xclip -i -selection clipboard
}}

cmd yank-basename-without-extension ${{
    echo "$fx" |
      xargs -r -d '\n' basename -a -- |
      awk -e '{
        for (i=length($0); i > 0; i--) {
          if (substr($0, i, 1) == ".") {
            if (i == 1) print $0
            else print substr($0, 0, i-1)

            break
          }
        }

        if (i == 0)
          print $0
      }' | xclip -i -selection clipboard
}}

# Dragon Mapping
map dr dragon
map ds dragon-stay
map di dragon-individual
map dm mvdragon
map dc cpdragon
map dl dlfile

# Basic Functions
map . set hidden!
map DD delete
map p paste
map x cut
map y copy
map <enter> open
map mf mkfile
map mr sudomkfile
map md mkdir
map ms $mkscript
map ch chmod
map r rename
map H top
map L bottom
map R reload
map C clear
map U unselect
map mf fzf_jump
map mo open

# Remove some defaults
map m
map o
map n
map "'"
map '"'
map d
map c
map e

@davidarrieta I tried your config with r14 from the releases page and with r16, and it doesn't work in both versions. This is to be expected since your command calls mpv foo bar.mp4 when $f is on a file named foo bar.mp4 which is condered two separate files named foo and bar.mp4 when it's parsed in shell so it fails.

You can either use quotes around $f (i.e. mpv --audio-display=no "$f"), or just set ifs "\n". This is described in "Shell Commands" section in the doc.

By the way, it's not related, but you don't need true or false in boolean options (e.g. it should be set preview instead of set preview true). See the doc for more info.

That worked like a charm! Here where I live I would tell that you are "un pan de Dios" thanks bro

Pd: It's weird, I swear that in r14 it worked but meh it doesn't matter anymore

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BachoSeven picture BachoSeven  路  9Comments

gokcehan picture gokcehan  路  7Comments

mvrozanti picture mvrozanti  路  6Comments

pr4th4m picture pr4th4m  路  7Comments

doronbehar picture doronbehar  路  3Comments