I'm setting up a project template for my office that uses .command
files to encapsulate some command-line functions, since not everyone in the office is terminal-savvy. Mostly this is going to involve some path-changing within the project, and launching some compilers/watchers like compass
or grunt
.
Here's the problem I'm running into - with each project having it's own svn repo, the path to any given project root is going to be different for each user:
- Bob:
/Users/bobsmith/work/clients/client-a/project-a
- Jane:
/Users/janedoe/web/projects/project-a
I want to put .command
files inside a project that are capable of finding the project root, regardless of where the project is located within the system. Is there any way to accomplish this? Maybe by referencing the path of the .command
being executed? Here's a sample .command
that's already in place:
# Replace this path with your project directory - remember to ignore it in svn!
cd /Users/janedoe/web/projects/project-a
grunt watch
.command
is already in the project... Then you can just usecd "$(dirname "$0")"
, which will cd into the directory in which the command file is kept. Or, at least, that's the bash way to do it.