-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathgit-credential-lastpass
More file actions
executable file
·59 lines (49 loc) · 1.17 KB
/
git-credential-lastpass
File metadata and controls
executable file
·59 lines (49 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# A credential helper for git to retrieve usernames and passwords from lastpass.
# For general usage, see https://git-scm.com/docs/gitcredentials.
# Here's a quick version:
# 1. Put this somewhere in your path.
# 2. git config --global credential.helper lastpass
declare -A params
if [ "x$1" == "x-l" ]; then
shift
lpassuser=$1
shift
fi
if [ "x$1" == "xget" ]; then
read line
while [ -n "$line" ]; do
key=${line%%=*}
value=${line#*=}
params[$key]=$value
read line
done
if [ "x${params['protocol']}" != "xhttps" ]; then
exit
fi
if [ -z "${params["host"]}" ]; then
exit
fi
lpass ls > /dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -z "$lpassuser" ]; then
read -p "Lastpass username: " lpassuser < /dev/tty > /dev/tty
fi
if [ -z "$lpassuser" ]; then
exit
fi
lpass login $lpassuser > /dev/null
if [ $? -ne 0 ]; then
echo "Failed to login to lastpass" > /dev/stderr
exit
fi
fi
user=`lpass show --username ${params["host"]}`
pass=`lpass show --password ${params["host"]}`
if [ "x$user" == "x" ] || [ "x$pass" == "x" ]; then
echo "Couldn't find host in lastpass DB." > /dev/stderr
exit
fi
echo username=$user
echo password=$pass
fi