Crates.io | grab_github_permalink |
lib.rs | grab_github_permalink |
version | 0.2.0 |
source | src |
created_at | 2022-09-14 20:37:25.78046 |
updated_at | 2024-03-26 14:38:15.549896 |
description | a small CLI utility for grabbing a range of a file on Github |
homepage | |
repository | https://github.com/alicewriteswrongs/grab_github_permalink |
max_upload_size | |
id | 666084 |
size | 56,650 |
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;
}
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!
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:
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;
}