aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2018-06-04 15:09:08 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2018-06-04 15:09:08 +0300
commit030637d7c4cbc9a813998bb23bd025cd3926fd8e (patch)
tree55971879e4d97f45ffaf8411af2cf42bd40c3961
parent.xsessionrc: use ~/.dbus.sh instead of ~/.dbus/Xdbus (diff)
downloadlinux-home-030637d7c4cbc9a813998bb23bd025cd3926fd8e.tar.gz
linux-home-030637d7c4cbc9a813998bb23bd025cd3926fd8e.zip
spawn_ssh_agent: refactoring
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_profile11
1 files changed, 7 insertions, 4 deletions
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