diff --git a/.bash_logout b/.bash_logout index 9d39b6e..d54b32b 100644 --- a/.bash_logout +++ b/.bash_logout @@ -1,7 +1,7 @@ #!/bin/bash - not strictly necessary, but helps nano with syntax highlighting. # Clear the screen/console on logout. -if (( $SHLVL == 1 )); then +if (( SHLVL == 1 )); then if [[ -x /usr/bin/clear_console ]]; then /usr/bin/clear_console -q elif [[ -x /usr/bin/clear ]]; then @@ -9,6 +9,19 @@ if (( $SHLVL == 1 )); then elif [[ -x /usr/bin/tput ]]; then /usr/bin/tput clear else - echo -ne "\E[2J" + echo -ne "\e[2J" fi fi + +hash ssh-add ssh-agent >/dev/null 2>&1 && { + # Stop any started ssh-agent as long as the shell level is 1 and we're not on a tty. + (( SHLVL == 1 )) && [[ "$(tty)" == /dev/pts/* ]] && [[ -n "$SSH_AGENT_PID" ]] && { + ssh-agent -k + (( $? != 0 )) && printf "\\033[1;31;40m%s\\033[0;39m\\n" "Failed to stop ssh-agent." >&2 + sleep 5 + unset SSH_AGENT_PID SSH_AUTH_SOCK + } + + # Update the ~/.ssh/agents file. + __read_ssh_agents && __write_ssh_agents +}