Home Download Buy Blog Forum Support

Storing User Settings Elsewhere

Storing User Settings Elsewhere

Postby ashb on Mon Aug 15, 2011 8:13 pm

Is it possible to change the user settings directory to be somewhere other than the default location?

I like to keep my settings checked into git (mainly so that I can easily work/migrate between machines) and would love to be able to have ST2 settings be loaded from ~/etc/sublime2/... or similar.

I suspect the answer is its not possible right now :(
ashb
 
Posts: 8
Joined: Thu Jun 02, 2011 9:29 pm

Re: Storing User Settings Elsewhere

Postby iamntz on Mon Aug 15, 2011 8:53 pm

I guess you can just make a symlink or something similar?
iamntz
 
Posts: 915
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Storing User Settings Elsewhere

Postby SeanWcom on Tue Aug 16, 2011 1:06 am

I did a funky setup. I installed ST2 then put the portable version in my Dropbox. Then I deleted the contents of my Program Files\ST2 directory and linked the portable version to that folder (directory junction I think it's called in Windows). This gives me my context menu entry on right click but allows me to sync my settings with dropbox. If I wanted to, I could turn that folder into a git repo. I then did the same steps at the office... voila, synced settings. Even synced tabs which is awesome... and even more awesome is syncing unsaved tabs. I can create a new text document, put some text in there, drive to work and have that tab waiting for me. Pretty cool! :)

One thing I was hoping to be able to do was to create a machine specific config file. At work I use the light Soda theme since I have crazy glaring lights and the dark themes are just too much contrast. At home I switch back to the dark theme. It's easy to change, but if I could setup a machine_name_01.sublime-settings for each desktop, I'd be in heaven! :)
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia

Re: Storing User Settings Elsewhere

Postby coarsesand on Tue Aug 16, 2011 2:26 am

Hey, thought your problem was kind of interesting because I work on three different machines during the day (Mac OS X at work, Windows & Ubuntu at home.) I just keep my packages directory synced across them all using Dropbox and some symlinks.

Anyways, this should do what you want.

Code: Select all
import sublime, sublime_plugin
import platform

class SodaThemeColorByHostCommand(sublime_plugin.WindowCommand):
   dark_theme = 'Soda Dark.sublime-theme'
   light_theme = 'Soda Light.sublime-theme'

   dark_machines = ['']
   light_machines = ['']

   def run(self):
      s = sublime.load_settings('Global.sublime-settings')
      hostname = platform.node()
      if hostname in self.light_machines:
         s.set('theme', self.light_theme)
      elif hostname in self.dark_machines:
         s.set('theme', self.dark_theme)
      sublime.save_settings('Global.sublime-settings')

sublime.active_window().run_command('soda_theme_color_by_host')


You should just be able to throw that into your Packages in a python file (I have it as 'sodacolor.py') and fill in the hostnames of the machines you want to be dark/light.
coarsesand
 
Posts: 5
Joined: Tue Aug 16, 2011 2:12 am

Re: Storing User Settings Elsewhere

Postby SeanWcom on Wed Aug 17, 2011 1:11 am

Awesome, thanks for the code! It looks like it should work perfectly, but I'm getting an error... unfortunately, I'm a complete Python noob, so I'm not sure if this is a Sublime thing or a Python thing... here's the error:

Code: Select all
Reloading plugin D:\MyStuff\Dropbox\Software\Sublime Text 2\Data\Packages\sodacolor.py
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 57, in reload_plugin
  File ".\sodacolor.py", line 20, in <module>
    sublime.active_window().run_command('soda_theme_color_by_host')
AttributeError: 'NoneType' object has no attribute 'run_command'

Also note that I'm running build 2101. I'm hoping this error doesn't stem from the fact that I'm keeping the app in my Dropbox folder. Any ideas?

Thanks a bunch!
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia

Re: Storing User Settings Elsewhere

Postby coarsesand on Thu Aug 18, 2011 4:49 am

Nope, nothing to do with you keeping your installation in Dropbox. Unfortunately when sodacolor.py is sourced, there are no windows, so that's why you see "'NoneType' object has no attribute 'run_command'." I'm working on a complete overhaul of this, and while there doesn't seem to be a way to get it to run on start up, you should at least be able to hit a single key binding and get the theme you wanted.
coarsesand
 
Posts: 5
Joined: Tue Aug 16, 2011 2:12 am

Re: Storing User Settings Elsewhere

Postby coarsesand on Thu Aug 18, 2011 7:14 am

Yup, "working on something" became "keeping me up way too late." Here's what you need Sean:
http://www.sublimetext.com/forum/viewtopic.php?f=5&t=2765&p=12852

Follow my instructions in there, then you'll want something like:

Code: Select all
{
   "machine1": {
      "defined": {
         "global": ["theme"]
      },
      "theme": "Soda Dark.sublime-theme",
   },
   "machine2": {
      "defined": {
         "global": ["theme"]
      },
      "theme": "Soda Light.sublime-theme",
   }
}

in User/Hosts.sublime-settings, with the machine names set to whatever you use. Ctrl+Shift+H when you start using Sublime and you should be good to go.
coarsesand
 
Posts: 5
Joined: Tue Aug 16, 2011 2:12 am

Re: Storing User Settings Elsewhere

Postby SeanWcom on Thu Aug 18, 2011 12:33 pm

Haha, thanks for staying up late. Funny how time flies when you're working on something fun. :)

Thanks for the help, this works perfectly!
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 14 guests