aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2018-06-04 18:05:08 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2018-06-04 22:00:02 +0300
commit374e073d5e648f3506e646b015f3bbf3925c64f6 (patch)
tree19fe9b4fd29c30ddcadf053dbe5bb60a1b2f844c /%HOME%/.bash_utils
parent.xsessionrc: refactoring (diff)
downloadlinux-home-374e073d5e648f3506e646b015f3bbf3925c64f6.tar.gz
linux-home-374e073d5e648f3506e646b015f3bbf3925c64f6.zip
move ssh-related stuff to ssh.sh
spawn_ssh_agent no longer creates ~/.ssh_agent.sh, because in cron jobs it's pretty useless actually, since they are typically run when I'm not connected via ssh.
Diffstat (limited to '%HOME%/.bash_utils')
-rw-r--r--%HOME%/.bash_utils/ssh.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/%HOME%/.bash_utils/ssh.sh b/%HOME%/.bash_utils/ssh.sh
new file mode 100644
index 0000000..fa92088
--- /dev/null
+++ b/%HOME%/.bash_utils/ssh.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2018 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Linux/Cygwin environment" project.
+# For details, see https://github.com/egor-tensin/linux-home.
+# Distributed under the MIT License.
+
+kill_ssh_agent() {
+ [ -n "${SSH_AGENT_PID:+x}" ] && kill "$SSH_AGENT_PID"
+}
+
+spawn_ssh_agent() {
+ local output
+ [ -z "${SSH_AGENT_PID:+x}" ] \
+ && command -v ssh-agent > /dev/null 2>&1 \
+ && output="$( ssh-agent -s )" \
+ && eval "$output" > /dev/null \
+ && [ -n "${SSH_AGENT_PID:+x}" ] \
+ && echo "Spawned ssh-agent with PID: $SSH_AGENT_PID." \
+ && trap kill_ssh_agent EXIT
+}
+
+alias ssh-copy-id='ssh-copy-id -i'