Difference between revisions of "How to set shell working directory after leaving Vifm"
Jump to navigation
Jump to search
(0.7.9 => 0.8; there was no 0.7.9 version) |
(fixed fish function) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 12: | Line 12: | ||
vicd() | vicd() | ||
{ | { | ||
− | local dst="$(command vifm --choose-dir -)" | + | local dst="$(command vifm --choose-dir - "$@")" |
if [ -z "$dst" ]; then | if [ -z "$dst" ]; then | ||
echo 'Directory picking cancelled/failed' | echo 'Directory picking cancelled/failed' | ||
Line 21: | Line 21: | ||
</source> | </source> | ||
− | Now running | + | or fish |
+ | <source lang="bash"> | ||
+ | function vicd | ||
+ | set dst "$(command vifm --choose-dir - $argv[2..-1])" | ||
+ | if [ -z "$dst" ]; | ||
+ | echo 'Directory picking cancelled/failed' | ||
+ | return 1 | ||
+ | end | ||
+ | cd "$dst" | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | Now running vicd via that shell function and quiting it will change directory of | ||
shell to the directory of current active pane. Use <code>:cq[uit]</code> | shell to the directory of current active pane. Use <code>:cq[uit]</code> | ||
command to cancel directory picking. | command to cancel directory picking. |
Latest revision as of 13:55, 10 September 2022
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.
Below is an example, how one can do that with bash shell.
Since 0.8[edit]
- Add this function to
.bashrc
vicd()
{
local dst="$(command vifm --choose-dir - "$@")"
if [ -z "$dst" ]; then
echo 'Directory picking cancelled/failed'
return 1
fi
cd "$dst"
}
or fish
function vicd
set dst "$(command vifm --choose-dir - $argv[2..-1])"
if [ -z "$dst" ];
echo 'Directory picking cancelled/failed'
return 1
end
cd "$dst"
end
Now running vicd via that shell function and quiting it will change directory of
shell to the directory of current active pane. Use :cq[uit]
command to cancel directory picking.
Prior to 0.8[edit]
- 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
# "command" prevents recursive call
command vifm "$@"
if [ -f ~/.vifm/lastdir ]; then
cd `cat ~/.vifm/lastdir`
fi
}
Now running Vifm via that shell function and quiting it using :Q
command (which can be to ZZ and/or ZQ) will
change directory of shell to the directory of current active pane.