
0 votes
in vifm by

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

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


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.


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?


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.