Created
March 9, 2020 10:48
-
-
Save mcsf/62c4104b1821d1b37b61d7bafae41c5c to your computer and use it in GitHub Desktop.
Given a command such as "docker-compose up", identifies the project root (the nearest ancestor containing e.g. "docker-compose.yml") and runs the command from there
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 | |
set -e | |
callee="$1" | |
invocation="$@" | |
target="" | |
case "$callee" in | |
docker-compose) | |
target=docker-compose.yml;; | |
make) | |
target=Makefile;; | |
npm) | |
target=package.json;; | |
esac | |
if [ -z "$target" ]; then | |
echo "Unknown command" | |
exit 1 | |
fi | |
while [ ! -f "$target" ]; do | |
if [[ $(pwd) = "/" ]]; then | |
echo "No project file found" | |
exit 1 | |
fi | |
cd .. | |
done | |
echo "$(pwd): $invocation" | |
eval $invocation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment