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.
0 votes
in vifm by

I open files like this:

filextype *.pdf firefox %c 2>/dev/null &

It works perfectly. I want to print a message 'opened in firefox', how to execute :echo after :filextype execution?

1 Answer

0 votes
by
 
Best answer

There is no easy way, :filextype defines external handler and doesn't process builtin commands.

Lua handler can be used to start a command and print message. If you create $VIFM/plugins/report/init.lua:

--[[

    filextype {*.pdf} #report#run firefox %c

--]]

local M = {}

local function run(info)
    local view = vifm.currview()
    local _, cmd = string.match(info.command, "^(%S+)%s*(.*)$")
    cmd = vifm.expand(cmd)

    vifm.startjob { cmd = cmd }
    vifm.sb.info(string.format("Started `%s`", string.match(cmd, "%S+")))
end

local added = vifm.addhandler {
    name = "run",
    handler = run,
}
if not added then
    vifm.sb.error(string.format("Failed to register #%s#run", vifm.plugin.name))
end

return M

Then adding

filextype {*.pdf} #report#run firefox %c

to your vifmrc should give what you expect.


You can also call back into Vifm (I used %i instead of 2>/dev/null &):

let $VIFM_SERVER_NAME = v:servername

filextype *.pdf firefox %i && vifm --server-name "$VIFM_SERVER_NAME" --remote +"echo 'opened in firefox'"

But the message doesn't remain on the screen, which might be a bug.

by
edited

Thank you. The first solution is pretty straightforward but requires writing a plugin. I thought there was a way to avoid using plugins.

...