July 2, 2024

An IntelliJ plugin for GitHub permalinks

I am a frequent user of the GitHub permalink feature. You can open a file in a repository on GitHub, select a line or a range of lines, and create a link to it. Anyone who opens this link will see this code location highlighted. The “perma” part means that the link stays valid if the file is changed in future commits. This works because the link also references the commit that the code was on when you viewed the file.

I use this feature when creating bug tickets to highlight problematic code, in tickets for new features to highlight where new functionality should be added, or in the chat to precisely show the code that I am talking about. For example, if I would want to quickly point someone to the code that generates the usernames for ActivityPub.Academy, I would send them this permalink.

Usually, I use IntelliJ to navigate through code. I can use my keyboard shortcuts to navigate through files, jump to definitions and to places where some code is used, and so forth. So to create a permalink for a location that I want to reference, I used to use IntelliJ to find this location, then switch to GitHub, open the file there, jump to the line I am interested in, and create the permalink. This workflow becomes annoying pretty quickly. But even though I use this feature several times a week, it took me quite a while to realize that this is an ideal candidate for an IntelliJ plugin. I got a bit excited, because I thought that this would be a pretty good candidate to get into IntelliJ plugin development. But of course someone already created a plugin for this: the Copy Git Link by Ryo Kawamata.

This plugin does everything that I would expect from it, and more. It works for GitHub, but also for Gitlab and Bitbucket, and it can create links in Markdown format.

The plugin comes with predefined keyboard shortcuts, but I use the IdeaVim Plugin, so I created my own bindings. I’m using

nmap <space>sl <Action>(com.github.kawamataryo.copygitlink.CopyPermalink)
vmap <space>sl <Action>(com.github.kawamataryo.copygitlink.CopyPermalink)

I’m using <space> as my leader. This means that after navigating to the code location I am interested, I only need to press <space>sl to copy the corresponding permalink to my clipboard, avoiding the dance to open GitHub in the browser and finding the same code location there again.

—Written by Sebastian Jambor. Follow me on Mastodon @crepels@mastodon.social for updates on new blog posts.