Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add folder that contains current file to sidebar, for Sublime Text. Goes well with Cmd+.,Cmd+O of GoSublime until is resolved.

File paths for Sublime Text 3 on OS X:

  • ~/Library/Application Support/Sublime Text 3/Packages/User/
  • ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap

Credit to for relevant resources I used to put this together.

import sublime
import sublime_plugin
import os.path
# Add folder that contains current file to sidebar.
class AddToProjectCommand(sublime_plugin.WindowCommand):
def run(self):
path = sublime.active_window().active_view().file_name()
if path == None:
path = os.path.dirname(path)
# TODO: Try to see if it's possible to preserve expanded folders when adding a new folder.
#wat = sublime.active_window().active_view().settings().has("expanded_folders")
#if wat:
# sublime.message_dialog("true")
# sublime.message_dialog("false")
data = sublime.active_window().project_data()
if data:
for folder in data['folders']:
if folder['path'] == path:
data['folders'].append({'follow_symlinks': True, 'path': path})
data = {'folders': [{'follow_symlinks': True, 'path': path}]}
// ... (existing content)
// Add folder that contains current file to sidebar.
{ "keys": ["f3"], "command": "add_to_project" },
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.