"Badges? We ain't got no badges. We don't need no badges. I don't have to show you any stinking badges!" Ok, I got that out of the way. If you don't know that popular reference, I suggest you watch The Treasure of the Sierra Madre.
This is a quick post to demonstrate a very simple edit to your GitHub repository's readme.md page which will reveal to visitors how many lines of code are available. Lines of code? We don't need no Lines of Code. I don't have to show... ok, let's not have that old argument. Let's just assume that Lines of Code does mean something to some people, for some reason.
First off, you certainly have choices. There is more than one free line of code badge service for use with GitHub (and GitLab.) I settled on Tokei which is a code counter written in Rust which claims support for 170 languages, including our favorite Pascal/Delphi.
In only takes a few seconds to add your badge. Simply visit your repo on GitHub and edit your readme.md page directly on the site (or edit locally and push the change) You'll typically want to add an image link somewhere near the top line of your page. The image link source will refer to the Tokei webservice which will scan your repo and report back the lines of code in a badge displayed as an SVG image. (Note that the very first image view can take a few seconds to show up, but it's amazingly quick even for large repositories.)
For example, a popular repository on GitHub for Delphi users is the JEDI Code Library found at https://github.com/project-jedi/jcl. To create a badge, you'll follow the URL scheme for Tokei:
So, in order to add a Tokei code badge to the Jedi repo, you would insert this simple markdown image reference:
Which yields this live line of code badge:
The image is SVG-based and for the super curious, the raw content returned right now is:
Very cool! With one simple line of markdown, you can have a live line-of-code badge on your repo. (I just created pull request #77 asking JCL to update their readme with this badge.)
Here are some live badges (captured in static image form for use with this blog article) for a few other popular Delphi related GitHub repos:
By default, the badge displays lines of code. You can have multiple badges, each with a category parameter. Current category choices available include: code, blanks, files, lines, and comments.
Here are all of the available live Tokei badges for the JCL repo. (Note: I captured an image of the live code badges to speed up display of the blog article.)
It couldn't get much simpler to add live badges to your GitHub repos. And thankfully this particular tool supports Delphi code, which is sometimes difficult to find these days.