diff --git a/bash/.config/bash/exports.bash b/bash/.config/bash/01_exports.bash similarity index 100% rename from bash/.config/bash/exports.bash rename to bash/.config/bash/01_exports.bash diff --git a/bash/.config/bash/completions.bash b/bash/.config/bash/10_completions.bash similarity index 100% rename from bash/.config/bash/completions.bash rename to bash/.config/bash/10_completions.bash diff --git a/macos/.config/shell-common/01_macos_xdg.sh b/macos/.config/shell-common/01_macos_xdg.sh new file mode 100644 index 0000000..4e5ddc8 --- /dev/null +++ b/macos/.config/shell-common/01_macos_xdg.sh @@ -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}" diff --git a/macos/.config/shell-common/macos.sh b/macos/.config/shell-common/99_macos.sh similarity index 71% rename from macos/.config/shell-common/macos.sh rename to macos/.config/shell-common/99_macos.sh index 2659f1d..ac341da 100644 --- a/macos/.config/shell-common/macos.sh +++ b/macos/.config/shell-common/99_macos.sh @@ -1,17 +1,17 @@ # 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 -export HOMEBREW_NO_ENV_HINTS=1 -[ -d /opt/homebrew ] && eval "$(/opt/homebrew/bin/brew shellenv)" +if [ -d /opt/homebrew ]; then + export HOMEBREW_NO_ENV_HINTS=1 + eval "$(/opt/homebrew/bin/brew shellenv)" +fi # Flushes the DNS cache on macOS function flushdns() { 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 echo 'This only works on macOS...' fi @@ -31,6 +31,10 @@ function itsok() { # Runs a brew bundle check and installs missing packages # Usage: 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 } @@ -39,18 +43,23 @@ function update-brewfile() { # app_nameapp_pathapp_type # where app_type can be "persisentApps" or "other" # Usage: 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 while read entry; do app_name=$(echo "$entry" | cut -d $'\t' -f 1) app_path=$(echo "$entry" | cut -d $'\t' -f 2) app_type=$(echo "$entry" | cut -d $'\t' -f 3) - idx=$((idx+1)) - dockutil --no-restart -a "$app_path" > /dev/null 2>&1 + idx=$((idx + 1)) + dockutil --no-restart -a "$app_path" >/dev/null 2>&1 if [ "$app_type" = "persisentApps" ]; then dockutil --move "$app_name" -p $idx fi - done < ~/.dotfiles/macos/.config/dotfiles/dockConfig.txt + done <~/.dotfiles/macos/.config/dotfiles/dockConfig.txt killall Dock } diff --git a/shell-common/.config/shell-common/exports.sh b/shell-common/.config/shell-common/01_exports.sh similarity index 100% rename from shell-common/.config/shell-common/exports.sh rename to shell-common/.config/shell-common/01_exports.sh diff --git a/shell-common/.config/shell-common/aliases.sh b/shell-common/.config/shell-common/10_aliases.sh similarity index 100% rename from shell-common/.config/shell-common/aliases.sh rename to shell-common/.config/shell-common/10_aliases.sh diff --git a/shell-common/.config/shell-common/functions.sh b/shell-common/.config/shell-common/10_functions.sh similarity index 100% rename from shell-common/.config/shell-common/functions.sh rename to shell-common/.config/shell-common/10_functions.sh diff --git a/shell-common/.config/shell-common/aws.sh b/shell-common/.config/shell-common/99_aws.sh similarity index 77% rename from shell-common/.config/shell-common/aws.sh rename to shell-common/.config/shell-common/99_aws.sh index 7a4659b..387a393 100644 --- a/shell-common/.config/shell-common/aws.sh +++ b/shell-common/.config/shell-common/99_aws.sh @@ -2,42 +2,53 @@ # Get the list of AWS profiles function awsprofiles() { - profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null) - if [[ -z "$profiles" ]]; then - echo "No AWS profiles found in '$HOME/.aws/config, check if ~/.aws/config exists and properly configured.'" - return 1 - else - echo $profiles - fi + if ! [ -x $(command -v aws) ]; then + echo "AWS CLI not installed." + return 1 + fi + profiles=$(aws --no-cli-pager configure list-profiles 2>/dev/null) + if [[ -z "$profiles" ]]; then + 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 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 region="" # Parse optional arguments while [[ $# -gt 0 ]]; do case "$1" in - --profile) - profile="$2" - shift 2 - ;; - --region) - region="$2" - shift 2 - ;; - *) - echo "Unknown option: $1" - echo "Usage: awslogin [--profile prof] [--region region]" - return 1 - ;; + --profile) + profile="$2" + shift 2 + ;; + --region) + region="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + echo "Usage: awslogin [--profile prof] [--region region]" + return 1 + ;; esac done # Get 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 echo "No AWS profiles found in ~/.aws/config" return 1 @@ -92,7 +103,11 @@ function awslogin() { # Clear AWS credentials from environment 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 echo "AWS profile and credentials cleared." } diff --git a/shell-common/.config/shell-common/99_terraform.sh b/shell-common/.config/shell-common/99_terraform.sh new file mode 100644 index 0000000..6967b03 --- /dev/null +++ b/shell-common/.config/shell-common/99_terraform.sh @@ -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 diff --git a/zsh/.config/zsh/exports.zsh b/zsh/.config/zsh/01_exports.zsh similarity index 100% rename from zsh/.config/zsh/exports.zsh rename to zsh/.config/zsh/01_exports.zsh diff --git a/zsh/.config/zsh/completions.zsh b/zsh/.config/zsh/10_completions.zsh similarity index 100% rename from zsh/.config/zsh/completions.zsh rename to zsh/.config/zsh/10_completions.zsh