From e535616faf5892acd45ca6e85ccf4d6f995560ae Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Sat, 24 May 2025 15:13:49 -0700 Subject: [PATCH] upd: fix bug where realpath could crash --- .config/shell/bin/upd | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.config/shell/bin/upd b/.config/shell/bin/upd index 4a0ff38..3c5179d 100755 --- a/.config/shell/bin/upd +++ b/.config/shell/bin/upd @@ -51,21 +51,16 @@ contains() { pretty_path() { arg="$1" + # If the arg starts with our home dir, replace the prefix with a tilde case "$arg" in - # If the arg starts with our home dir, "$HOME"*) - # replace the home dir part with a ~ - printf '~%s' "$(printf '%s' "$arg" | sed -E 's/^.{'"${#HOME}"'}//')" + arg="~${arg#"$HOME"}" ;; + esac - # Otherwise, - *) - # Just print the arg - printf '%s' "${arg}" - ;; - esac | # Pass through some other filters - sed -E 's_/+$__' | # Remove trailing slash - tr -s '/' # Remove duplicate slashes + printf '%s' "$arg" | + tr -s '/' | # Remove duplicate slashes + sed 's+/$++' # Remove trailing slash } # Warn about incomplete changes to a repository @@ -101,7 +96,7 @@ do_pull() { for repo in "$@"; do if [ -n "$repo" ]; then repo_pretty="$(pretty_path "$repo")" - repo="$(realpath "$repo" 2>/dev/null)" + repo="$(realpath "$repo" 2>/dev/null || true)" repo="$(git -C "$repo" rev-parse --show-toplevel 2> /dev/null || true)" if [ -n "$repo" ]; then if ! contains "$repo" ':' "$updated"; then @@ -133,7 +128,7 @@ do_pull() { ${did_updates:-false} && echo echo " Updating ${green}dotfiles${nc}…" dotfiles pull - do_checks "$(dotfiles rev-parse --git-dir)" dotfiles + do_checks "$(pretty_path "$(dotfiles rev-parse --git-dir)")" dotfiles fi }