Reorder the redirections to prevent errors being displayed when they shouldn't be.

This commit is contained in:
Darren 'Tadgy' Austin 2019-07-02 01:30:43 +01:00
commit 6bc2b27b67

View file

@ -6,7 +6,7 @@ _agent_prompt_command() {
# Check the ssh agent socket is still alive.
# Need to work around an ssh-add bug here: ssh-add doesn't always return 2 on failure
# to contact the agent, so also check if any errors were produced.
OUTPUT=$(ssh-add -l >/dev/null)
OUTPUT=$(ssh-add -l 2>&1 >/dev/null)
if ((${PIPESTATUS[0]} >= 2)) || [[ ! -z "$OUTPUT" ]]; then
# Auth socket has become unusable, search for a new one.
SOCK="$(_find_agent_sock)"
@ -40,7 +40,7 @@ _clean_agent_socks() {
local I OUTPUT SSH_AUTH_SOCK
# Go through the array of sockets and validate each one.
for ((I = 0; I < ${#SOCKS[@]}; I++)); do
OUTPUT="$(SSH_AUTH_SOCK="${SOCKS[$I]}" ssh-add -l >/dev/null)"
OUTPUT="$(SSH_AUTH_SOCK="${SOCKS[$I]}" ssh-add -l 2>&1 >/dev/null)"
((${PIPESTATUS[0]} >= 2)) || [[ ! -z "$OUTPUT" ]] && {
unset SOCKS[$I]
}
@ -59,7 +59,7 @@ _find_agent_sock() {
fi
# Search backwards through the list to find an active socket.
for ((I = (${#SOCKS[@]} - 1); I >= 0; I--)); do
OUTPUT="$(SSH_AUTH_SOCK="${SOCKS[$I]}" ssh-add -l >/dev/null)"
OUTPUT="$(SSH_AUTH_SOCK="${SOCKS[$I]}" ssh-add -l 2>&1 >/dev/null)"
{ ((${PIPESTATUS[0]} <= 1)) && [[ -z "$OUTPUT" ]]; } && [[ ! -z "${SOCKS[$I]}" ]] && {
printf "%s" "${SOCKS[$I]}"
return 0