Tag cloud shell script

As an interesting challenge, I wanted to output a tag cloud (aka. word cloud) for a text file using standard shell tools. The result is surprisingly fast (2 minutes to create the tag cloud for War and Peace), and surprisingly short: As you can see, less than 10 lines doing anything more complex than echo. The latest version is much more flexible, but the main work is still just some 20 lines (tr -s … and below), and it’s still fast.

If you do anything more fancy with this, I’d be interested to know about it. I’ve got a couple ideas, but I’m not sure if I’ll ever get around to them:

  • Exclude words from another file
  • Multiple word tags from another file

Example usage:
txt2cloud.sh < foo.txt > foo.xhtml

Update: The code is now on GitHub. Fork away!

Delicious bookmarks search in the shell

fil.tero.us is no more, long live filterous! After much deliberation (and switching to a more productive platform & programming language), I decided to re-implement the Delicious personal bookmarks search page in Python for the *nix shell. The result is more security (I don’t store your bookmarks for you), more uptime, and more opportunity for parsing with shell tools such as less, wc, sort and grep.

  1. Install / upgrade: sudo apt-get install libxslt1-dev && sudo easy_install -U filterous
  2. Download your bookmarks
  3. Usage: filterous --help

Guest uploader setup script

Just slammed together a script to add users and give them access to the “upload” user directory.

Edit: Sorry for the updates, it turned out the first version was not optimal.

#!/bin/sh

# Usage: uploader [username ...]

error()
{
	test -t 1 && {
		tput setf 4
		echo "$1" >&2
		tput setf 7
	} || echo "$1" >&2
	exit 1
}

users="upload $*"

for user in $users
do
	# Create user if necessary
	id $user 1>/dev/null 2>&1
	if [ "$?" -ne "0" ]
	then
		useradd --groups upload --comment "Upload user" $user && \
		echo "Created upload user '${user}'." || \
		error "Could not create upload user '${user}'."
	fi
done

# Disable upload password
usermod --lock upload

# Files
chown -R upload:upload ~upload || \
error "Could not change owner of upload home dir"
chmod -R ug+rwX,o= ~upload || \
error "Could not change rights of upload home dir"