Skip to content

Instantly share code, notes, and snippets.

@fliphess
Last active February 19, 2020 13:24
Show Gist options
  • Save fliphess/568e29244b21f21fdb84de52480bf52b to your computer and use it in GitHub Desktop.
Save fliphess/568e29244b21f21fdb84de52480bf52b to your computer and use it in GitHub Desktop.

Revisions

  1. fliphess revised this gist Feb 19, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion git-link
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    #!/usr/bin/env python3
    import configparser
    import os
    import sys
    import subprocess
  2. fliphess created this gist Jan 15, 2020.
    28 changes: 28 additions & 0 deletions git-browse
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env bash

    function usage() {
    cat <<EOF
    Open current git repo in your browser
    Arguments:
    --pipe - Show pipeline
    --cr - Show container registry
    --mr - Show merge requests
    EOF
    exit 1
    }

    GITLINK="$( git-link | sed -e 's/\.git//' )"

    if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
    usage
    elif [ "$1" == "--pipe" ] ; then
    GITLINK="$GITLINK/pipelines"
    elif [ "$1" == "--cr" ] ; then
    GITLINK="$GITLINK/container_registry"
    elif [ "$1" == "--mr" ] ; then
    GITLINK="$GITLINK/merge_requests"
    fi

    /usr/bin/open "$GITLINK"
    23 changes: 23 additions & 0 deletions git-link
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/usr/bin/env python3
    import configparser
    import os
    import sys
    import subprocess


    def main():
    try:
    command = "git remote -v | grep ^origin | awk '/push/ {print $2}'"
    url = subprocess.check_output(command, shell=True)
    url = url.decode().strip()
    except Exception as e:
    print("Error: {}".format(e))
    sys.exit(1)

    if url.startswith('git@'):
    url = url.replace(':', '/').replace('git@', 'https://')
    print(url)


    if __name__ == "__main__":
    main()