Sublime Forum

Variable for $Home Directory?

#1

Hi,

I just was wondering if there is a variable like $packages, which stores the path of the installed packages, for the “Home”-directory in ST2.

Sadly, something like this won’t work:


    { "caption": "Open TODO", "command": "open_file", "args": {"file": "${HOME}/Documents/Privat/privat.TODO"} }
or 
    { "caption": "Open TODO", "command": "open_file", "args": {"file": "~/Documents/Privat/privat.TODO"} }
]

As you can see, I want to open a specific file using the ctrl+shift+p command.

Has anybody some hints for me, how it should look like?

0 Likes

#2

You could do something like this (stackoverflow.com/questions/1599 … 1#16408331). Of course, that answer is specifically for expanding variables, so replace the for loop with something like

s = sublime.load_settings(filename) for key in setting_keys: value = s.get(key) value = os.path.expandvars(value) value = os.path.expanduser(value) s.set(key, value)

Untested, but should work.

0 Likes

#3

Hi skuroda,

first thx for your reply.

I have to admit, that I am not that familiar with this kind of coding.
Does your suggestion mean that I have to write my own plugin to get the variable which stores the path to the home-directory? :S

Just to clarify, I am syncing my settings of Sublime between MacOS and Windows, and want to open a file which is located in the users document folder. The problem of course is, that the path to this directory is different in both OS and so I can’t use my setting on both OS. Or is there a way to use different *.sublime-commands-files for different OS? :wink:

0 Likes

#4

Yes you have to write a plugin. But if you check the stackoverflow link, the plugin is already written. Just replace the contents of the for loop with what I posted before. “~” is expanded properly in both windows and os x. To demonstrate that to yourself, enter the following into the ST console.

import os
os.path.expanduser("~")

This method would require you to place the files in the same location on both machines (relative to the home directory). I don’t know if you can create a OS specific *.sublime-command file.

1 Like

Home variable in project config