Create a gist now

Instantly share code, notes, and snippets.

Embed
Add folder that contains current file to sidebar, for Sublime Text. Goes well with Cmd+.,Cmd+O of GoSublime until https://github.com/DisposaBoy/GoSublime/issues/553 is resolved.

File paths for Sublime Text 3 on OS X:

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

Credit to https://www.sublimetext.com/forum/viewtopic.php?f=6&t=13021 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:
return
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")
#else:
# sublime.message_dialog("false")
data = sublime.active_window().project_data()
if data:
for folder in data['folders']:
if folder['path'] == path:
return
data['folders'].append({'follow_symlinks': True, 'path': path})
else:
data = {'folders': [{'follow_symlinks': True, 'path': path}]}
sublime.active_window().set_project_data(data)
[
// ... (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