Instead of using a grep to remove the current SSH_AUTH_SOCK, use a loop.

This commit is contained in:
Darren 'Tadgy' Austin 2019-07-01 17:06:19 +01:00
commit dc550c2d59

13
.bashrc
View file

@ -67,15 +67,22 @@ _find_agent_sock() {
}
_pop_agent_sock() {
local IFS=$'\n' REPLY SOCKS=()
local I IFS=$'\n' REPLY SOCKS=()
# Read the current list of auth sockets.
if ((${BASH_VERSINFO[0]} >= 4)); then
mapfile -t SOCKS < <(egrep -v "^$SSH_AUTH_SOCK\$" ~/.ssh/agents 2>/dev/null)
mapfile -t SOCKS <~/.ssh/agents
else
while read -r; do
SOCKS+=("$REPLY")
done < <(egrep -v "^$SSH_AUTH_SOCK\$" ~/.ssh/agents 2>/dev/null)
done <~/.ssh/agents
fi
# Remove the last instance of the socket in $SSH_AUTH_SOCK.
for ((I = (${#SOCKS[@]} - 1); I >= 0; I--)); do
[[ "${SOCKS[$I]}" == "$SSH_AUTH_SOCK" ]] && {
unset SOCKS[$I]
break
}
done
# Clean up any dead sockets - this modifies the SOCKS array.
_clean_agent_socks
# Write the new list back to disk.