aboutsummaryrefslogtreecommitdiffstats
path: root/addkey
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2015-11-01 16:09:36 +0100
committerEduardo Pedroni <e.pedroni91@gmail.com>2015-11-01 16:09:36 +0100
commit48bd2dee17a7293fe5329534afac31f913dc4b71 (patch)
tree403a9660e84eeb6c4989731af0b0d299886a1b7d /addkey
parentbdd700ee0c78e2908ccc82770cf575055a029e6a (diff)
Initial commitHEADmaster
Diffstat (limited to 'addkey')
-rwxr-xr-xaddkey20
1 files changed, 20 insertions, 0 deletions
diff --git a/addkey b/addkey
new file mode 100755
index 0000000..5f7a13a
--- /dev/null
+++ b/addkey
@@ -0,0 +1,20 @@
+#!/usr/bin/env zsh
+#
+# Adds the specified key to the agent if one is running, optionally for the specified time. The default lifetime is forever if not specified.
+# Usage is as such: addkey <key> [time]
+# where key is the name of the private key file, and time is an optional timeout in seconds
+
+if [ $# -eq 0 ]; then
+ echo "No arguments provided, usage: addkey <key> [time]"
+ exit 1
+fi
+
+if [ -z "$(ssh-add -l | grep "$HOME/.ssh/$1")" ]; then
+ if [ -z $2 ]; then
+ ssh-add ~/.ssh/$1
+ else
+ ssh-add -t $2 ~/.ssh/$1
+ fi
+else
+ echo "$1 is already in the agent"
+fi