From 0f37f2756392431822c90ba8afc30931cc349614 Mon Sep 17 00:00:00 2001 From: aya Date: Wed, 29 Jul 2026 20:54:40 +0200 Subject: [PATCH] fix for zsh on macos --- docker/myos/rc.sh | 20 +++++++++++++++++--- docker/myos/rc_functions.sh | 13 ++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/docker/myos/rc.sh b/docker/myos/rc.sh index 87dd6a7..2b07256 100644 --- a/docker/myos/rc.sh +++ b/docker/myos/rc.sh @@ -2,7 +2,7 @@ # file rc.sh: Call user defined functions ## author: Yann "aya" Autissier ## license: GPL -## version: 20220630 +## version: 20260730 case $- in # if this is an interactive shell @@ -20,7 +20,14 @@ case $- in func_name="${func_name#?}" done # call user function with args passed from the content of the file - command -v "${func_name}" >/dev/null 2>&1 && "${func_name}" "${func_args}" + # an empty file means no args at all, do not pass an empty string + if command -v "${func_name}" >/dev/null 2>&1; then + if [ -n "${func_args}" ]; then + "${func_name}" "${func_args}" + else + "${func_name}" + fi + fi fi done # load user stuff from RC_* env vars @@ -36,7 +43,14 @@ case $- in func_name="${func_name#?}" done # call user function with args passed from the value of the env var - command -v "${func_name}" >/dev/null 2>&1 && "${func_name}" "${func_args}" + # RC_FOO=true means no args at all, do not pass an empty string + if command -v "${func_name}" >/dev/null 2>&1; then + if [ -n "${func_args:-}" ]; then + "${func_name}" "${func_args}" + else + "${func_name}" + fi + fi done unset IFS ;; diff --git a/docker/myos/rc_functions.sh b/docker/myos/rc_functions.sh index 0bd1c60..f099a89 100644 --- a/docker/myos/rc_functions.sh +++ b/docker/myos/rc_functions.sh @@ -2,7 +2,7 @@ # file rc_functions.sh: Define shell functions ## author: Yann "aya" Autissier ## license: GPL -## version: 20221229 +## version: 20260730 # function force: Run a command sine die force() { @@ -295,8 +295,12 @@ ssh_add() { # split on spaces/newlines via tr, portable across bash (IFS split) and zsh (no word split) printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do [ -r "${file}" ] || continue + # fingerprint is empty when ssh-keygen cannot read the key (legacy PEM without .pub): + # in that case add it instead of matching the empty pattern against every agent line + fingerprint="$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')" + [ -n "${fingerprint}" ] && ssh-add -l 2>/dev/null |grep -qF "${fingerprint}" && continue # add private key to agent - ssh-add -l |grep -q "$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')" 2>/dev/null || ssh-add "${file}" + ssh-add "${file}" done unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_AGENT_DIR SSH_AGENT_SOCK SSH_PRIVATE_KEYS } @@ -323,8 +327,11 @@ ssh_del() { # split on spaces/newlines via tr, portable across bash (IFS split) and zsh (no word split) printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do [ -r "${file}" ] || continue + # skip keys we cannot fingerprint, an empty pattern would match any agent line + fingerprint="$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')" + [ -n "${fingerprint}" ] || continue # remove private key from agent - ssh-add -l |grep -q "$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')" 2>/dev/null && ssh-add -d "${file}" + ssh-add -l 2>/dev/null |grep -qF "${fingerprint}" && ssh-add -d "${file}" done unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_PRIVATE_KEYS }