Skip to content

Instantly share code, notes, and snippets.

@jrob00
Last active December 20, 2015 13:59
Show Gist options
  • Save jrob00/6143229 to your computer and use it in GitHub Desktop.
Save jrob00/6143229 to your computer and use it in GitHub Desktop.
User profile extension that allows you to execute "subl" in a project's root folder and have it automatically open the project file if such a file exists. This script looks in the current directory and in a hard coded location in case that's where you store all your project files.
# sublime text alias
function project_aware_subl() {
current_directory=${PWD##*/}
result=$(ls *.sublime-project 2>/dev/null | head -n 1)
if [ -z $result ]; then
result=$(ls ~/Documents/Sublime/${current_directory}.sublime-project 2>/dev/null | head -n 1)
result=$(printf '%q' "$result")
if [[ $result == "''" ]]; then
unset result
else
echo "opening project.."
fi
else
echo "opening project.."
fi
subl ${*:-${result:-.}}
}
alias subl="project_aware_subl"
@jrob00
Copy link
Author

jrob00 commented Aug 2, 2013

This script requires that the subl sym link already exists:

sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment