Commit 073ea01c authored by Peter Han's avatar Peter Han Committed by Robby Russell
Browse files

Create an alias to open up sublime project (#5258)

* Adding an alias to open up the sublime project

* README update for stp command
parent 95371afd
......@@ -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.
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment