#!/bin/bash BUILD_CONFIG= # try to find a valid build config path if [ -n "${1+x}" ] && [ -f "$1" ] && [[ "$(basename "$1")" == ".buildconfig" ]]; then BUILD_CONFIG="$1" # first check if a build config has been specified, and whether it's a valid path elif [ -n "${1+x}" ]; then echo "E: the specified path '$1' is not a valid path!"; exit 1 elif [[ -f "$PWD/.buildconfig" ]]; then BUILD_CONFIG="$PWD/.buildconfig" # then check if there is a build config in the current working directory elif [[ -f "$HOME/.buildconfig" ]]; then BUILD_CONFIG="$HOME/.buildconfig" # then check if there is a build config in the home directory else $EDITOR .buildconfig #else echo "E: could not find a .buildconfig file and none was specified!"; exit 1 fi source "$BUILD_CONFIG" [ -z "${cmd+x}" ] && { echo "E: cmd was not set! '$BUILD_CONFIG'"; exit 1; } [ -z "${arg+x}" ] && { echo "E: arg was not set! '$BUILD_CONFIG'"; exit 1; } # export the environment variables if they've been set if [[ -n ${env+x} ]]; then for var in "${!env[@]}"; do export "$var=${env[$var]}" done fi # execute the command with the arguments # don't mind if the user made arguments separate out, that would likely be the user's intention $cmd "$arg" exit $?