#github #file #range #line #file-io #command-line-tool #source

app grab_github_permalink

a small CLI utility for grabbing a range of a file on Github

6 releases

0.2.0 Mar 26, 2024
0.1.4 Dec 13, 2022
0.1.3 Sep 19, 2022

#106 in #file-io

Download history 10/week @ 2024-07-23 6/week @ 2024-09-24 2/week @ 2024-10-01

182 downloads per month

MIT license

16KB
117 lines

grab github permalink

This is a small Rust program that takes a Github permalink, like

https://github.com/torvalds/linux/blob/master/fs/autofs/dev-ioctl.c#L28-L36

and fetches the lines referred to in the #L${start}-L${finish} bit. In the case of that example link it will produce:

typedef int (*ioctl_fn)(struct file *, struct autofs_sb_info *,
			struct autofs_dev_ioctl *);

static int check_name(const char *name)
{
	if (!strchr(name, '/'))
		return -EINVAL;
	return 0;
}

Usage

You can install this from crates.io or clone this repo and build from source, there's nothing fancy going on here build-wise.

Then you can

grab_github_permalink $URL

and it will just spit it to STDOUT. I'd suggest piping to pbcopy or xsel or whatever you have handy!

Markdown mode

If you pass the --markdown / -m flag then it will spit out the code snippet formatted as a Markdown code block with a link to the original. The example link above will come out like this:

fs/autofs/dev-ioctl.c:L28-L36

typedef int (*ioctl_fn)(struct file *, struct autofs_sb_info *,
			struct autofs_dev_ioctl *);

static int check_name(const char *name)
{
	if (!strchr(name, '/'))
		return -EINVAL;
	return 0;
}

Dependencies

~11–24MB
~352K SLoC