Skip to content

Instantly share code, notes, and snippets.

@danbrakeley
Created July 8, 2019 00:02
Show Gist options
  • Save danbrakeley/913f89c967359c75dc92e16a800d13ee to your computer and use it in GitHub Desktop.
Save danbrakeley/913f89c967359c75dc92e16a800d13ee to your computer and use it in GitHub Desktop.
#!/bin/bash
# hit v0.1 by Dan Brakeley
# This script just looks for a file named `hit` in the current or a parent folder.
# If it finds it, it runs it, passing along all arguments passed to this script.
# I use hit scripts as a quick & dirty make.
BIN_DIR=$(dirname $(realpath $0))
LOCAL_DIR=$(realpath $(pwd))
function exit_with_no_hits {
echo "No hit file found"
exit 1
}
for i in {1..10}
do
if [[ $BIN_DIR != $LOCAL_DIR ]]; then
if [ -f $LOCAL_DIR/hit ]; then
$LOCAL_DIR/hit $*
exit 0
fi
if [[ $LOCAL_DIR == "/" ]]; then
exit_with_no_hits
fi
LOCAL_DIR=$(dirname $LOCAL_DIR)
fi
done
exit_with_no_hits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment