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
edited by

I have been using the bg plugin to open videos in media player in background. However I have seen the ueberzug plugin which creates a file handler for fileviewer. My goal is to create a handler with the bg plugin so that i can run it like this

filextype <video/*> #Bg#run mpv %f

I know '&' is also an option to spawn the player separate, but I just want to know if the previous is possible. here is my current bg plugin

--[[

Provides :Bg command that runs external command in background displaying it on
job bar until its done.

Expands %-macros and $-environment variables.

Usage example:

:Bg sleep 10

--]]

local function bg(info)
   local cmd = vifm.expand(info.args)
   vifm.startjob {
      cmd = cmd,
      description = cmd,
      visible = true
   }
end

-- this does NOT overwrite pre-existing user command
local added = vifm.cmds.add {
   name = "Bg",
   description = "run an external command in background",
   handler = bg,
   minargs = 1,
   maxargs = -1,
}

if not added then
   vifm.sb.error("Failed to register :Bg")
end

added = vifm.addhandler {
   name = "run",
   handler = bg,
}

if not added then
   vifm.sb.error("Failed to register bg#run")
end


return {}

and in my vifmrc

filextype <video/*> #Bg#run mpv %f

but it doesn't work for some reason.

Thanks always for your great work.

Also I have managed to modify the unpack plugin to ask password for encrypted zip files.
https://0x0.st/HWbb.txt

Hope I can be of help.

1 Answer

+1 vote
by
selected by
 
Best answer

filextype <video/*> #Bg#run mpv %f

Did you derive Bg from command name? The prefix comes from plugin name which is taken from the directory in which the plugin resides, which is likely bg. So the handler is accessed by the name of #bg#run.

Also I have managed to modify the unpack plugin to accept filenames with spaces and allow .tgz, .tbz like files. Also implemented a way to ask password for encrypted zip files.

Thanks, I'll apply your changes.

by

Not working even with #bg#run. I tried in a fresh vifmrc but no luck.
It does show up in the handler menu when I type command :file but it doesn't run anything.

Does it work on your system?

by

If it has [present] marker in the menu, then it's recognized as a handler.

It probably doesn't work because of info.args. Handler's parameters are dictated by the context in which it's called. Try using info.args or info.command to account for :command and :filetype handler cases.

See :help vifm-lua-handlers for more details.

by
edited by

Sorry, for the late reply but I tried it with info.command but still not working.
By the way i was testing the unpack plugin and it didn't work. The modified version correctly expands filenames with space, at least on my machine. https://0x0.st/HWt1.txt

by

Sorry, looks like I confused notification e-mails and didn't see your reply. I forgot that info.command includes handler name, so it needs to be cut off:

-- "#bg#run " is 8 chars, but Lua offsets are base 1
local cmd = vifm.expand(info.args or info.command:sub(9))
by

Its working. Thanks <3

...