-->

Custom command for Eclipse on current file

2019-01-22 22:00发布

问题:

I would like to enhance Eclipse so that when I press a custom key combo--say Ctrl + Shift + E--then it will run a command on the current file (if my current buffer is foo.c then it will run `mycommand foo.c' in foo.c's directory).

回答1:

Open the External Tools Configuration dialog from the Run menu. Create a new configuration with the following settings.

Location: c:\mycommand.exe (alter to your needs)

Working directory: ${container_loc}

Arguments: ${resource_loc}

Under Prefrences->General->Keys you can setup a shortcut for "Run last launched external tool".

This should solve your problem.



回答2:

Also, make sure that your "resource" (foo.c) is selected. It happened to me that when testing the external tool and horizontally scrolling the output pane, the resource gets deselected. When you run the external tool again after probably having made changes to its configuration, Eclipse will pop up an error box about "empty variable" (e.g. ${resource_loc} ).