Created
March 21, 2014 02:36
-
-
Save astronaughts/9678368 to your computer and use it in GitHub Desktop.
Get active project root path in Sublime Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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