Skip to content

Instantly share code, notes, and snippets.

@gustaflindqvist
Forked from digitaljhelms/gist:3014302
Created December 3, 2012 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustaflindqvist/4195333 to your computer and use it in GitHub Desktop.
Save gustaflindqvist/4195333 to your computer and use it in GitHub Desktop.
Sublime Text 2 bash alias & CLI function to open projects without using the `.sublime-project` file extension
# bash alias
alias subl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
# bash function, usage: $ st -p [projectname] -opt2 -opt3
function st() {
if [ -n "$1" -a -n "$2" ]; then # if more than one argument
if [ "$1" = "-p" -o "$1" = "--project" ]; then # if arg1 is -p or --project
local projectfile="$2"
[[ $projectfile != *.sublime-project ]] && projectfile="$2.sublime-project" # detect if arg2 already includes the ext
if [ -e $projectfile ]; then # does project file exist?
subl -n --project $projectfile ${*:3} # open project file, in new window, include trailing args
#echo "project specified, and project file exists, execute: subl -n --project $projectfile ${*:3}"
else
subl ${*:3} # open sublime but drop -p||--project and project name from args
#echo "project specified, but project file doesn't exist, execute: subl ${*:3}"
fi
else
subl $* # open sublime and pass args as usual
#echo "project argument not passed, execute: subl $*"
fi
else
subl $* # open sublime and pass args as usual
#echo "only 1 argument passed, execute: subl $*"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment