Last active
August 3, 2020 14:05
-
-
Save coldnebo/035cfaa4fb5a5b784a6d3eaa2f22e2b3 to your computer and use it in GitHub Desktop.
modification of Sublime Text 3 /usr/bin/subl script to auto-open implict project directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
have_project=false | |
implicit_project_file=false | |
for arg in $@; do | |
if [ $arg = "--project" ]; then | |
have_project=true | |
break | |
fi | |
done | |
# if a project argument doesn't already exist, then check for an implicit project | |
if [ $have_project != true ]; then | |
for directory in $@; do | |
# if the arguments have directories | |
if [ -d $directory ]; then | |
# try to find an existing sublime-project file | |
for project in $directory/*.sublime-project; do | |
if [ -f "$project" ]; then | |
implicit_project_file="$project" | |
break | |
fi | |
done | |
fi | |
done | |
fi | |
if [ "$implicit_project_file" = false ]; then | |
# execute the original command | |
exec /opt/sublime_text/sublime_text --fwdargv0 "$0" "$@" | |
else | |
# execute the alternative open project form | |
exec /opt/sublime_text/sublime_text --fwdargv0 "$0" --project "$implicit_project_file" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I spend most of my time in the shell and with a lot of separate project directories. My preferred way to startup sublime is:
This let's me run other commands from the shell while working on code. The directory may contain a project file, e.g.
project.sublime-project
, checked into source control. Sublime Projects are a great way to capture project settings and folder exclusions for efficient "Find in Files" that remain targeted on actual source files and ignore various generated artifacts.It turns out the name of the project file has some quirks.
P1: Sublime's UI does not like unnamed projects, i.e.
.sublime-project
, presumably because the UI has no way to distinguish an empty name in the "Switch Project" dialog. So, I name the project fileproject.sublime-project
.However, because of the environment I work in (a mix of perforce and git), I often need to checkout feature branches into separate directories. This means there can be more than one
project.sublime-project
in different directories.P2: Sublime's UI is not great at differentiating the same project name in multiple directories. This makes it difficult to select the proper project from the UI.
P3: Coordinating project location between the shell and the workspace manually using the UI is tedious the more projects you work with. Opening the project from the command line is preferable.
P4: But, the long form
subl --project project.sublime-project
is also tedious the more projects you work with. I'm already typing enough information with changing directories. I would prefer Sublime to automatically open implicit projects when passed a directory such assubl .
that contains a*.sublime-project
file. This way, I can be sure that my shell and Sublime are pointing at the same files and I'm not making a bunch of edits in another project.The above modification to the default /usr/bin/subl script improves the usability of Sublime projects for my personal tastes by addressing the pain points (P1..P4) listed above. There are some similar feature requests in the Sublime issue tracker, so perhaps new features will address these points in the future.