From dae5b0fdaada6d139e8ca11f6543f66875c942a8 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 2 Jul 2019 22:04:33 +0100 Subject: [PATCH] Added flag so .bash_logout won't try to unregister a socket that didn't register. --- .bash_logout | 2 +- .bash_profile | 8 ++++---- .bashrc | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.bash_logout b/.bash_logout index c801b0d..2e5c6a0 100644 --- a/.bash_logout +++ b/.bash_logout @@ -18,7 +18,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { _PLATFORM="$(uname -s)" # Remove the SSH_AUTH_SOCK from the agents file. - [[ ! -z "$SSH_AUTH_SOCK" ]] && { + [[ ! -z "$SSH_AUTH_SOCK" ]] && (( ${_SSH_AGENT_REG_FAILED:-0} == 0 )) && { _lock_agents_file && { _pop_agent_sock || { echo -e "$(tput setaf 1 || tput AF 1)Failed to clean up agents file!$(tput op)" diff --git a/.bash_profile b/.bash_profile index 6db7240..41d9842 100644 --- a/.bash_profile +++ b/.bash_profile @@ -51,7 +51,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo "Connected to ssh-agent." else echo -e "$(tput setaf 3)Connected to ssh-agent, but failed to register socket.$(tput op)" - # FIXME: Set marker here that we failed. + _SSH_AGENT_REG_FAILED=1 fi } _unlock_agents_file @@ -67,7 +67,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo "Connected to alternate ssh-agent - you may need to re-add keys." else echo "$(tput setaf 3)Connected to, but failed to register, alternate ssh-agent - you may need to re-add keys.$(tput op)" - # FIXME: Set marker here that we failed. + _SSH_AGENT_REG_FAILED=1 fi } _unlock_agents_file @@ -87,7 +87,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo "Connected to ssh-agent." else echo "$(tput setaf 3)Connected to, but failed to register, ssh-agent.$(tput op)" - # FIXME: Set marker here that we failed. + _SSH_AGENT_REG_FAILED=1 fi } _unlock_agents_file @@ -103,7 +103,7 @@ hash ssh-add ssh-agent >/dev/null 2>&1 && { echo "Started new ssh-agent." else echo "$(tput setaf 3)Started, but failed to register, new ssh-agent$(tput op)" - # FIXME: Set marker here that we failed. + _SSH_AGENT_REG_FAILED=1 fi } _unlock_agents_file diff --git a/.bashrc b/.bashrc index 8d593cf..79420fa 100644 --- a/.bashrc +++ b/.bashrc @@ -15,8 +15,10 @@ _agent_prompt_command() { _lock_agents_file && { if _push_agent_sock; then echo "Connected to alternate ssh-agent - you may need to re-add keys." + _SSH_AGENT_REG_FAILED=0 else echo "Connected to, but failed to register, alternate ssh-agent - you may need to re-add keys." + _SSH_AGENT_REG_FAILED=1 fi } _unlock_agents_file