summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/sublime/README.md6
-rw-r--r--plugins/sublime/sublime.plugin.zsh29
2 files changed, 33 insertions, 2 deletions
diff --git a/plugins/sublime/README.md b/plugins/sublime/README.md
index e1e666f05..7b02d8428 100644
--- a/plugins/sublime/README.md
+++ b/plugins/sublime/README.md
@@ -15,5 +15,7 @@ Plugin for Sublime Text, a cross platform text and code editor, available for Li
* If `st` is passed a file, open it in Sublime Text
* If `stt` command is called, it is equivalent to `st .`, opening the current folder in Sublime Text
-
- * If `sst` command is called, it is like `sudo st`, opening the file or folder in Sublime Text. Useful for editing system protected files. \ No newline at end of file
+
+ * If `sst` command is called, it is like `sudo st`, opening the file or folder in Sublime Text. Useful for editing system protected files.
+
+ * If `stp` command is called, it find a `.sublime-project` file by traversing up the directory structure. If there is no `.sublime-project` file, but if the current folder is a Git repo, opens up the root directory of the repo. If the current folder is not a Git repo, then opens up the current directory.
diff --git a/plugins/sublime/sublime.plugin.zsh b/plugins/sublime/sublime.plugin.zsh
index a5d63cde6..75a39eab1 100644
--- a/plugins/sublime/sublime.plugin.zsh
+++ b/plugins/sublime/sublime.plugin.zsh
@@ -56,3 +56,32 @@ elif [[ "$OSTYPE" = 'cygwin' ]]; then
fi
alias stt='st .'
+
+find_project()
+{
+ local PROJECT_ROOT="${PWD}"
+ local FINAL_DEST="."
+
+ while [[ $PROJECT_ROOT != "/" && ! -d "$PROJECT_ROOT/.git" ]]; do
+ PROJECT_ROOT=$(dirname $PROJECT_ROOT)
+ done
+
+ if [[ $PROJECT_ROOT != "/" ]]; then
+ local PROJECT_NAME="${PROJECT_ROOT##*/}"
+
+ local SUBL_DIR=$PROJECT_ROOT
+ while [[ $SUBL_DIR != "/" && ! -f "$SUBL_DIR/$PROJECT_NAME.sublime-project" ]]; do
+ SUBL_DIR=$(dirname $SUBL_DIR)
+ done
+
+ if [[ $SUBL_DIR != "/" ]]; then
+ FINAL_DEST="$SUBL_DIR/$PROJECT_NAME.sublime-project"
+ else
+ FINAL_DEST=$PROJECT_ROOT
+ fi
+ fi
+
+ st $FINAL_DEST
+}
+
+alias stp=find_project