Last active
July 25, 2023 14:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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