0

So I'm using the terminal file explorer vifm and especially have a hotkey to open a shell in the current directory.

nnoremap s :shell<cr>

However, when I exit this shell, I get back to vifm. But I don't want to have vifm still open after going to the shell. I want to kill vifm and afterwards when I exit the terminal, it should bring me to the grandparent process or kill the terminal emulator. I tried stuff like

nnoremap s :!./testscript.sh<cr>

where testscript.sh contains:

#!/bin/sh
zsh &
kill $PPID

, but I always get an error code 1 from the last command when doing this. However, the grandparent terminal opens (not in the current directory of vifm) without a child being created. Changing the script to

#!/bin/sh
zsh &
kill $PPID
clear

Does also give me an error code and opens the grandparent terminal (not in the current directory of vifm) and changing the script to

#!/bin/sh
kill $PPID
zsh

Makes the now open terminal buggy (buffer for letters somehow breaks).

So what is the right way to open a terminal in the current directory while closing vifm without receiving an error code or messing up the buffer?

Edit: To clearify what I need this for. I want to prevent a usb-stick being busy. If the current shell isn't using the usb-stick anymore, but vifm is still inside a directory of the usb-stick, I can't unmount the stick. And I want to do this without exiting the terminal, but rather closing vifm beforehand.

Edit 2: Found the answer. It works with:

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

( https://q2a.vifm.info/449/closing-vifm-while-still-opening-terminal-current-directory )

  • Would this be close enough? :nn s :shell<cr>:exit<cr> – Mark Plotnick Mar 28 at 14:27
  • That does the trick. Thank you so much! Edit: Sorry, but I still have a problem with this. My main reason for doing this is to prevent a usb-stick being busy. If the current shell isn't using the usb-stick anymore, but vifm is still inside a directory of the usb-stick, I can't unmount the stick. And I want to do this without exiting to stop vifm. – Uwe Müller Mar 28 at 14:28
  • I just saw your newly-edited question. Try :nn s :cd /<cr>:shell<cr>:exit<cr>. That may not be sufficient if you have multiple directories/panes open. Hopefully someone can come up with a solution. – Mark Plotnick Mar 28 at 14:41
  • Thanks for the answer. However, I would still like to open the shell in the current directory, not in /. But I really like the idea of this. – Uwe Müller Mar 28 at 14:47
  • Please see Can I answer my own question? Your answer should not be in the question body. – Kamil Maciorowski Mar 29 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.