Commit 1b58187

xxwhirlpool  ·  2026-06-27 22:49:49 -0400 EDT
parent fe6fd6c
`urlref`, misc stuff
5 files changed,  +89, -5
+2, -0
1@@ -51,5 +51,7 @@ scripts/Scripts/icons
2 scripts/Scripts/gallery.html
3 scripts/Scripts/iconshare_pl/icons/*
4 scripts/Scripts/iconshare_pl/out/*
5+scripts/Scripts/urlref/links.txt
6+
7 config/.local/bin/khal_reminder
8 config/.config/khal/config_reminder
+5, -5
 1@@ -179,11 +179,11 @@ export FZF_ALT_C_OPTS="
 2 export LEDGER_FILE=~/.config/hledger/katmoney.journal
 3 
 4 # perl shit
 5-PATH="/home/kat/perl5/bin${PATH:+:${PATH}}"; export PATH;
 6-PERL5LIB="/home/kat/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
 7-PERL_LOCAL_LIB_ROOT="/home/kat/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
 8-PERL_MB_OPT="--install_base \"/home/kat/perl5\""; export PERL_MB_OPT;
 9-PERL_MM_OPT="INSTALL_BASE=/home/kat/perl5"; export PERL_MM_OPT;
10+PATH="/home/kat/.perl5/bin${PATH:+:${PATH}}"; export PATH;
11+PERL5LIB="/home/kat/.perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
12+PERL_LOCAL_LIB_ROOT="/home/kat/.perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
13+PERL_MB_OPT="--install_base \"/home/kat/.perl5\""; export PERL_MB_OPT;
14+PERL_MM_OPT="INSTALL_BASE=/home/kat/.perl5"; export PERL_MM_OPT;
15 
16 ######################################
17 # functions
+2, -0
 1@@ -6,6 +6,7 @@ die() {
 2 
 3 rollslug=$(gum input --placeholder "enter slug") || die
 4 rollurl=$(gum input --placeholder "enter url") || die
 5+rollfeed=$(gum input --placeholder "enter feed url") || die
 6 rollname=$(gum input --placeholder "enter name") || die
 7 rolltype=$(gum input --placeholder "enter type") || die
 8 
 9@@ -16,6 +17,7 @@ fi
10 cat << EOF >> /home/kat/Projects/mine/eunoia-astro/src/content/blogroll/blogs.yml
11 - slug: $rollslug
12   url: "$rollurl"
13+  feed: "$rollfeed"
14   name: "$rollname"
15   type: $rolltype
16 EOF
+17, -0
 1@@ -0,0 +1,17 @@
 2+# `urlref`
 3+
 4+inspired by [urlref](https://benjaminhollon.com/musings/urlref/) by benjamin hollon, but rewritten as a simple perl script.
 5+
 6+the script takes a URL and saves it in a file with a generated 5-character alphanumeric code (all uppercase, for less confusion when writing it down). when you want to search for a URL by its code, you use the `--get-code` argument.
 7+
 8+## usage
 9+
10+run `urlref.pl` without any arguments to bookmark a URL. the script accepts this through `STDIN`, and will output the code attached to the URL. both the code and the URL are saved on the same line (separated by a space) in `links.txt` in the same directory as the script.
11+
12+to find a URL with a code, use the `--get-code` argument. for example:
13+
14+```pl
15+./urlref --get-code AKB48
16+```
17+
18+this will return the matching code and URL.
+63, -0
 1@@ -0,0 +1,63 @@
 2+#!/usr/bin/env perl
 3+
 4+use 5.38.2;
 5+use strict;
 6+use warnings;
 7+
 8+use Getopt::Long qw(GetOptions);
 9+
10+sub usage {
11+	print("Usage: urlref.pl [--get-code|--help]\n
12+	run without args to add URL\n");
13+	exit 0;
14+}
15+
16+my $getcode;
17+
18+GetOptions(
19+	"get-code=s" => \$getcode,
20+	"help" => \&usage,
21+) or die "\nif you want to get a URL, supply a code: --get-code [CODE]\n";
22+
23+sub encode {
24+	my @chars = ("A".."Z","0".."9","_");
25+
26+	my $string;
27+	$string .= $chars[int(rand(@chars))] for 1..5;
28+
29+	return $string;
30+}
31+
32+sub addurl {
33+	my $url = <STDIN>;
34+	chomp $url;
35+	my $code = encode($url);
36+
37+	if (!length $url == 0) {
38+		print("code is: $code\n");
39+
40+		my $filename = "links.txt";
41+
42+		open(my $fh, ">>", "$filename") or die "could not open $filename: $!";
43+		print $fh "$code $url\n";
44+		close $fh;
45+
46+		print("saved URL to file: $filename\n");
47+	} else {
48+		die("no URL given");
49+	}
50+}
51+
52+if ($getcode) {
53+	my $filename = "links.txt";
54+
55+	open(my $fh, "<", "$filename") or die "could not open $filename: $!";
56+	while(my $line = <$fh>) {
57+		if($line =~ /^$getcode\s/) {
58+			print("found: $line");
59+		}
60+	}
61+	close $fh;
62+} else {
63+	addurl
64+}