fix for zsh on macos

This commit is contained in:
aya
2026-07-29 20:55:08 +02:00
parent b6b4522d31
commit 0f37f27563
2 changed files with 27 additions and 6 deletions
+17 -3
View File
@@ -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
;;
+10 -3
View File
@@ -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
}