When I take notes on a technical article I make a new directory with example code to experiment with. In these situations, it’s useful to keep the link to the article in this same directory.
Here’s a script that makes a special ‘weblink’ file, which can be opened later.
# file: ~/bin/mkwl ("make web link")
#!/usr/bin/env fish
source /home/t/.config/fish/global.fish
set url $argv[1]
set filename \
(string sub -s 3 -e 66 \
(string replace 'http:' '' \
(string replace 'https:' '' \
(string replace --all '/' '_' $url)))).weblink
echo "$filename"
echo $url > $filename
So to create a weblink we just do
$ mkwl https://medium.com/@siacavazzi/how-i-made-a-robust-web-scraper-d17060470bd8
And we get
$ ls
'medium.com_@siacavazzi_how-i-made-a-robust-web-scraper-d17060470.weblink'
And now we need a script to open it
# file: ~/bin/owl ("open web link")
#!/usr/bin/env fish
xdg-open (cat $argv[1] | head -n1) >/dev/null 2>&1 &
disown
Make it official
Here’s how we can web links recognized by the OS.
We need a desktop entry
# file: ~/.local/share/applications/weblink.desktop
[Desktop Entry]
Type=Application
Name=Open Web Link
Exec=/home/t/bin/owl %f
MimeType=application/x-weblink;
NoDisplay=true
Terminal=false
And a mime type
# file: ~/.local/share/mime/packages/weblink.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-weblink">
<comment>Web link</comment>
<glob pattern="*.weblink"/>
</mime-type>
</mime-info>