Skip to content

Instantly share code, notes, and snippets.

@matchaxnb
Last active June 3, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matchaxnb/ffda100e558f0a47a31132b7be12e790 to your computer and use it in GitHub Desktop.
Save matchaxnb/ffda100e558f0a47a31132b7be12e790 to your computer and use it in GitHub Desktop.
GitLab-URL
#!/bin/sh
# Take a local path. Make the GitLab URL for it. Assumes you use git remotes for Fetch
TGT=$(realpath $1)
GITLAB_SERVER="${GITLAB_SERVER:-https://gitlab.com}"
the_remote_path=$(git -C $(dirname "$TGT") remote show -n origin | grep Fetch | head -n 1 | cut -d: -f3)
the_root_path=$(git -C $(dirname "$TGT") rev-parse --show-toplevel)
the_remote_path=${the_remote_path%.git}
the_active_branch=$(git -C $(dirname "$TGT") symbolic-ref --short HEAD)
the_rel_path=${TGT#${the_root_path}}
echo "${GITLAB_SERVER}/${the_remote_path}/-/blob/${the_active_branch}${the_rel_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment