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.

Specify command run when item clicked in custom menu

0 votes
asked Dec 26, 2018 in vifm by anonymous

Is it possible to specify the command that is run when an item is clicked in a custom menu?

I wanted to create a menu that list all of the processes (windows 10) using the tasklist command and to have the kill command run if I clicked one of the processes.

Below is what I was using to display the menu.

command! tasklist tasklist %m

1 Answer

0 votes
answered Dec 26, 2018 by xaizek

There is no way to do that at the moment. But there is a c key which brings current line into command-line, which can be somewhat abused here. For example, if you make a menu using

:!ps%m

the following K menu mapping will print process id from current line on status line:

:mnoremap K c<c-a><c-d>echo <c-e> | cut -f1 -d' ')"<c-a>!echo %S "$(<cr>

Right-hand side here is pretty much a sequence of command-line editing keys that add some prefix and suffix to the line.

This form might be more readable:

command printpid echo %S "$(echo %a | cut -f1 -d' ')"
mnoremap K c<c-a><c-d>printpid <cr>

Selected line will be substituted where %a is in the first line.

commented Dec 28, 2018 by anonymous

thanks! that worked.

this seems to work for windows, guessing it can be cleaned up a bit.

:mnoremap K c<c-a><c-d>killpid <cr>
:command! killpid for /f "tokens=2" %%7 in ('echo "%a"') do taskkill /pid:%%7 /f %S

Is there any way to do multi select in the Menu?

commented Dec 28, 2018 by xaizek

Is there any way to do multi select in the Menu?

No, the menu wasn't made for general purpose item selection, so corresponding means are lacking.

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...