Commit 1b58187

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