Windows-like shortcuts on Linux

It's been close to a year since I started using Fedora as my "get sh*t done" operating system. I am quite the fan of the GNOME desktop environment and that's what drew me in in the first place. But...

Recently I was browsing around the web and wanted to save a link to a cool reddit thread I found. At first, I was like "ok, let me bookmark this!". But then, I looked at my bookmark's bar and it was a TOTAL mess! I thought to myself "If I bookmark this page, I will probably just forget it even exists.". This is very rational thinking since it would get lost in the sea of "Cool! Lemme save this and then forget about it" links.

Second choice would be to download the whole page as an HTML file. Yep this would work and it would probably be a good choice for preserving the content in case it gets taken down in the future. The problem with downloading the whole page though is that the downloaded version most times doesn't look like the online one. There's missing CSS, fonts, elements not scaling corectly etc.

So then I remembered! "Hey! There's these things called shortcuts! Windows had them but what about GNOME/Linux? Does it have shortcuts?" I quickly fired up Nautilus (or Files if you prefer the new naming), right clicked but saw no option to create a shortcut...After a bit of Googling, I learned that XDG supports Internet shortcuts by making a .desktop file containing the url. However this only worked if the .desktop file is saved in the ~/Desktop directory. But GNOME doesn't "have" a Desktop. Everything put in there is not shown by default.

So I decided to bring out the big guns! After a little bit of scouring the HTML and Bash docs, I made an exportable funtion called shortcut that creates an HTML file which automatically redirects to a given link.

Here it is:

# Write an HTML file acting as an Web shorcut
# $1 is the URL, $2 is the name of the shorcut to save
shortcut() {
  echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url='"$1"'"/></head></html>' > "$2".html
}

If you put this in your ~/.bashrc and export it, you can then type:

shortcut <link> <name_of_shortcut>

in a given dir and a shortcut will be created!

There probably is a way to integrate this with Nautilus but this works for now.