How to set Vifm current directory after leaving sub-shell

From Vifm Wiki
Revision as of 20:56, 31 August 2018 by Xaizek (talk | contribs) (→‎Passing Vifm server name to the subsell: Fix a typo: subsell -> subshell)
Jump to navigation Jump to 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

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

let $VIFM_SERVER_NAME = v:servername

Changing the folder in parent Vifm

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\""
        }
}