leo-arch / clifm

The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell.
https://github.com/leo-arch/clifm/wiki
GNU General Public License v2.0
1.29k stars 41 forks source link

Spawned apps detaching from Clifm #262

Open ErinVoid opened 7 months ago

ErinVoid commented 7 months ago

Is your feature request related to a problem? Please describe. The documentation is not clear but would like to spawn an application, i.e. mpv, and the clifm instance return to the prompt rather than await the application quitting. Am using Lira as the opener.

Additional context Clifm is good but not easy for mortals to understand from the documentation. Coming from nnn (as it doesn't [plugins especially nuke] play well with Alpine's standard Busybox install). Maybe the documentation could do with better structure and certainly be a little more consistent such as whenever a keypress is required, quote the necessary keys. However, getting into Clifm with previews for images so thank you.

leo-arch commented 7 months ago

Hi @ErinVoid. Edit Lira's config file (via mm edit) and add this line under the Video and audio section (delete/comment out the old line or place the new one on top of it):

X:^video/.*=xterm -e mpv %f &

This instructs clifm to open video files in the background using mpv on a separate instance of xterm (The focus will be on the newly created window, but clifm will immediately generate a new prompt).

As to the docs, thanks for the observation; I will take a look at it. Please feel free to edit it as you see it fits.

getting into Clifm with previews for images so thank you.

You're welcome!

ErinVoid commented 7 months ago

Thank for the feedback. The above doesn't work with Sakura which does spawn a new term but opens some random file from another folder completely with and without wrapping the %f in quotes. Trying st works correctly but complains "couldn't read from shell: I/O error" when exiting.

What would be perfect would be a variable that could set to detach apps without the need to launch another terminal if possible either globally or on a per app basis.

leo-arch commented 7 months ago

Tried with both sakura (3.8.7, AUR) and st (0.8.2) and they both work fine. Have you tried with another terminal, say xterm?

opens some random file from another folder completely with and without wrapping the %f in quotes

This is pretty weird, specially if it works fine when using st (which means that the file to be opened is properly passed to the opening application). Maybe some issue with your sakura version?

What would be perfect would be a variable that could set to detach apps without the need to launch another terminal if possible either globally or on a per app basis.

I'll bear this in mind.

ErinVoid commented 7 months ago

Thank you

leo-arch commented 7 months ago

But the thing is still not working, isn't it? Could you provide more context info (OS, DE/WM, term, shell, clifm version)? I need to reproduce the issue.

ErinVoid commented 7 months ago

Alpine Linux 3.18 up to date (musl libc) Sakura 3.8.7-r0 st 0.9-r1 CliFM 1.11-r0 bash 5.2.15-r5

In a folder; type "2" at the prompt, it recognises it being "Show S13E01.mp4", st opens correctly "/my/file/path/show name/Show S13E01" [st -e %f &] whereas Sakura immediately opens "/my/file/path/show/Show S00E01.mp4". It also occurs whatever file is chosen in the selected folder.

Bit of debugging; the requested URI is ""/my/file/path/show name/Show" so the whole folder is enqueued.

There are other posts about Sakura and it not coping with spaces. Wrapping the %f in "" makes no difference. st is fine!

leo-arch commented 7 months ago

Hey @ErinVoid! I'll try to reproduce the issue, but it is good to know that it seems to be a Sakura bug. However, maybe we can think of some workaround. For the time being, I guess it's better not to rely on Sakura, at least for this specific use case.

Btw, clifm current version is 1.15 (available in Alpine's Edge branch).

leo-arch commented 7 months ago

Issue reproduced, and yes, the -e option seems to be broken in Sakura since a long time (see this post).

So, if there's nothing else to add regarding our original issue, I guess we can close it.

ErinVoid commented 7 months ago

If possible, change to a feature request for spawning apps and focus returning to Clifm?

Happy the -e bug is Sakura's.

leo-arch commented 7 months ago

What do you mean exactly? Isn't this request already fulfilled by my first comment? True, once an app is spawned in a different window (detached), the focus will change to it, but this is not controlled by clifm, but by the window manager, in which case there's nothing we can do as far as I know.

ErinVoid commented 7 months ago

The request was for Clifm to open GUI applications as a separate process to allow Clifm to continue to be used without opening additional terminal windows.

leo-arch commented 7 months ago

When it comes to GUI apps, all you need to do is to specify the desired application. For example, if you want to open video files with vlc:

X:^video/.*=vlc

This will open vlc on a separate window without requiring a new terminal window (because GUI apps have their own window). Furthermore, the process is independent/detached: close clifm, and even the terminal it is running on, and vlc will continue running. You can also run it in the background (though it doesn't make much difference):

X:^video/.*=vlc %f &

In the case of terminal apps, like mpv, which do not create a new window by themselves, we need to run them on a new terminal window in order to detach it (otherwise, it will be executed on the current terminal window):

X:^video/.*=xterm -e mpv %f &

If this is not what you want, please provide a more concrete example.

leo-arch commented 7 months ago

@ErinVoid, is it ok to close this issue then?

ErinVoid commented 7 months ago

Other CLI FMs manage to open mpv without a terminal. Going to close anyway.

leo-arch commented 7 months ago

You can try silencing both STDERR and STDOUT, as follows:

X:^video/.*=mpv %f !EO &

As an alternative, mpv provides a --no-terminal command line switch which can be useful in this case. Try this:

X:^video/.*=mpv --no-terminal %f &

Please give it a shot and tell me if it's ok now.

leo-arch commented 6 months ago

@ErinVoid, have you tried this? Does it work for you?

leo-arch commented 6 months ago

@ErinVoid, does the above solution work as expected?

leo-arch commented 5 months ago

Happy the -e bug is Sakura's

Bug fixed upstream.

LinArcX commented 3 months ago

I have this issue. I tried: X:^video/.*=mpv --no-terminal %f &. mpv is running, yes. but the terminal is freezing. even Ctrl+C doesn't work. I need to press Ctrl+z to get out of it. I have this impression that & doesn't work properly in clifm.

leo-arch commented 3 months ago

@LinArcX , I cannot reproduce this issue (tried this rule with Openbox/i3 and alacritty/xterm/lxterminal, no issue). Could you provide more context information (clifm version, terminal, desktop environment/window manager)?

LinArcX commented 3 months ago

OS: VoidLinux Clifm: v1.18(https://github.com/search?q=repo%3Avoid-linux%2Fvoid-packages%20clifm&type=code) Terminal Emulator: wezterm Windows Manager: dwm

leo-arch commented 3 months ago

Tried with wezterm. Still nothing.

The only way I've found to reproduce this issue (or at least something similar) is having the current terminal window maximized, in which case the video is certainly reproduced, but in a window hidden by the currently used one.

Please try with a different terminal (to discard a terminal-specific issue) and with a different video application (to discard an mpv-specific issue).

leo-arch commented 4 weeks ago

@LinArcX, could you try the latest git version (1.18.6)? We added a new value (%x) to control how opening applications are launched. Replace your video line with this:

X:^video/.*=mpv --no-terminal %x