I want to have a simple sublime-command to open a specific (dot config) file in my home folder. Is there a variable or other magic I can use like ${packages}, but for the user's home folder?
Currently I have (Default.sublime-commands)
{
"caption": "Edit my config",
"command": "open_file",
"args": {
"file": "/Users/MyName/.myconfig"
}
}
but want to get rid of the hard coded user name.
Unfortunately I can't find anything in the api "documentation" of sublime.
It can be done using custom command like this:
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)
and the following (Default.sublime-commands):
{
"caption": "Edit my config",
"command": "open_custom_file",
"args": { "file_name": "/Users/{username}/.myconfig" }
}
And of course you can extend OpenCustomFileCommand with your own replacements.
P.S. Command must be stored within Packages directory of ST2, i.e. in file open_custom_file.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With