我想有一个简单的sublime命令来打开我的主文件夹中的特定(点配置)文件.我可以像$ {packages}一样使用变量或其他魔法,但对于用户的主文件夹?
目前我有(Default.sublime-commands)
{
"caption": "Edit my config",
"command": "open_file",
"args": {
"file": "/Users/MyName/.myconfig"
}
}
Run Code Online (Sandbox Code Playgroud)
但想要摆脱硬编码的用户名.
不幸的是我在sublime的api"文档"中找不到任何东西.
可以使用自定义命令来完成,如下所示:
import sublime_plugin, getpass
class OpenCustomFileCommand(sublime_plugin.WindowCommand):
def run(self, file_name):
if("{username}" in file_name):
file_name = file_name.replace("{username}", getpass.getuser())
self.window.open_file(file_name)
Run Code Online (Sandbox Code Playgroud)
以及以下内容(Default.sublime-commands):
{
"caption": "Edit my config",
"command": "open_custom_file",
"args": { "file_name": "/Users/{username}/.myconfig" }
}
Run Code Online (Sandbox Code Playgroud)
当然,您可以使用自己的替换来扩展OpenCustomFileCommand。
PS 命令必须存储在 ST2 的 Packages 目录中,即文件open_custom_file.py中
归档时间: |
|
查看次数: |
595 次 |
最近记录: |