Fork是一個好用的git工具,之前一直是使用source tree,但是經(jīng)常遇到崩潰,經(jīng)過同事推薦開始用上了Fork.

Fork.jpg
Fork工具中內(nèi)置了腳本工具

Fork-commands.png
fork工具的custom commands 存儲的位置位于
~/Library/Application Support/com.DanPristupov.Fork/
# 給定的字符串
# address="ssh://git@gitlab.xxxxx.cn/xxx/xxx.git"
address=$(git config --get remote.origin.url)
# echo "$address"
# SSH 地址的正則表達式模式
ssh_pattern="^ssh:\/\/.*@.*$"
# 進行匹配判斷
if [[ $address =~ $ssh_pattern ]]; then
# echo "是 SSH 地址"
# 原始 SSH 地址
# ssh_address="$address"
# 提取主機部分
host=$(echo "$address" | sed -e 's/ssh:\/\/.*@\(.*\):[0-9]*\/.*/\1/')
# 提取路徑部分
http_path=$(echo "$address" | sed -e 's/ssh:\/\/.*@.*:[0-9]*\(\/.*\)/\1/')
# 構(gòu)建 HTTP 地址
http_address="https://$host$http_path"
# echo "$http_address"
# else
# echo "不是 SSH 地址"
fi
# 給定的 SSH 地址
address="$http_address"
# 刪除端口號
http_address=$(echo "$address" | sed -e 's/ssh:\/\/.*@\(.*\):[0-9]*\//https:\/\/\1\//')
http_address="${http_address%.git}"
# 拼接后續(xù)數(shù)據(jù)
merge_request_data="/merge_requests/new?merge_request%5Bsource_branch%5D=${ref}"
merge_request_data="$merge_request_data"
final_url="$http_address$merge_request_data"
# echo "$final_url"
open "$final_url"
下面是我的custom-commads.json
[
{
"version" : 1
},
{
"action" : {
"script" : "#!\/bin\/bash\n\n# 給定的字符串\naddress=$(git config --get remote.origin.url)\n# echo \"$address\"\n# SSH 地址的正則表達式模式\nssh_pattern=\"^ssh:\\\/\\\/.*@.*$\"\n\n# 進行匹配判斷\nif [[ $address =~ $ssh_pattern ]]; then\n# echo \"是 SSH 地址\"\n\n # 原始 SSH 地址\n # ssh_address=\"$address\"\n\n # 提取主機部分\n host=$(echo \"$address\" | sed -e 's\/ssh:\\\/\\\/.*@\\(.*\\):[0-9]*\\\/.*\/\\1\/')\n \n # 提取路徑部分\n http_path=$(echo \"$address\" | sed -e 's\/ssh:\\\/\\\/.*@.*:[0-9]*\\(\\\/.*\\)\/\\1\/')\n\n # 構(gòu)建 HTTP 地址\n http_address=\"https:\/\/$host$http_path\"\n\n # echo \"$http_address\"\n# else\n# echo \"不是 SSH 地址\"\nfi\n\n\n# 給定的 SSH 地址\naddress=\"$http_address\"\n\n# 刪除端口號\nhttp_address=$(echo \"$address\" | sed -e 's\/ssh:\\\/\\\/.*@\\(.*\\):[0-9]*\\\/\/https:\\\/\\\/\\1\\\/\/')\nhttp_address=\"${http_address%.git}\"\n# 拼接后續(xù)數(shù)據(jù)\nmerge_request_data=\"\/merge_requests\/new?merge_request%5Bsource_branch%5D=${ref}\"\nmerge_request_data=\"$merge_request_data\"\nfinal_url=\"$http_address$merge_request_data\"\n\n# echo \"$final_url\"\n\nopen \"$final_url\"",
"showOutput" : false,
"type" : "sh",
"waitForExit" : true
},
"name" : "Create Merge Request",
"referenceTargets" : [
"localBranch",
"remoteBranch"
],
"target" : "reference"
}
]
下面是腳本寫好效果.

Fork-create.png
點擊后可以快速跳轉(zhuǎn)到gitlab中的new merge request 頁面
按道理應(yīng)用中應(yīng)該自帶這個功能(Fork的blog里面有win版本的效果),不知道是倉庫權(quán)限問題,還是工具不支持,我用source tree創(chuàng)建拉取請求也沒有效果...
所以寫了這個腳本.主要是為了將ssh地址轉(zhuǎn)換成https并且攜帶一些默認參數(shù).like 當前分支名稱,方便快速發(fā)起請求....
github上面一些custom-commands
https://gist.github.com/oktomus/e284923a7fce837615bb756a1060e5dc
如果有好用的commands 歡迎寫到評論區(qū)...