Skip to content

Commit 21beac5

Browse files
Create git_http_to_ssh.sh
1 parent d2439dd commit 21beac5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

git_http_to_ssh.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
function git_http_to_ssh {
4+
local name=${1}
5+
local name=${name:=origin}
6+
local url=$( git remote get-url $name )
7+
[[ "$url" =~ (http[s]?)://(.+)/(.+)/(.+)(\.git)? ]]
8+
local protocol="${BASH_REMATCH[1]}"
9+
if [ \( "$protocol" == "http" \) -o \( "$protocol" == "https" \) ] ;then
10+
local provider="${BASH_REMATCH[2]}"
11+
local team="${BASH_REMATCH[3]}"
12+
local prj="${BASH_REMATCH[4]}"
13+
local ext="${BASH_REMATCH[5]}"
14+
company=$(fgrep Host ~/.ssh/config | fgrep -v Hostname | cut -d' ' -f2)
15+
if [ X"${company}" != "X" -a X"${provider}" == "Xbitbucket.org" -a -f "~/.ssh/id_rsa_${team}" ] ;then
16+
provider="${company}"
17+
fi
18+
git remote set-url $name "git@${provider}:${team}/${prj}${ext}"
19+
git remote set-url --push $name "git@${provider}:${team}/${prj}${ext}"
20+
fi
21+
}
22+
git_http_to_ssh $@

0 commit comments

Comments
 (0)