How to set shell working directory after leaving Vifm

From Vifm Wiki
Revision as of 17:47, 27 August 2014 by Xaizek (talk | contribs) (Add ! to command definition)
Jump to navigation Jump to search

Vifm can't do that on its own, since it's impossible to change working directory of another process (parent shell in this case). Still, it's possible to do this by relying on a shell to do part of the job.

Here is an example, how one can do that with bash:

  • Add special command to vifmrc
command! Q :execute '!echo %d > ~/.vifm/lastdir' | quit
  • Add this function to .bashrc
    if [ -f ~/.vifm/lastdir ]; then
        rm ~/.vifm/lastdir
    /usr/local/bin/vifm "$@"
    if [ -f ~/.vifm/lastdir ]; then
        cd `cat ~/.vifm/lastdir`

Now running Vifm and quiting it using :Q command (which can be mapped to ZZ and/or ZQ) will change directory of shell to the directory of current active pane.