Sublime Forum

Add a Folder to Sidebar via API?

#1

Is it possible to add a folder to the sidebar from a plugin? If I pass a folder to the open_file command, will it open in the sidebar?

Thanks.

0 Likes

API Requests
#2

+1, it would be really useful for some plugins

0 Likes

#3

+1, I would like this too :smile:

0 Likes

#4

I just spent a few minutes digging through the Default package looking for a solution to this. I would also approve of such a feature! :smile:

Alternatively a way to open a folder without a prompt, or opening a project without a prompt would work also.

0 Likes

#5

You can kind of cheat by running this system command. This is how I always do it, i just keep a terminal open and add stuff through that.

/path/to/sublime_text.exe -a /path/to/file_or_folder
0 Likes

#6

[quote=“impeached”]You can kind of cheat by running this system command. This is how I always do it, i just keep a terminal open and add stuff through that.

/path/to/sublime_text.exe -a /path/to/file_or_folder

I was going to attempt this, however with the limited amount of time I spent on it, I could not think of a good way to programatically determine the path to the command line program. Perhaps I am overlooking a simple solution?

0 Likes

#7

[pre=#0C1021]>>> import sys

sys.executable
‘C:\Program Files\Sublime Text 2\sublime_text.exe’[/pre]

0 Likes

#8

Though, now I think about it, iirc that won’t work on OSX as you’ll get the system python executable.

0 Likes

#9

[pre=#0C1021]>>> open(’/proc/self/cmdline’).read().split(chr(0))0]
‘/usr/lib/sublime-text-2/sublime_text’[/pre]
For *nix ( not osx it seems)

0 Likes

#10

I think sys.executable may be good enough since OS X users are unlikely to install Sublime in a non-standard location, whereas Linux users have no standard and Windows users could be using the portable installation.

So, I think the best solution (until we get an API method) is:

import sublime
import sys
import subprocess

def get_sublime_path():
    if sublime.platform() == 'osx':
        return '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'
    if sublime.platform() == 'linux':
        return open('/proc/self/cmdline').read().split(chr(0))[0]
    return sys.executable

def sublime_command_line(args):
    args.insert(0, get_sublime_path())
    return subprocess.Popen(args)

Usage for adding a folder to the sidebar would be:

sublime_command_line('-a', '/path/to/folder'])
0 Likes

#11

sys.executable didn’t work on linux on my ubuntu 10.04 vm at least

it just returned an empty string

0 Likes

#12

[quote=“castles_made_of_sand”]sys.executable didn’t work on linux on my ubuntu 10.04 vm at least

it just returned an empty string[/quote]

I was wondering why you had talked about reading /proc for Linux. :smile: It worked for me, but clearly it is not consistent across different distros.

0 Likes

#13

Odd eh? Apparently /proc is only on linux. There’s no real equivalent on OSX. Not even a generic *nix thing. I’m a windows loser. Don’t really know shit about osx and only a little of linux.

Might be some ctypes hack for OSX? Jon would know. For that 1 guy who walked under a ladder taking his black cat to the vet after installing to a non default location. Actually, fuck that guy, he brought it on himself!

0 Likes