Difference between revisions of "How to set shell working directory after leaving Vifm"

From Vifm Wiki
Jump to: navigation, search
(Initial version of the page)
 
m (Add ! to command definition)
Line 8: Line 8:
 
* Add special command to <code>vifmrc</code>
 
* Add special command to <code>vifmrc</code>
 
<source lang="vim">
 
<source lang="vim">
command Q :execute '!echo %d > ~/.vifm/lastdir' | quit
+
command! Q :execute '!echo %d > ~/.vifm/lastdir' | quit
 
</source>
 
</source>
 
* Add this function to <code>.bashrc</code>
 
* Add this function to <code>.bashrc</code>

Revision as of 20:47, 27 August 2014

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.