Alfred appreciation post
This post, as the name suggests, is more of an appreciation post. Today, I’m appreciating Alfred. Who’s Alfred, you ask? Well Alfred is my butler!
Nah, not really. I don’t have a butler. But what I do have is nothing short of a butler when it comes to serving files on a network. Alfred is a simple, easy to use command line tool I made sometime ago to, well, share files on a network. ‘Why, oh why’ you ask, when there’s already a million local network sharing applications out there. Two reasons; one, I needed a light local-network file sharing utility that’s simple enough to get going without any configurations and yet good enough to serve multiple files and folders to a number of users. And second, I wanted hands-on with Python, this was a fairly easy task, and a little motivation from someone very awesome, I was convinced I wanted to do this. Now, of course, I could just use Python’s default SimpleHTTPServer, but that plan goes straight out the window when you want to share the files with like a dozen of your friends (taking turns to download isn’t a thing). Ergo, Alfred. Though it was never meant to be anything worth blogging about, I clung to it long enough to make it a useful daily use tool. Alfred can handle multiple connections at once, and over the time, evolved into a pretty nice utility that I practically use everyday. So here’s some stuff Alfred can do:
Serve directories (the basics)
Serve the any directory over the localhost. You can specify a path to the directory you want to served, or you can just skip it and the current one will be served. Default port is 8021
, but you override that from the command line.
$ alfred serve # Serve current directory
$ alfred serve --path /path/to/directory/ # Serve directory at given path
Now you may be wondering why the additional serve
argument. One word, aesthetics.
Serve single files
It often happens that I just want to serve a single file, and not the whole directory. This can be because either I don’t want you to see what’s in that directory (things better left in the dark ) or I’m too polite to make you sift through my deeply nested folders or excessive number of files for what you need. So simply,
$ alfred serve --path /path/to/file # Serve a file
Yup, the same syntax. Just make it a path to a file and Alfred will serve it individually.
Share links and text
Another cool thing I always find handy is sharing text snippets, code snippets or links. It’s too cumbersome to share such snippets on WhatsApp or Messenger. And Slack won’t work for people not in your team. So, here’s a quick command for it:
$ alfred serve --text 'Lorem ipsum dolor set amit.'
There’s actually more than just this, so here’s a table of the parameters and what they do:
Arguments | Purpose |
---|---|
-h, –help | show this help message and exit |
-p PORT, –port PORT | specify port to host server on (default: 8021) |
-c COUNT_MAX, –count-max COUNT_MAX | maximum number of times directory can be served (default: 10000) |
-f, –force-port | force the server to run on specified port (server won’t start if port unavailable) |
-P PATH, –path PATH | specify path (file or directory) to be served (overrides –directory) |
-t TEXT, –text TEXT | specify text to be served (enter text in quotes) |
And of couse, all the code is available on Github under MIT License (as usual). So feel free to hack as you will.
Yeah, I know what you’re thinking right now. ‘Why on EARTH would someone make such a big deal of so little a thing.’ Overkill, I get it. But I guess I just keep adding stuff to it that I often need, and accidentally made it this unnecessarily powerful command ine utility that has really no reason to be so. Ah well, typical me. And guessing by the way I tend to overdo things, you can expect some more “features” added to Alfred (I don’t know them yet either, but let’s see )