6 # Define sst only if sudo exists
7 (( $+commands[sudo] )) && alias sst='sudo subl'
10 alias stn=create_project
13 # Search for the Sublime Text command if not found
14 (( $+commands[subl] )) || {
15 declare -a _sublime_paths
17 if [[ "$OSTYPE" == linux* ]]; then
18 if [[ "$(uname -r)" = *icrosoft* ]]; then
20 "$(wslpath -u 'C:\Program Files\Sublime Text\sublime_text.exe' 2>/dev/null)"
21 "$(wslpath -u 'C:\Program Files\Sublime Text 3\subl.exe' 2>/dev/null)"
22 "$(wslpath -u 'C:\Program Files\Sublime Text 2\subl.exe' 2>/dev/null)"
26 "$HOME/bin/sublime_text"
27 "/opt/sublime_text/sublime_text"
28 "/opt/sublime_text_3/sublime_text"
29 "/usr/bin/sublime_text"
30 "/usr/local/bin/sublime_text"
34 "/snap/bin/sublime-text.subl"
37 elif [[ "$OSTYPE" = darwin* ]]; then
40 "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
41 "/Applications/Sublime Text 4.app/Contents/SharedSupport/bin/subl"
42 "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
43 "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
44 "$HOME/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
45 "$HOME/Applications/Sublime Text 4.app/Contents/SharedSupport/bin/subl"
46 "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
47 "$HOME/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
49 elif [[ "$OSTYPE" = cygwin ]]; then
51 "$(cygpath "$ProgramW6432/Sublime Text 2")/subl.exe"
52 "$(cygpath "$ProgramW6432/Sublime Text 3")/subl.exe"
54 elif [[ "$OSTYPE" = msys ]]; then
56 "/c/Program Files/Sublime Text/sublime_text.exe"
57 "/c/Program Files/Sublime Text 2/subl.exe"
58 "/c/Program Files/Sublime Text 3/subl.exe"
62 for _sublime_path in $_sublime_paths; do
63 if [[ -a $_sublime_path ]]; then
64 alias subl="'$_sublime_path'"
65 (( $+commands[sudo] )) && alias sst="sudo '$_sublime_path'"
70 unset _sublime_paths _sublime_path
73 function find_project() {
74 local PROJECT_ROOT="${PWD}"
77 while [[ $PROJECT_ROOT != "/" && ! -d "$PROJECT_ROOT/.git" ]]; do
78 PROJECT_ROOT=$(dirname $PROJECT_ROOT)
81 if [[ $PROJECT_ROOT != "/" ]]; then
82 local PROJECT_NAME="${PROJECT_ROOT##*/}"
84 local SUBL_DIR=$PROJECT_ROOT
85 while [[ $SUBL_DIR != "/" && ! -f "$SUBL_DIR/$PROJECT_NAME.sublime-project" ]]; do
86 SUBL_DIR=$(dirname $SUBL_DIR)
89 if [[ $SUBL_DIR != "/" ]]; then
90 FINAL_DEST="$SUBL_DIR/$PROJECT_NAME.sublime-project"
92 FINAL_DEST=$PROJECT_ROOT
99 function create_project() {
102 if [[ "${_target}" == "" ]]; then
104 elif [[ ! -d ${_target} ]]; then
105 echo "${_target} is not a valid directory"
109 local _sublime_project_file=$_target/$(basename $_target).sublime-project
111 if [[ ! -f $_sublime_project_file ]]; then
112 touch $_sublime_project_file
114 echo -e "{" >> $_sublime_project_file
115 echo -e "\t\"folders\":" >> $_sublime_project_file
116 echo -e "\t\t[{" >> $_sublime_project_file
117 echo -e "\t\t\t\"path\": \".\"," >> $_sublime_project_file
118 echo -e "\t\t\t\"file_exclude_patterns\": []" >> $_sublime_project_file
119 echo -e "\t\t}]" >> $_sublime_project_file
120 echo -e "}" >> $_sublime_project_file
122 echo -e "New Sublime Text project created:\n\t${_sublime_project_file}"