How to set Vifm current directory after leaving sub-shell

From Vifm Wiki
Revision as of 00:06, 1 September 2018 by Xaizek (talk | contribs) (Add the page to HOWTO category)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The idea is to pass the Vifm server name to the subshell, and then add a shell exit hook that would use Vifm remote command to change the folder of the parent Vifm instance.

Passing Vifm server name to the subshell[edit]

This could be done via environment variables. Set the following in vifmrc :

let $VIFM_SERVER_NAME = v:servername

Changing the folder in parent Vifm[edit]

The command to do it is

vifm --server-name "$VIFM_SERVER_NAME" --remote +"cd \"$PWD\""

Note: please do not use "... --remote "$PWD"" - this will always change the folder of the left panel.

Now, the exit handler is shell dependant:

  • For zsh, the following function could be added to .zshrc :
zshexit() {
        if [[ -n $VIFM_SERVER_NAME ]] {
                vifm --server-name "$VIFM_SERVER_NAME" --remote +"cd \"$PWD\""