Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

Closing vifm while still opening a terminal in current directory

0 votes
asked Mar 29 in vifm by anonymous
edited Mar 29 by xaizek

Hello everybody,

I use this hotkey to open a shell in the current directory:

nnoremap s :shell<cr>
However, vifm is the parent process of this shell. This leads to the problem that when I mount a device, jump into it with vifm and open a shell there, and then e.g. cd ~, I can't unmount the device because vifm still uses the device and therefore it is busy. I have to exit the shell, quit vifm and then I can unmount the device.

Is it possible to open a shell in the current directory and also closing vifm in the background?

I tried

:nn s :shell<cr>:exit<cr>
, but there vifm is still open in the background.
Also using the script

#!/bin/sh
kill $PPID
zsh

and then using it with the key s doesn't help because the now opened terminal is broken (letter buffer is going crazy).

Is there a way to do what I want? Thank you in advance.

1 Answer

0 votes
answered Mar 29 by xaizek
edited Mar 29 by xaizek

Hello,

maybe a script like this will do as a workaround

#!/bin/sh
kill $PPID
usleep 20
reset
exec zsh

Alternatively, if closing vifm isn't required, something like this mapping might do

nnoremap s : let $PREVPWD = system('pwd')
          \| cd
          \| !cd $PREVPWD && exec $SHELL<cr>

It "remembers" current location, changes to home directory and starts a shell in original location.

I think this is as good as it gets without a builtin way to replace vifm's process with a shell.

In case you're using vifm only for navigation, see this wiki page.

commented Mar 29 by anonymous

Thank you so much! However, with the first solution used like this:

nnoremap s :! sh ~/script.sh<cr>
I get an exit code 1 and get to the grandparent process, so to the terminal in which I opened vifm.

The second solution creates a new terminal. However, this will always be placed in ~ and not in the current directory.

commented Mar 29 by xaizek

Hm, not sure why the first one doesn't work properly.

The second solution creates a new terminal.

It shouldn't. Maybe $SHELL contains path to terminal? You can replace it with zsh.

commented Mar 29 by anonymous

I mean with a terminal zsh, not e.g. xterm. It doesn't create a new window, just adds zsh to the process tree (e.g. zsh -> vifm -> zsh). However, this new zsh instance points to ~, not the current directory of vifm.

commented Mar 29 by xaizek

Renaming to $OLDPWD at last moment was a bad idea, renamed to $PREVPWD. Directory should be correct now.

commented Mar 29 by anonymous

Works now! Thank you so much!

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...