Skip to content

Instantly share code, notes, and snippets.

@purpleidea
Created March 10, 2018 07:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save purpleidea/ebf5ee7bf47f41132e5d0c1cd8329c75 to your computer and use it in GitHub Desktop.
Save purpleidea/ebf5ee7bf47f41132e5d0c1cd8329c75 to your computer and use it in GitHub Desktop.
#!/bin/bash
# James Shubin, 2018
# run `make` in the first directory (or its parent recursively) that it works in
# https://purpleidea.com/blog/2018/03/10/running-make-from-anywhere/
MF='Makefile' # looks for this file, could look for others, but that's silly
CWD=$(pwd) # starting here
while true; do
if [ -e "$MF" ]; then
make $@ # run make!
e=$?
cd "$CWD" # go home first
exit $e # pass on the exit status
fi
# stop if we get home
if [ "$(pwd)" = "$HOME" ]; then
cd "$CWD"
exit 2 # the exit status of `make` when it errors
fi
#echo "searching..."
cd .. # go up one dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment