aboutsummaryrefslogtreecommitdiffstats
path: root/addkey
blob: 5f7a13a2290474fcc161f18a4369c3626a02a307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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