#!/bin/bash
git-remote-url() {local rmt=$1; shift || { printf "Usage: git-remote-url [REMOTE]\n" >&2; return 1; }local url
if ! git config --get remote.${rmt}.url &>/dev/null; thenprintf "%s\n" "Error: not a valid remote name" && return 1# Verify remote using 'git remote -v' commandfi
url=`git config --get remote.${rmt}.url`
# Parse remote if local clone used SSH checkout[[ "$url" == git@* ]] \&& { url="https://github.com/${url##*:}" >&2; }; \{ url="${url%%.git}" >&2; };
printf "%s\n" "$url"}
用法:
# Either launch a new terminal and copy `git-remote-url` into the current shell process,# or create a shell script and add it to the PATH to enable command invocation with bash.
# Create a local clone of your repo with SSH, or HTTPSgit clone git@github.com:your-username/your-repository.gitcd your-repository
git-remote-url origin
git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'
https://gitlab.com/company/product/production.git
alias git-repo="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'"alias git-pr="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g' | sed 's/....$//' | sed -ne 's/$/\/pulls &/p'"