Last Updated: February 25, 2016
·
688
· destructuring

Getting the root of your project

It's useful to get the root of your project, so you can fully qualify paths to scripts, config files and not worry about the current directory.

In bash, I define shome to be (assuming the script is in a subdirectory). I got this from a script in ronn.

shome="$(cd -P -- "$(dirname -- "$0")/.." && pwd -P)"

In ruby:

shome=File.dirname(File.expand_path(__FILE__))