gitr: copy git remote

Too often I found myself needing the repo URL of the git repository I am currently working in.

Of course, you can always type git config --get remote.origin.url but who has time for that?

If you source the following file in your shell, you will then have access to gitr which will output the git remote URL, and you can open $(gitr) to quickly open the URL in your browser.

You will also have access to cgitr which will copy the git remote to your clipboard so you can quickly paste it anywhere you need to. cgitr.sh
#!/bin/bash
copyfx=''
if [[ `uname` -eq 'Darwin' ]]; then
	copyfx='pbcopy'
elif [[ `uname` =~ "cygwin"* ]]; then
	copyfx='putclip'
else
	copyfx='xclip'
fi
function gitr () {
	git config --get remote.origin.url | tr -d '\n'
}
function cgitr () {
	gitr | tr -d '\n' | $copyfx
}
if [[ "$0" != "$_" ]]; then
	`cgitr`
fi


code

last updated 2024-03-18