mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 03:04:06 +00:00
78 lines
2.0 KiB
Bash
Executable File
78 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Load our configuration files
|
|
# Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved.
|
|
|
|
# Enable verbosity with VERBOSE=1 x-load-configs
|
|
VERBOSE="${VERBOSE:=0}"
|
|
# Enable debugging with DEBUG=1 x-load-configs
|
|
DEBUG="${DEBUG:=0}"
|
|
|
|
[ "$DEBUG" = "1" ] && {
|
|
set -x
|
|
}
|
|
|
|
CONFIG_PATH="$DOTFILES/config"
|
|
|
|
# Load the shell dotfiles, and then some:
|
|
HOST="$(hostname -s)"
|
|
[ "$VERBOSE" = "1" ] && {
|
|
echo "x-load-configs: VERBOSE=1"
|
|
echo "x-load-configs: HOST: $HOST"
|
|
}
|
|
|
|
configFile()
|
|
{
|
|
echo "$CONFIG_PATH/$1"
|
|
}
|
|
|
|
configMsg()
|
|
{
|
|
printf 'x-load-configs: %s %s\n' "$1" "$2"
|
|
}
|
|
|
|
loadConfigFiles()
|
|
{
|
|
CONFIG_FILE=$1
|
|
SECRET_FILE=$CONFIG_FILE-secret
|
|
HOST_FILE=$CONFIG_FILE-$HOST
|
|
SECRET_HOST=$HOST_FILE-secret
|
|
|
|
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$CONFIG_FILE"
|
|
|
|
# global (exports|alias|functions) FILENAME for all hosts
|
|
# shellcheck source=../config/exports
|
|
[ -r "$CONFIG_FILE" ] && {
|
|
source "$CONFIG_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$CONFIG_FILE"
|
|
}
|
|
|
|
# global secret FILENAME, git ignored
|
|
# shellcheck source=../config/exports-secret
|
|
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$SECRET_FILE"
|
|
[ -r "$SECRET_FILE" ] && {
|
|
source "$SECRET_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$SECRET_FILE"
|
|
}
|
|
# host specific (exports|alias|functions) FILENAME
|
|
# shellcheck source=../config/exports
|
|
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$HOST_FILE"
|
|
[ -r "$HOST_FILE" ] && {
|
|
source "$HOST_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$HOST_FILE"
|
|
}
|
|
# host specific (exports|alias|functions) FILENAME, git ignored
|
|
# shellcheck source=../config/exports
|
|
[ "$VERBOSE" = "1" ] && configMsg "Looking for" "$SECRET_HOST"
|
|
[ -r "$SECRET_HOST" ] && {
|
|
source "$SECRET_HOST" \
|
|
&& [ "$VERBOSE" = "1" ] && configMsg "Found" "$SECRET_HOST"
|
|
}
|
|
}
|
|
|
|
FILE_EXPORTS=$(configFile "exports")
|
|
FILE_FUNCTIONS=$(configFile "functions")
|
|
FILE_ALIAS=$(configFile "alias")
|
|
|
|
loadConfigFiles "$FILE_EXPORTS"
|
|
loadConfigFiles "$FILE_FUNCTIONS"
|
|
loadConfigFiles "$FILE_ALIAS"
|
|
|
|
exit 0
|