From 030637d7c4cbc9a813998bb23bd025cd3926fd8e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 4 Jun 2018 15:09:08 +0300 Subject: spawn_ssh_agent: refactoring --- %HOME%/.bash_profile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to '%HOME%/.bash_profile') diff --git a/%HOME%/.bash_profile b/%HOME%/.bash_profile index 317adae..fb2b58f 100644 --- a/%HOME%/.bash_profile +++ b/%HOME%/.bash_profile @@ -2,10 +2,15 @@ echo "Welcome to $( hostname )" +kill_ssh_agent() { + [ -n "${SSH_AGENT_PID:+x}" ] && kill "$SSH_AGENT_PID" + local output_path="$HOME/.ssh_agent.sh" + rm -f -- "$output_path" +} + spawn_ssh_agent() { # This spawns ssh-agent and exports its variables to ~/.ssh_agent.sh, # to be used in cron jobs and such. - local rm_ssh_agent local output_path="$HOME/.ssh_agent.sh" [ -z "${SSH_AGENT_PID:+x}" ] \ && command -v ssh-agent > /dev/null 2>&1 \ @@ -15,9 +20,7 @@ spawn_ssh_agent() { && source "$output_path" > /dev/null \ && [ -n "${SSH_AGENT_PID:+x}" ] \ && echo "Spawned ssh-agent with PID: $SSH_AGENT_PID." \ - && command -v printf > /dev/null 2>&1 \ - && rm_ssh_agent="$( printf -- 'kill %q' "$SSH_AGENT_PID" )" \ - && trap "$rm_ssh_agent" EXIT + && trap kill_ssh_agent EXIT } spawn_ssh_agent -- cgit v1.2.3