Indeed, according to the unofficial (while very good) documentations, the command palette is handled at a low level in the application, which may explains why $packages
in the only available variable:
Command Palette (docs.sublimetext.info)
As near to all the custom commands I used in any editor are implemented as external commands getting either a file name as an argument or reading text from standard-input, I needed to be able to get the same in Sublime Text. For people with the same need, here is how to do this in Sublime Text 3 ; here, for external command expecting the active file name as an argument, via a simple plug-in:
Plugin /…/Packages/User/external_command.py
:
""" Run an external command on the current file.
Usage: run command `external_command` and giving it the executable name as the
`executable` argument. The external command with be invoked with the current
file path and name, as its first and single argument.
"""
import sublime_plugin
class ExternalCommandCommand(sublime_plugin.WindowCommand):
def run(self, executable):
variables = self.window.extract_variables()
if "file" in variables:
file = variables"file"]
self.window.run_command("exec", {"cmd": [executable, file]})
else:
sublime.status_message("Error: no file")
def description(self):
return (
"Run an external command with the current file path and name as "
"a single argument.")
def description(self):
return (
"Run an external command "
"with the current file path "
"and name as a single argument.")
Example /…/Packages/User/MyCommands.sublime-commands
making use of it:
{
"caption": "Markdown: Preview",
"command": "external_command",
"args": { "executable": "multimarkdown-preview" }
}
]
References used:
Now Ctrl+Shift+P the “Markdown preview” then Enter, works as expected.
This simple plug-in will allow me to integrate all of my external command I used with another editor, into Sublime Text 3.