How to set shell working directory after leaving Vifm

From Vifm Wiki
Revision as of 20:39, 26 August 2014 by Xaizek (talk | contribs) (Initial version of the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
vifm()
{
    if [ -f ~/.vifm/lastdir ]; then
        rm ~/.vifm/lastdir
    fi
    /usr/local/bin/vifm "$@"
    if [ -f ~/.vifm/lastdir ]; then
        cd `cat ~/.vifm/lastdir`
    fi
}

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.