From a18c16b0b960e142a29dafea36bde6c82ce780a2 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Sun, 8 Feb 2026 01:12:39 +0200 Subject: [PATCH] fix(shell): harden shared.sh and dfm for set -euo pipefail Use ${VAR:-} defaults in shared.sh to prevent set -u failures on unset variables (DOTFILES, ZSH_CUSTOM_COMPLETION_PATH, FPATH). Export DOTFILES/BREWFILE/HOSTFILES in dfm so sourced scripts see them. --- config/shared.sh | 6 +++--- local/bin/dfm | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config/shared.sh b/config/shared.sh index d563dd2..ffeedea 100755 --- a/config/shared.sh +++ b/config/shared.sh @@ -5,7 +5,7 @@ # shellcheck shell=bash # Defaults -[[ -z "$DOTFILES" ]] && export DOTFILES="$HOME/.dotfiles" +[[ -z "${DOTFILES:-}" ]] && export DOTFILES="$HOME/.dotfiles" DOTFILES_CURRENT_SHELL=$(basename "$SHELL") export DOTFILES_CURRENT_SHELL @@ -76,9 +76,9 @@ x-path-prepend "$DOTFILES/local/bin" x-path-prepend "$XDG_BIN_HOME" # Custom completion paths -[[ -z "$ZSH_CUSTOM_COMPLETION_PATH" ]] && export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" +[[ -z "${ZSH_CUSTOM_COMPLETION_PATH:-}" ]] && export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" x-dc "$ZSH_CUSTOM_COMPLETION_PATH" -export FPATH="$ZSH_CUSTOM_COMPLETION_PATH:$FPATH" +export FPATH="$ZSH_CUSTOM_COMPLETION_PATH:${FPATH:-}" if ! declare -f msg > /dev/null; then # Function to print messages if VERBOSE is enabled diff --git a/local/bin/dfm b/local/bin/dfm index c66a750..9b39ff9 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -12,6 +12,7 @@ : "${DOTFILES:=$HOME/.dotfiles}" : "${BREWFILE:=$DOTFILES/config/homebrew/Brewfile}" : "${HOSTFILES:=$DOTFILES/hosts}" +export DOTFILES BREWFILE HOSTFILES SCRIPT=$(basename "$0")