Created
October 6, 2024 20:53
-
-
Save lf94/9be1f21ff46d814358a36dafc4118d76 to your computer and use it in GitHub Desktop.
Generate GitHub URLs from code selections
This file contains hidden or 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
def git-link-yank %{ | |
nop %sh{ | |
url="$(git remote get-url origin | sed -e 's/:/\//' -e 's/git@/https:\/\//' -e 's/\.git//')/blob" | |
branch="/$(git status -b --porcelain=v2 | grep branch.oid | cut -d ' ' -f 3)" | |
top=$(git rev-parse --show-toplevel | sed 's/\//\\\//g') | |
path=$(echo -n "$kak_buffile" | sed "s/$top//") | |
line1="#L$(echo $kak_selection_desc | sed 's/\..*$//')" | |
line2="-L$(echo $kak_selection_desc | cut -d ',' -f 2 | sed 's/\..*$//')" | |
printf "%s%s%s%s" "$url" "$branch" "$path" "$line1" "$line2" | xsel -b | |
} | |
} | |
map global normal <c-y> ': git-link-yank<ret>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment