Fork是一个好用的git工具,之前一直是使用source tree,但是经常遇到崩溃,经过同事推荐开始用上了Fork.
Fork工具中内置了脚本工具
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/')
# 构建 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}"
# 拼接后续数据
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 # 构建 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# 拼接后续数据\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"
}
]
下面是脚本写好效果.
点击后可以快速跳转到gitlab中的new merge request 页面
按道理应用中应该自带这个功能(Fork的blog里面有win版本的效果),不知道是仓库权限问题,还是工具不支持,我用source tree创建拉取请求也没有效果...
所以写了这个脚本.主要是为了将ssh地址转换成https并且携带一些默认参数.like 当前分支名称,方便快速发起请求....
github上面一些custom-commands
https://gist.github.com/oktomus/e284923a7fce837615bb756a1060e5dc
如果有好用的commands 欢迎写到评论区...