Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
+1 vote
in vifm by
edited by

CONTEXT: I am trying to use vifm as a xdg file chooser using the xdg-desktop-portal-termfilechooser library. But facing some limitations.

  • vifm --choose-files and --choose-dir always prints a newline to stdout when selection is abort/or no selection.
  • vifm --choose-files command line argument that lets user select one or multiple objects and then returns the selection. Unlike ranger, vifm doesn't have a mechanism where only one selection is valid and in case multiple objects selected, it will block and show warning. Is there any plugin or method to simulate such behavior?
  • Is there a navigation mode for normal command line operation? (afaik it only works in search mode)

1 Answer

+1 vote
by
selected by
 
Best answer

vifm --choose-files and --choose-dir always prints a newline to stdout when selection is abort/or no selection.

Thanks, but I could reproduce this only for a combination of --choose-dir and :cquit. Do you see it happening in other cases?

vifm --choose-files command line argument that lets user select one or multiple objects and then returns the selection. Unlike ranger, vifm doesn't have a mechanism where only one selection is valid and in case multiple objects selected, it will block and show warning. Is there any plugin or method to simulate such behavior?

I think this needs a new --choose-file option. Edit: I couldn't make ranger show me that dialog, it just silently saves a file under the cursor.

Is there a navigation mode for normal command line operation? (afaik it only works in search mode)

Navigation mode is a modification of search and local filter prompts. Command-line mappings implemented in Lua should be able to move cursor and change directory, although that wasn't really intended and might have issues in some corner cases.

by

I think this needs a new --choose-file option. Edit: I couldn't make ranger show me that dialog, it just silently saves a file under the cursor.

It was meant for vifm. Ranger most likely doesn't have dialog but last I checked it had a --choose-file option to select a single file. Anyway, thanks for considering this feature.

Navigation mode is a modification of search and local filter prompts. Command-line mappings implemented in Lua should be able to move cursor and change directory, although that wasn't really intended and might have issues in some corner cases.

That sounds great. Any example is appreciated.
I mostly need the hjkl motions working from commandline mode.

Also, completely unrelated but I am curious if there is a way to quit vifm printing some message to the stdout.

by

It was meant for vifm. Ranger most likely doesn't have dialog but last I checked it had a --choose-file option to select a single file. Anyway, thanks for considering this feature.

Got it. In Vifm it will be -1 because there is also --on-choose and it should also be possible to constraint it. I still need to finalize it, but already have the implementation.

I mostly need the hjkl motions working from commandline mode.

How to use this:

local added = vifm.keys.add {
    shortcut = "<a-j>",
    modes = { "cmdline" },
    description = "go up",
    handler = function()
        local c = vifm.currview().cursor
        c.pos = c.pos + 1
    end,
}
if not added then
    vifm.sb.error("Failed to register Alt-j key")
end

local added = vifm.keys.add {
    shortcut = "<a-k>",
    modes = { "cmdline" },
    description = "go down",
    handler = function()
        local c = vifm.currview().cursor
        c.pos = c.pos - 1
    end,
}
if not added then
    vifm.sb.error("Failed to register Alt-k key")
end

local added = vifm.keys.add {
    shortcut = "<a-h>",
    modes = { "cmdline" },
    description = "go to parent",
    handler = function()
        vifm.currview():cd("..")
    end,
}
if not added then
    vifm.sb.error("Failed to register Alt-h key")
end

local added = vifm.keys.add {
    shortcut = "<a-l>",
    modes = { "cmdline" },
    description = "enter directory",
    handler = function()
        local v = vifm.currview()
        local e = v:entry(v.currententry)
        if e.type == 'dir' then
            v:cd(e.name)
        end
    end,
}
if not added then
    vifm.sb.error("Failed to register Alt-l key")
end

return {}

Also, completely unrelated but I am curious if there is a way to quit vifm printing some message to the stdout.

There is, but stdout needs to be redirected. Looks like this:

vifm.events.listen {
    event = 'app.exit',
    handler = function()
        vifm.stdout():write('hello')
    end
}
by
edited by

Changes for future v0.15 release:

by
edited by

That was so fast. Thank you so much. <3

Vifm as filepicker working great.

...