【发布时间】:2018-04-18 10:18:57
【问题描述】:
设置:我使用 Sublime Text 3 (ST),并且我经常使用 RemoteSubl 在不同的远程工作区中打开 2-3 个不同的 Sublime + iTerm2 会话。
使用简单的批处理脚本,我已将 iTerm2 设置为在我 ssh 进入不同的主机时更改颜色(通过激活不同的 iTerm 用户)。
我想知道 RemoteSubl 是否也可以这样做?这样当我从特定的主机/IP/端口打开某些东西时,Sublime 会以不同的配色方案打开,具体取决于主机/IP/端口。
解决方案尝试:到目前为止,这是我尝试构建一个在主机为remote_host 时更改配色方案的小插件。
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, view):
try:
host = view.settings().get('remote_subl.host')
print(host)
if host == 'remote_host':
view.settings().set(
'color_scheme',
'Packages/Color Scheme - Default/Mariana.tmTheme')
print(view.settings().get('color_scheme'))
except:
print("Not on remote_host")
pass
问题:在控制台中使用 view.settings().get('remote_subl.host') 时,它工作正常,并返回 remote_host。但是,当运行脚本view.run_command('example') 时,我得到“不在 remote_host”打印,表明 try 循环由于某种原因而失败。
根据 Keiths 的建议:
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, view):
view = self.view
host = view.settings().get('remote_subl.host', None)
print(host)
if host:
view.settings().set(
'color_scheme',
'Packages/Color Scheme - Default/Mariana.tmTheme')
print(view.settings().get('color_scheme'))
if host is None:
view.settings().set(
'color_scheme',
'Packages/Color Scheme - Default/Monokai.tmTheme')
print(view.settings().get('color_scheme'))
【问题讨论】:
标签: python python-3.x sublimetext3 sublime-text-plugin