Last active
June 3, 2022 16:30
-
-
Save matchaxnb/ffda100e558f0a47a31132b7be12e790 to your computer and use it in GitHub Desktop.
GitLab-URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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