Openrc

Problem Statement:

After doing git push how many of us wanted to see the

To be generic, you want to open a particular url after an action. How can we achieve it easily ?

Solution:

Put this openrc script file in the path (so that we can invoke this from anywhere) Eg: /usr/local/bin/openrc

Note: Below script depends on git-open, fzf, ripgrep (replace rg with grep if you want)

$ cat /usr/local/bin/openrc
#!/usr/bin/env bash

gitUrl=$(git open -p)
file=".openrc"
if [ -f "$file" ]
then
	echo $gitUrl | cat $file - |rg ^http | fzf --select-1 -m | xargs -I{} open {}
else
    open $gitUrl
fi

Have a file .openrc with list of urls in your repo directory.

openrc.gif

My usecase:

Want to see the result of jenkins pipeline after git push So, my .openrc will be like

$ cat .openrc
http://myjenkins.com/job/my-repo/job/master/

Note: Url should start with http:// or https:// so that open command opens in default browser.

So after pushed, I will do

$ openrc # which opens my jenkins pipeline url for the master branch

Why not plain git-open ?

So started using this script which makes my life easily.

How the script evolved:

alias openrc="cat .openrc | xargs -I{} open {}"
$ alias openrc="grep . .openrc | xargs -I{} open {}"
$ # or
$ alias openrc="rg . .openrc | xargs -I{} open {}"
$ alias openrc="grep . .openrc | fzf --select-1 -m | xargs -I{} open {}"
$ alias openrc="grep ^http .openrc | fzf --select-1 -m | xargs -I{} open {}"
$ alias openrc="echo \$(git open -p) | cat .openrc - |rg ^http | fzf --select-1 -m | xargs -I{} open {}"

Note: The above script will print the error message if the .openrc file is not found. But still it will open the git url in the repo. To fix this, I moved from alias to script.

Comments

comments powered by Disqus