Skip to content

Instantly share code, notes, and snippets.

@falsefalse
Last active July 25, 2023 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falsefalse/46fb69d672278b13042530ea5e93a8da to your computer and use it in GitHub Desktop.
Save falsefalse/46fb69d672278b13042530ea5e93a8da to your computer and use it in GitHub Desktop.
Run active file in the terminus terminal, similar to vscode "Run active file in active terminal" command
import sublime
import sublime_plugin
from os.path import relpath
class RunActiveFileInTerminusCommand(sublime_plugin.TextCommand):
def relative_path(self, filename):
return min(
(
relpath(filename, folder)
for folder in sublime.active_window().folders()
),
key=len,
)
def run(self, _):
window = self.view.window()
file_name = window.active_view().file_name()
relative_path = self.relative_path(file_name)
window.run_command(
'terminus_send_string',
{ 'string': relative_path + '\n' }
)
def is_enabled(self):
file_name = self.view.window().active_view().file_name()
return bool(file_name and len(file_name) > 0)
# [
# {
# "keys": ["ctrl+super+enter"],
# "command": "run_active_file_in_terminus",
# "context": [ { "key": "terminus_view"} ]
# }
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment