From e918a41d757bb996a6e20f36d192ffac6b0537e7 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 18 Mar 2026 12:33:00 +0200 Subject: [PATCH] fix: guard success messages on command exit status - Source x-path instead of capturing empty stdout via command substitution - Validate --dry-run argument in cleanup script, reject unknown flags - Gate success messages on preceding command's exit status with && - Applies to dfm (fmt, reset_nvim, shfmt) and install scripts (fonts, gh-extensions, python-packages, shellspec, z) --- config/exports | 5 ++++- local/bin/dfm | 26 ++++++++++++++----------- scripts/cleanup-old-version-managers.sh | 10 +++++++++- scripts/install-fonts.sh | 5 +++-- scripts/install-gh-extensions.sh | 4 ++-- scripts/install-python-packages.sh | 4 ++-- scripts/install-shellspec.sh | 4 ++-- scripts/install-z.sh | 4 ++-- 8 files changed, 39 insertions(+), 23 deletions(-) diff --git a/config/exports b/config/exports index 014070f..902edab 100755 --- a/config/exports +++ b/config/exports @@ -22,7 +22,10 @@ PATH="$DOTFILES/local/bin:$PATH" # Use x-path to deduplicate PATH entries (only if x-path is available) if command -v x-path &> /dev/null; then - PATH="$(x-path prepend "$XDG_BIN_HOME" "$DOTFILES/local/bin" "/opt/homebrew/bin" "/usr/local/bin")" + # shellcheck source=../local/bin/x-path + source "$(command -v x-path)" + normalize_path_var + do_prepend "$XDG_BIN_HOME" "$DOTFILES/local/bin" "/opt/homebrew/bin" "/usr/local/bin" fi export PATH diff --git a/local/bin/dfm b/local/bin/dfm index e6421fc..b6f177a 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -531,9 +531,9 @@ section_dotfiles() case "$1" in fmt) msgr run "Running all formatters" - $0 dotfiles yamlfmt - $0 dotfiles shfmt - msgr run_done "...done!" + $0 dotfiles yamlfmt \ + && $0 dotfiles shfmt \ + && msgr run_done "...done!" ;; reset_all) @@ -547,12 +547,16 @@ section_dotfiles() ~/.local/share/nvim \ ~/.local/state/nvim \ ~/.cache/nvim \ - ~/.config/nvim - msgr ok "Deleted old nvim files (share, state and cache + config)" - ln -s "$DOTFILES/config/nvim" ~/.config/nvim - msgr ok "Linked nvim and astronvim" - $0 install mise - msgr ok "Installed packages" + ~/.config/nvim \ + && msgr ok "Deleted old nvim files (share, state and cache + config)" + ln -s "$DOTFILES/config/nvim" ~/.config/nvim \ + && msgr ok "Linked nvim and astronvim" + if $0 install mise; then + msgr ok "Installed packages" + else + msgr err "Failed to install mise tools" + exit 1 + fi msgr run_done "nvim reset!" ;; @@ -575,8 +579,8 @@ section_dotfiles() --language-dialect bash \ --func-next-line --list --write \ --indent 2 --case-indent --space-redirects \ - --binary-next-line {} \; - msgr yay "dotfiles have been shfmt formatted!" + --binary-next-line {} \; \ + && msgr yay "dotfiles have been shfmt formatted!" ;; *) menu_builder "$USAGE_PREFIX" "${MENU[@]}" ;; diff --git a/scripts/cleanup-old-version-managers.sh b/scripts/cleanup-old-version-managers.sh index 405c64f..feca1f7 100755 --- a/scripts/cleanup-old-version-managers.sh +++ b/scripts/cleanup-old-version-managers.sh @@ -12,7 +12,15 @@ fi # shellcheck source=shared.sh source "$DOTFILES/config/shared.sh" -DRY_RUN="${1:-}" +DRY_RUN="" +if [[ $# -gt 0 ]]; then + if [[ "$1" = "--dry-run" ]]; then + DRY_RUN="--dry-run" + else + echo "Usage: $0 [--dry-run]" >&2 + exit 1 + fi +fi remove_dir() { diff --git a/scripts/install-fonts.sh b/scripts/install-fonts.sh index 712faf3..efe2fcb 100755 --- a/scripts/install-fonts.sh +++ b/scripts/install-fonts.sh @@ -51,8 +51,9 @@ install_fonts() { msgr run "Starting to install NerdFonts..." # shellcheck disable=SC2048,SC2086 - ./install.sh -q -s ${fonts[*]} - msgr run_done "Done" + # shellcheck disable=SC2086 + ./install.sh -q -s ${fonts[*]} \ + && msgr run_done "Done" return 0 } diff --git a/scripts/install-gh-extensions.sh b/scripts/install-gh-extensions.sh index a7d7020..9a48c12 100755 --- a/scripts/install-gh-extensions.sh +++ b/scripts/install-gh-extensions.sh @@ -51,8 +51,8 @@ install_extensions() # Install all GitHub CLI extensions main() { - install_extensions - msgr run_done "Done" + install_extensions \ + && msgr run_done "Done" return 0 } diff --git a/scripts/install-python-packages.sh b/scripts/install-python-packages.sh index 993ee87..ef27249 100755 --- a/scripts/install-python-packages.sh +++ b/scripts/install-python-packages.sh @@ -35,5 +35,5 @@ install_libraries() return 0 } -install_libraries -msgr yay "Python library installations complete" +install_libraries \ + && msgr yay "Python library installations complete" diff --git a/scripts/install-shellspec.sh b/scripts/install-shellspec.sh index 7f3501e..6448859 100755 --- a/scripts/install-shellspec.sh +++ b/scripts/install-shellspec.sh @@ -23,8 +23,8 @@ install_shellspec() fi msgr run "Running make install..." - make -C "$SHELLSPEC_CACHE" install PREFIX="$HOME/.local" - msgr run_done "shellspec $version installed to $HOME/.local/bin/shellspec" + make -C "$SHELLSPEC_CACHE" install PREFIX="$HOME/.local" \ + && msgr run_done "shellspec $version installed to $HOME/.local/bin/shellspec" return 0 } diff --git a/scripts/install-z.sh b/scripts/install-z.sh index b40e7e9..cdd315b 100755 --- a/scripts/install-z.sh +++ b/scripts/install-z.sh @@ -15,8 +15,8 @@ clone_z_repo() local bin_path=$2 if [[ ! -d "$bin_path" ]]; then - git clone "$git_path" "$bin_path" - msgr run_done "z installed at $bin_path" + git clone "$git_path" "$bin_path" \ + && msgr run_done "z installed at $bin_path" else msgr ok "z ($bin_path/) already installed" fi