# Copy github permalink for selected file and line

**URL:** <https://discuss.kakoune.com/t/copy-github-permalink-for-selected-file-and-line/2843>\
**Category:** Recipes & Guides\
**Created:** [February 22, 2026, 12:32pm UTC](https://discuss.kakoune.com/t/copy-github-permalink-for-selected-file-and-line/2843 "2026-02-22T12:32:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erock](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@erock](https://discuss.kakoune.com/u/erock)\
**Post date:** [February 22, 2026, 12:32pm UTC](https://discuss.kakoune.com/t/copy-github-permalink-for-selected-file-and-line/2843/1 "2026-02-22T12:32:30Z")

</div>

Hey all.

In neovim there was a very useful plugin called `gitlinker` which would grab a github permalink for the file and line you currently had selected. [GitHub - linrongbin16/gitlinker.nvim: Maintained fork of ruifm's gitlinker, refactored with bug fixes, ssh aliases, blame support and other improvements.](https://github.com/linrongbin16/gitlinker.nvim)

I was missing it in `kak` so I figured I would try to replicate its core functionality. It uses OSC52 for the copy mechanism.

I figured other kak users might find it useful as well. Cheers!

```auto
define-command copy-github-permalink %{
    evaluate-commands %sh{
        file=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||")
        line="$kak_cursor_line"
        github_remote=$(git config --get-regexp '^remote\..*\.url' | grep github.com | head -1 | awk '{print $2}')
        if [[-z "$github_remote"]]; then
            printf "echo 'error: No github remote found'"
        else
            remote=$(echo "$github_remote" | sed 's|^.*://||;s|^git@||;s|:|/|;s|\.git$||')
            commit=$(git rev-parse HEAD)
            url="https://$remote/blob/$commit/$file#L$line"
            encoded=$(printf %s "$url" | base64 | tr -d '\n')
            printf "set-register '\"' '%s'\n" "$url"
            printf "nop %%sh{ printf '\\e]52;;%s\\e\\\\' '%s' >/dev/tty }\n" "$encoded"
            printf "echo 'Copied github permalink to clipboard'"
        fi
    }
}

map global user u ':copy-github-permalink<ret>' -docstring 'Copy github permalink'

```
