ruby one-liners as random signatures for blog posts and emails
The random sigs appearing below are due to some simple features of Vim (and bash).
1. Create sig files by splitting a tips/oneliners file. I found a ruby1liner file on the internet and split it based on ‘^#’. The file names are now ruby.1, ruby.2 etc. A tgz of these is here.
You can split the file using split or csplit. Since my split did not, and csplit seems buggy, I wrote a ruby program to do so, csplit.rb.
You may unzip the above tgz in some convenient folder.
2. A script is needed to return a random file from that folder. The
jot command is great for returning random numbers. The
60 signifies the number of the highest file (60 sig files). rubysig.sh:
cat $DIR/ruby.`jot -r 1 1 60`
3. Your editor needs to pick up a random file when it loads a new file and insert it at the correct place. I use the Movable Type format, so my sig must go after the 3 hyphens. After placing the sig, I’d like the cursor to come back to one line after the BODY tag. I placed the following lines in a source file that my editor Vim can understand. The second line is the one that does the work.
You may use a Vim command-line option to go to end of file (+) but I already have some links at the end so the extra steps.
This is how the new file is created.
vim -s ~/bin/y.so filename.html
I could also have just said:
vim + -c ':r !rubysig.sh' file.html
This would put the sig at the end of the file. Check your Vim options with
If you use a mail client such as mutt or alpine, the command
rubysig.sh can be used to generate the sgnature.
# print every 3rd line starting at line 4
$ cat | ruby -pe ‘next unless $. >= 4 && $. % 3 == 0’