Skip to content

Instantly share code, notes, and snippets.

@astronaughts
Created March 21, 2014 02:36
Show Gist options
  • Save astronaughts/9678368 to your computer and use it in GitHub Desktop.
Save astronaughts/9678368 to your computer and use it in GitHub Desktop.
Get active project root path in Sublime Text
def get_active_project_path():
import os
window = sublime.active_window()
folders = window.folders()
if len(folders) == 1:
return folders[0]
else:
active_view = window.active_view()
active_file_name = active_view.file_name() if active_view else None
if not active_file_name:
return folders[0] if len(folders) else os.path.expanduser("~")
for folder in folders:
if active_file_name.startswith(folder):
return folder
return os.path.dirname(active_file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment