Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created April 18, 2018 17:26
Show Gist options
  • Save OdatNurd/2dd05cd2669d1b2bd4a14fc922170300 to your computer and use it in GitHub Desktop.
Save OdatNurd/2dd05cd2669d1b2bd4a14fc922170300 to your computer and use it in GitHub Desktop.
Detecting when a file is opened via rsubl in Sublime (from Stack Overflow)
import sublime
import sublime_plugin
# From the Stack Overflow Question:
# https://stackoverflow.com/questions/49897187/sublime-text-3-simple-plug-in-that-changes-color-theme-depending-on-remote-host
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
host = view.settings().get('remote_subl.host', None)
print(host)
if host == 'dsintmain':
view.settings().set(
'color_scheme',
'Packages/Color Scheme - Default/Mariana.tmTheme')
print(view.settings().get('color_scheme'))
else:
print("Not on remote_host")
class RSublOpenListener(sublime_plugin.EventListener):
def on_load_async(self, view):
if view.settings().has("remote_subl.host"):
view.run_command("example")
print("A file was just loaded from a remote place")
@OdatNurd
Copy link
Author

This is a version of the plugin from the linked SO question that shows how to detect when a file is opened from a remote host using the RemoteSubl package.

The original command has been modified slightly taking the advice of the original question answerer w/regards to removing the exception handling in favor of a default setting if the setting is not set. This allows potential code errors to show you a trace back in the console instead of being masked by the exception handling.

The addition here is the listener that detects when a file has been loaded that has the appropriate setting set to indicate that the above package opened it, which it logs to the console after running the original command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment