1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 13:50:09 +00:00

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

* Adding an alias to open up the sublime project

* README update for stp command
This commit is contained in:
Peter Han 2016-08-14 18:00:19 -07:00 committed by Robby Russell
parent 95371afdd8
commit 073ea01cce
2 changed files with 33 additions and 2 deletions

View file

@ -17,3 +17,5 @@ Plugin for Sublime Text, a cross platform text and code editor, available for Li
* If `stt` command is called, it is equivalent to `st .`, opening the current folder 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. * 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.

View file

@ -56,3 +56,32 @@ elif [[ "$OSTYPE" = 'cygwin' ]]; then
fi fi
alias stt='st .' 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