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

From Vifm Wiki
Jump to navigation Jump to search
m (→‎Passing Vifm server name to the subsell: Fix a typo: subsell -> subshell)
(Add the page to HOWTO category)
 
Line 30: Line 30:
 
}
 
}
 
</source>
 
</source>
 +
 +
[[Category:HOWTO]]

Latest revision as of 21:06, 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[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\""
        }
}