Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by

The wiki suggests using a shell function to allow for using vifm to change directories.

However, the function given there runs vifm in a subshell -
local dst="$(command vifm --choose-dir - "$@")"
Because of which it cannot be suspended and resumed with Ctrl-Z

Suspending and resuming is crucial to my workflow - often I end up opening and working on a file in vifm, and then I need to suspend the editor to run something in the terminal. I'm probably not the only person who does this, either.

I've tried to write my own script -

vicd () {
    # Write output of --choose-dir
    # to a temporary file; then set
    # _dst using that file.

    # clean up temporary files on unexpected exit
    trap 'rm -f "$_tmp"' EXIT TERM INT HUP
    local _tmp="$(mktemp)"
    command vifm --choose-dir - "$@" > "$_tmp"
    local _dst=$(cat "$_tmp")
    rm "$_tmp"

    if [ -z "$_dst" ]; then
        echo "Directory picking cancelled/failed"
        return 1
    cd "$_dst"

And I am able to suspend vifm this way - but after suspending, the directory is not changed. The directory only changes if vifm has not been suspended.

Does anyone have any ideas? I'm pretty stumped here.

1 Answer

0 votes

Couple changes you could do:

  • local variable might not be available trap
  • specify --choose-dir "$_tmp" instead of using redirection

after suspending, the directory is not changed

After Ctrt+Z the execution of the function continues, it doesn't suspend the function halfway. So when you resume the process and end it, no more code will run (and the output file is gone). Not sure if there is a way to overcome this.