Difference between revisions of "How to set Vifm current directory after leaving sub-shell"

From Vifm Wiki
Jump to navigation Jump to search
(Created page with "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....")
 
m (→‎Passing Vifm server name to the subsell: Fix a typo: subsell -> subshell)
Line 1: Line 1:
 
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.
 
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 subsell ====
+
==== Passing Vifm server name to the subshell ====
  
 
This could be done via environment variables. Set the following in <code>vifmrc</code> :
 
This could be done via environment variables. Set the following in <code>vifmrc</code> :

Revision as of 20:56, 31 August 2018

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