fix for zsh on macos
This commit is contained in:
+17
-3
@@ -2,7 +2,7 @@
|
|||||||
# file rc.sh: Call user defined functions
|
# file rc.sh: Call user defined functions
|
||||||
## author: Yann "aya" Autissier
|
## author: Yann "aya" Autissier
|
||||||
## license: GPL
|
## license: GPL
|
||||||
## version: 20220630
|
## version: 20260730
|
||||||
|
|
||||||
case $- in
|
case $- in
|
||||||
# if this is an interactive shell
|
# if this is an interactive shell
|
||||||
@@ -20,7 +20,14 @@ case $- in
|
|||||||
func_name="${func_name#?}"
|
func_name="${func_name#?}"
|
||||||
done
|
done
|
||||||
# call user function with args passed from the content of the file
|
# 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
|
fi
|
||||||
done
|
done
|
||||||
# load user stuff from RC_* env vars
|
# load user stuff from RC_* env vars
|
||||||
@@ -36,7 +43,14 @@ case $- in
|
|||||||
func_name="${func_name#?}"
|
func_name="${func_name#?}"
|
||||||
done
|
done
|
||||||
# call user function with args passed from the value of the env var
|
# 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
|
done
|
||||||
unset IFS
|
unset IFS
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# file rc_functions.sh: Define shell functions
|
# file rc_functions.sh: Define shell functions
|
||||||
## author: Yann "aya" Autissier
|
## author: Yann "aya" Autissier
|
||||||
## license: GPL
|
## license: GPL
|
||||||
## version: 20221229
|
## version: 20260730
|
||||||
|
|
||||||
# function force: Run a command sine die
|
# function force: Run a command sine die
|
||||||
force() {
|
force() {
|
||||||
@@ -295,8 +295,12 @@ ssh_add() {
|
|||||||
# split on spaces/newlines via tr, portable across bash (IFS split) and zsh (no word split)
|
# 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
|
printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do
|
||||||
[ -r "${file}" ] || continue
|
[ -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
|
# 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
|
done
|
||||||
unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_AGENT_DIR SSH_AGENT_SOCK SSH_PRIVATE_KEYS
|
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)
|
# 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
|
printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do
|
||||||
[ -r "${file}" ] || continue
|
[ -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
|
# 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
|
done
|
||||||
unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_PRIVATE_KEYS
|
unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_PRIVATE_KEYS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user