gokcehan / lf

Terminal file manager
MIT License
7.62k stars 324 forks source link

Add command to safely eject/unmount/unplug external drive #1475

Open Andrew15-5 opened 11 months ago

Andrew15-5 commented 11 months ago

It would be nice to have as a built-in feature, but maybe it will be hard to do cross-platform, so at least a script in the https://github.com/gokcehan/lf/wiki/Tips would be great to have. I've made a script that uses rofi in which I can select one of the mounted partitions and based on the selection I can unmount it and power off its device. So basically what "eject"/"unmount" button does in Nautilus or any other GUI file manager.

But the problem is that I can't integrate it with lf (which would be 100% much easier and quicker to do). The udisksctl command that I use to unmount and power off says that the device is busy. Either lf is blocking the device or sh, since the custom lf command, is executing sh in the directory of the mounted device (partition). And doing cd / inside the ${{}} script doesn't help.

If I could do command chain (like in ranger, I remember it vaguely), then maybe cmd eject :chain saved_pwd=$PWD; cd /media/; eject "$saved_pwd" would work, since the underlying sh command will be executed in the /media/ directory and lf's PWD would also be in the /media/ so the external device shouldn't be busy anymore and could be ejected with no problem.

I can only think of creating a wrapper script that isn't somehow executed from the target device directory. If someone have any idea of how it can be done with pure scripts (POSIX shell is ideal), then please let me know.

dase78 commented 8 months ago

I do my automounting and unmounting stuff with udiskie (on Debian).

For lf I have following cmd:

cmd media-eject ${{ udiskie-umount --detach "$f" }} map E media-eject

With that, I just jump to the /media/USER/USBSTICK and execute the cmd by E.

Andrew15-5 commented 8 months ago

Although it's nice that I can use this new utility for me to unmount + turn-off the device, I still have a few problems: