DEV Community

Discussion on: Open the GitHub project page of a repo from Terminal

Collapse
 
engineercoding profile image
Wesley Ameling

The version for Git Bash (windows). It replaces the open command and for some reason it cannot parse a nested variable modification (line 17)

function GitHub()
{
    if [ ! -d .git ] ;
        then echo "ERROR: This isnt a git directory" && return false;
    fi

    git_url=`git config --get remote.origin.url`
    git_domain=`echo $git_url | awk -v FS="(@|:)" '{print $2}'`
    git_branch=`git rev-parse --abbrev-ref HEAD 2>/dev/null`

    if [[ $git_url == https://* ]];
    then
        url=${git_domain}/${git_url%.git}/tree/${git_branch}
    else
       if [[ $git_url == git@* ]]
       then
            cut_off=${git_url#*:}
            url=https://${git_domain}/${cut_off%.git}/tree/${git_branch}
       else
           echo "ERROR: Remote origin is invalid" && return false;
       fi
    fi
    explorer $url
}
Enter fullscreen mode Exit fullscreen mode