mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-05 10:44:49 +00:00
feat(config): config loading changes and fixes
This commit is contained in:
@@ -2,35 +2,76 @@
|
||||
# Load our configuration files
|
||||
# Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved.
|
||||
|
||||
# Set verbosity with VERBOSE=1 x-load-configs
|
||||
: "${VERBOSE:0}"
|
||||
set -euo pipefail
|
||||
|
||||
DOTFILES="$HOME/.dotfiles"
|
||||
# Set verbosity with VERBOSE=1 x-load-configs
|
||||
VERBOSE="${VERBOSE:=0}"
|
||||
|
||||
[ "$VERBOSE" = "1" ] && {
|
||||
set -x
|
||||
}
|
||||
|
||||
CONFIG_PATH="$DOTFILES/config"
|
||||
|
||||
# Load the shell dotfiles, and then some:
|
||||
HOST="$(hostname -s)"
|
||||
[ "$VERBOSE" = "1" ] && {
|
||||
echo "x-load-config-fn: VERBOSE=1"
|
||||
echo "x-load-config-fn: HOST: $HOST"
|
||||
echo "x-load-configs: VERBOSE=1"
|
||||
echo "x-load-configs: HOST: $HOST"
|
||||
}
|
||||
for FILE in $CONFIG_PATH/{exports,alias,functions}; do
|
||||
FILENAME="$FILE"
|
||||
|
||||
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 "?" "$CONFIG_FILE"
|
||||
|
||||
# global (exports|alias|functions) FILENAME for all hosts
|
||||
# shellcheck source=../config/exports
|
||||
[ -r "$FILENAME" ] && source "$FILENAME" \
|
||||
&& [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME"
|
||||
[ -r "$CONFIG_FILE" ] && {
|
||||
source "$CONFIG_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$CONFIG_FILE"
|
||||
}
|
||||
|
||||
# global secret FILENAME, git ignored
|
||||
# shellcheck source=../config/exports-secret
|
||||
[ -r "$FILENAME-secret" ] && source "$FILENAME-secret" \
|
||||
&& [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-secret"
|
||||
[ "$VERBOSE" = "1" ] && configMsg "?" "$SECRET_FILE"
|
||||
[ -r "$SECRET_FILE" ] && {
|
||||
source "$SECRET_FILE" && [ "$VERBOSE" = "1" ] && configMsg "Found" "$SECRET_FILE"
|
||||
}
|
||||
# host specific (exports|alias|functions) FILENAME
|
||||
# shellcheck source=../config/exports
|
||||
[ -r "$FILENAME-$HOST" ] && source "$FILENAME-$HOST" \
|
||||
&& [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-$HOST"
|
||||
[ "$VERBOSE" = "1" ] && configMsg "?" "$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
|
||||
[ -r "$FILENAME-$HOST-secret" ] && source "$FILENAME-$HOST-secret" \
|
||||
&& [ "$VERBOSE" = "1" ] && echo "x-load-config-fn: $FILENAME-$HOST-secret"
|
||||
done
|
||||
[ "$VERBOSE" = "1" ] && configMsg "?" "$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
|
||||
|
||||
50
local/bin/x-set-php-aliases
Executable file
50
local/bin/x-set-php-aliases
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Check which php versions are installed with brew, and create aliases for each installation.
|
||||
# Copyright (c) 2023 Ismo Vuorinen. All Rights Reserved.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Set verbosity with VERBOSE=1 x-load-configs
|
||||
VERBOSE="${VERBOSE:=0}"
|
||||
|
||||
[ "$VERBOSE" = "2" ] && {
|
||||
set -x
|
||||
}
|
||||
|
||||
! x-have brew && {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Get installed php versions from brew and setup aliases
|
||||
php_versions=()
|
||||
while IFS="" read -r line; do php_versions+=("$line"); done < <(bkt -- brew list | grep '^php')
|
||||
|
||||
php_error_reporting='-d error_reporting=22527'
|
||||
|
||||
for version in "${php_versions[@]}"; do
|
||||
[ "$VERBOSE" = "1" ] && echo "Setting aliases for $version"
|
||||
# drop the dot from version (8.0 -> 80)
|
||||
php_abbr="${version//\./}"
|
||||
# replace "php@" with "p" so "php@80" becomes "p80"
|
||||
php_alias="${php_abbr//php@/p}"
|
||||
|
||||
# Fetch the exec path once
|
||||
php_exec="$HOMEBREW_PREFIX/opt/$version/bin/php"
|
||||
|
||||
[ -f "$php_exec" ] && {
|
||||
[ "$VERBOSE" = "1" ] && echo "-> php_exec $php_exec"
|
||||
|
||||
# Raw PHP without error_reporting flag.
|
||||
# shellcheck disable=SC2139
|
||||
alias "${php_alias}"r="$php_exec"
|
||||
# PHP with error_reporting flag.
|
||||
# shellcheck disable=SC2139,SC2140
|
||||
alias "$php_alias"="$php_exec $php_error_reporting"
|
||||
# Local PHP Server.
|
||||
# shellcheck disable=SC2139,SC2140
|
||||
alias "${php_alias}s"="$php_exec -S localhost:9000"
|
||||
# Use composer with specific PHP and error_reporting flag on.
|
||||
# shellcheck disable=SC2139,SC2140
|
||||
alias "${php_alias}c"="$php_exec $php_error_reporting $(which composer)"
|
||||
}
|
||||
done
|
||||
Reference in New Issue
Block a user