[multiple] Move shell files to define load order

This commit is contained in:
Andrew Williams
2026-01-07 15:20:19 +00:00
parent c76580004c
commit a7ee37ce1e
11 changed files with 71 additions and 32 deletions

View File

@@ -0,0 +1,5 @@
# shellcheck shell=bash
# Override XDG cache location for macOS to use the standard Library/Caches directory
export XDG_CACHE_HOME="$HOME/Library/Caches"
export XDG_RUNTIME_DIR="${TMPDIR}runtime-${UID}"

View File

@@ -1,17 +1,17 @@
# shellcheck shell=bash # shellcheck shell=bash
# Override XDG cache location for macOS to use the standard Library/Caches directory
export XDG_CACHE_HOME="$HOME/Library/Caches"
export XDG_RUNTIME_DIR="${TMPDIR}runtime-${UID}"
# Configure Homebrew environment # Configure Homebrew environment
export HOMEBREW_NO_ENV_HINTS=1 if [ -d /opt/homebrew ]; then
[ -d /opt/homebrew ] && eval "$(/opt/homebrew/bin/brew shellenv)" export HOMEBREW_NO_ENV_HINTS=1
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Flushes the DNS cache on macOS # Flushes the DNS cache on macOS
function flushdns() { function flushdns() {
if [[ $(uname) == "Darwin" ]]; then if [[ $(uname) == "Darwin" ]]; then
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; echo 'DNS cache flushed.' sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
echo 'DNS cache flushed.'
else else
echo 'This only works on macOS...' echo 'This only works on macOS...'
fi fi
@@ -31,6 +31,10 @@ function itsok() {
# Runs a brew bundle check and installs missing packages # Runs a brew bundle check and installs missing packages
# Usage: update-brewfile # Usage: update-brewfile
function update-brewfile() { function update-brewfile() {
if ! [ -x $(command -v brew) ]; then
echo "Homebrew is not installed. Please install it first."
return 1
fi
brew bundle check --global || brew bundle --cleanup -f --global brew bundle check --global || brew bundle --cleanup -f --global
} }
@@ -39,18 +43,23 @@ function update-brewfile() {
# app_name<TAB>app_path<TAB>app_type # app_name<TAB>app_path<TAB>app_type
# where app_type can be "persisentApps" or "other" # where app_type can be "persisentApps" or "other"
# Usage: update-dock # Usage: update-dock
function update-dock() { function update-dock() {
if ! [ -x $(command -v dockutil) ]; then
echo "dockutil is not installed. Please install it via Homebrew: brew install dockutil"
return 1
fi
idx=1 idx=1
while read entry; do while read entry; do
app_name=$(echo "$entry" | cut -d $'\t' -f 1) app_name=$(echo "$entry" | cut -d $'\t' -f 1)
app_path=$(echo "$entry" | cut -d $'\t' -f 2) app_path=$(echo "$entry" | cut -d $'\t' -f 2)
app_type=$(echo "$entry" | cut -d $'\t' -f 3) app_type=$(echo "$entry" | cut -d $'\t' -f 3)
idx=$((idx+1)) idx=$((idx + 1))
dockutil --no-restart -a "$app_path" > /dev/null 2>&1 dockutil --no-restart -a "$app_path" >/dev/null 2>&1
if [ "$app_type" = "persisentApps" ]; then if [ "$app_type" = "persisentApps" ]; then
dockutil --move "$app_name" -p $idx dockutil --move "$app_name" -p $idx
fi fi
done < ~/.dotfiles/macos/.config/dotfiles/dockConfig.txt done <~/.dotfiles/macos/.config/dotfiles/dockConfig.txt
killall Dock killall Dock
} }

View File

@@ -2,42 +2,53 @@
# Get the list of AWS profiles # Get the list of AWS profiles
function awsprofiles() { function awsprofiles() {
profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null) if ! [ -x $(command -v aws) ]; then
if [[ -z "$profiles" ]]; then echo "AWS CLI not installed."
echo "No AWS profiles found in '$HOME/.aws/config, check if ~/.aws/config exists and properly configured.'" return 1
return 1 fi
else profiles=$(aws --no-cli-pager configure list-profiles 2>/dev/null)
echo $profiles if [[ -z "$profiles" ]]; then
fi echo "No AWS profiles found in '$HOME/.aws/config, check if ~/.aws/config exists and properly configured.'"
return 1
else
echo $profiles
fi
} }
# login via SSO to AWS # login via SSO to AWS
function awslogin() { function awslogin() {
for cmd in "aws" "fzf"; do
if ! [ -x "$(command -v $cmd)" ]; then
echo "$cmd is not installed. Please install it to use awslogin."
return 1
fi
done
local profile="" local profile=""
local region="" local region=""
# Parse optional arguments # Parse optional arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--profile) --profile)
profile="$2" profile="$2"
shift 2 shift 2
;; ;;
--region) --region)
region="$2" region="$2"
shift 2 shift 2
;; ;;
*) *)
echo "Unknown option: $1" echo "Unknown option: $1"
echo "Usage: awslogin [--profile prof] [--region region]" echo "Usage: awslogin [--profile prof] [--region region]"
return 1 return 1
;; ;;
esac esac
done done
# Get available profiles # Get available profiles
local available_profiles local available_profiles
available_profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null) available_profiles=$(aws --no-cli-pager configure list-profiles 2>/dev/null)
if [[ -z "$available_profiles" ]]; then if [[ -z "$available_profiles" ]]; then
echo "No AWS profiles found in ~/.aws/config" echo "No AWS profiles found in ~/.aws/config"
return 1 return 1
@@ -92,7 +103,11 @@ function awslogin() {
# Clear AWS credentials from environment # Clear AWS credentials from environment
function awslogout() { function awslogout() {
aws sso logout --profile "${AWS_PROFILE:-default}" 2> /dev/null if ! [ -x "$(command -v aws)" ]; then
echo "AWS CLI not installed."
return 1
fi
aws sso logout --profile "${AWS_PROFILE:-default}" 2>/dev/null
unset AWS_PROFILE AWS_PROFILE_ACTIVE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_CREDENTIAL_EXPIRATION unset AWS_PROFILE AWS_PROFILE_ACTIVE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_CREDENTIAL_EXPIRATION
echo "AWS profile and credentials cleared." echo "AWS profile and credentials cleared."
} }

View File

@@ -0,0 +1,10 @@
# shellcheck shell=bash
# Terraform helpers
if [ -x "$(command -v terraform)" ]; then
# Define a shared cache location for Terraform plugins
export TF_PLUGIN_CACHE_DIR="${XDG_CACHE_HOME}/terraform-plugins"
alias tfplan="terraform plan -out=tfplan.binary"
alias tf="terraform"
fi