Files
.dotfiles/.local/bin/buildconfig
Quinn a50ead749a move xdg directories to the default location.
a lot of applications seem to hardcode this location, so it's better to
have something default, or default-adjasoned.
2025-11-19 10:39:51 +01:00

30 lines
1.2 KiB
Bash
Executable File

#!/usr/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 $?