Created
August 18, 2020 18:30
-
-
Save aviflax/23b05327559c26f64d79618a5ef99872 to your computer and use it in GitHub Desktop.
Running a shell script from anywhere in a Git repo
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/sh | |
# This can be run from anywhere within the repo. | |
set -eu | |
# This is the trick | |
repo_root=$(git rev-parse --show-toplevel) | |
# Now that we have the absolute path to the repo root, we can just use it | |
# in the rest of the script -- no need to worry about relative paths, or | |
# about whether they’re relative to the user’s cwd or to the location of | |
# the script file or whatever: | |
some_path="$repo_root/some/path/to/something/from/the/root" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment