The power of git command line interface

  |   Source

power of git command line interface :en:git:percol:bash:linux:

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"
        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}" == "" ]; then
            echo`echo ${msg}|sed -e "s/^git\@github\.com\:\(.*\)\.git$/\1/"`/commit/$1

# 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: git-percol-001.gif

Here is demo of gqurl: git-percol-002.gif

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.

Comments powered by Disqus