Lf: Close lf without close the opened file

Created on 1 Mar 2019  路  6Comments  路  Source: gokcehan/lf

When I open a file, a video, for example, and close lf, the video closes too, so I need to mantain open lf to work with my files.

I tried adding & disown at the end of the open script and of the map o command, but works only when I open lf throught a terminal and if I close lf using q, if I close the terminal window the file closes too. If I open lf ussing my keyboard keybinding super + f and press q, then both the terminal and the file window is closed.

There's a way to close lf without close the opened file? Thanks!

bug

All 6 comments

@juacq97 I did not quite understand what you say. You may need to describe this more clearly and separately for each use case.

You can use shell-async commands to detach a process from lf. For example &ffplay $f should open a movie file that is detached from the terminal and you should be able to close lf and/or the terminal without closing the movie.

For the desktop shortcut, I'm guessing you start a terminal and pass lf as the initial process in your desktop binding. In that case, it is normal that terminal closes once you quit lf. You may be able to change your binding to start a shell instead and run lf as the first command inside the shell. Then terminal should not close once lf is closed.

Case 1: Open lfwith my WM shortcut (termite -e lf)

  1. Opened a video with mpv (my open script is ashell-async command, but I tried with &mpv $f and I have the same results)
  2. Focused on lf, I press q
  3. Both lf and mpv windows closes.

Case 2: Open a terminal (termite) and open lf inside

  1. Opened a video with mpv
  2. Focused on the terminal, I press my WM shortcut to close windows (super + shift + q)
  3. Both lf and mpv windows closes.

Case 3: Open a terminal and open lf inside

  1. Opened a video with mpv
  2. Focused on lf I press q
  3. lf closes. The mpv window is still alive.
  4. I close the terminal window and the mpv window still there

The result on the third case (only lf closes and the other window still there) it's the desired on the two first. Isn't a big problem, but sometimes I tend to close all the windows that are not occupied, and accidentally close lf.

@juacq97 I'm able to reproduce the problem on my machine. Same thing happens in the terminal without lf unless you disown the process but this does not seem to work when you add it to the commands as you say. I tried adding process.Release to the code for async commands but it does not seem to fix this problem either. I will need to look further into this. I'm marking this issue as a bug. Thanks for the report.

I wouldn't call this an issue with lf, as it's a universal trait of how Linux spawns processes and is something you have to take into account with any terminal app.

Use setsid along with & to avoid this. This is what I have to open videos with mpv:

case $(file --mime-type $f -b) in
    ...
    video/*) setsid mpv $f >/dev/null 2>&1 & ;;
    ...
esac

It does exactly what you want.

@LukeSmithxyz I did not know about setsid at all, thanks. @juacq97 This does seem to solve both use cases. Strangely though, this only seems to work for mpv but not for ffplay for me. This is probably related to attached terminals or so. In any case, the use of ffplay is not very common as a standalone video player so this should not be much of a problem.

I will try to mention setsid somewhere in the documentation. Then I think we can close this issue.

I tried with setsid and now works as I want, I tried with mpv, sxiv, zathura and emacs and all works fine:

cmd open &{{
    case $(file --mime-type "$f" -b) in
        text/*) setsid /home/$USER/.config/lf/emc $f;;
    video/*) setsid mpv $f > /dev/null 2 2>&1 & ;;
        *) for f in $f; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
    esac }}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nostdm picture nostdm  路  6Comments

ipstone picture ipstone  路  6Comments

aidam38 picture aidam38  路  9Comments

davidarrieta picture davidarrieta  路  6Comments

marcosrdac picture marcosrdac  路  3Comments