The power of git command line interface
Examples about how to use git CLI.
You need install beautiful percol developed by mooz by run pip install percol
.
percol "adds flavor of interactive filtering to the traditional pipe concept of UNIX shell".
Append below code into ~/.bashrc
and run source ~/.bashrc
:
function gurl () {
if [ -z "$1" ]; then
echo "Usage: gurl commit-id"
echo "get the full http url of commit"
else
local msg=`git remote -v|grep "origin\s\+.*\s\+(fetch)"|sed -e "s/origin\s\+\(.*\)\s\+(fetch)/\1/"`
local url=""
# github
if [ "${msg:0:14}" == "git@github.com" ]; then
echo https://github.com/`echo ${msg}|sed -e "s/^git\@github\.com\:\(.*\)\.git$/\1/"`/commit/$1
fi
fi
}
# pick commit id from `git log`
function gcid () {
local commit_id=`git log --pretty=format:'%h %ad %s (%an)' --date=short|percol|sed -e"s/^\([a-z0-9]\+\)\s\+.*$/\1/"`
echo ${commit_id}
}
#pick commit from `git log` and output its url
function gqurl () {
local commit_id=`git log --pretty=format:'%h %ad %s (%an)' --date=short|percol|sed -e"s/^\([a-z0-9]\+\)\s\+.*$/\1/"`
gurl ${commit_id}
}
Now you have three bash functions gurl
, gcid
, gqurl
.
Here is demo how to use gcid
:
Here is demo of gqurl
:
BTW, I use CLI clipboard tool like xsel. For example, "echo hello|xsel -ib" which insert string "hello" into system clipboard.
so I can git show `gcid`|xsel -ib
to copy/paste the code of specific commit between terminal and firefox.