Last active
October 26, 2017 13:56
-
-
Save redoPop/00558e9d82bdb1476d3ae66a545f32dc to your computer and use it in GitHub Desktop.
Bash script to generate and open Sublime Text Projects.
This file contains hidden or 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/bash | |
# Bash script to generate and open Sublime Text Projects | |
# | |
# If the current directory is part of a git repo, this script will | |
# look for a .sublime-project file in that repo root and open it. | |
# If no such file exists, it'll generate one based on the dir name. | |
# | |
# If the current directory is _not_ a git repo, no .sublime-project | |
# will be generated and if none is found in the current directory then | |
# Sublime will simply open the directory itself. | |
# If this is a git repo… | |
if [ `git rev-parse --is-inside-work-tree 2>/dev/null` ]; then | |
git_dir=`git rev-parse --absolute-git-dir` | |
project_dir=`dirname $git_dir` | |
# Test to see if a ST Project already exists for this repo | |
if [ -f $project_dir/*.sublime-project ]; then | |
# Obtain the name of the existing Project file | |
project_file=`ls -1 $project_dir/*.sublime-project | head -n 1` | |
else | |
# Create a new Project file | |
project_name=`basename $project_dir` | |
project_file="$project_dir/$project_name.sublime-project" | |
echo "{\"folders\":[{\"path\": \".\"}]}" >> $project_file | |
fi | |
# Open the found or generated Project | |
subl --project "$project_file" | |
else | |
# Open any Project file that exists in this dir, else the dir itself | |
if [ -f *.sublime-project ]; then | |
subl `ls -1 *.sublime-project | head -n 1` | |
else | |
subl . | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment