Now I like a good screensaver and phosphor (written by Jamie Zawinski) is one of them. Phosphor emulates an old green monochrome terminal screen with a very long afterglow (due to the phosphor). Phosphor can be used in many ways. You can configure it to get its output from a file, URL or from a program. It can even emulate a VT100 so you can use terminal control characters. You could recreate some visicalc screens and old stuff like that, whatever keeps you ticking.
Now Jason Kress thought that it might be cool to display random Linux kernel source files using the phosphor screensaver and I like that. Jason created a small C-program to select a random file from all
.c files found using the
find command. I don’t like the fact that
find has run to completion before a file is selected. Please keep in mind that the linux kernel has well over 9000
.c files. When I start my screensaver I’m taking a break. Possibly because my computer is compiling. I don’t want the screensaver hamper my compilation with a heavy
find command on the disk.
So forget about Jasons solution. I created my own which uses a small shell script that creates a somewhat larger Perl script but it doesn’t require
find at runtime anymore. How about that? The code to efficiently read a random line from an input source is straight from the Perl Cookbook. Here’s the small shell script. I called it
create-phosphor-kernel-script.sh but you can name it whatever you like. By the way I installed this in
#!/bin/sh file=phosphor-kernel-src.pl # script to create linux_src_dir=/usr/src/linux # location of kernel src cat << EOF > "$file" #!/usr/bin/perl srand; rand(\$.) < 1 && (\$line = \$_) while <DATA>; print \$line; __DATA__ EOF find -L "$linux_src_dir" -name \*.c >> $file chmod 555 $file
So copy & paste the above script and save it in a text-file somewhere. Change the file if needed. You can change the definition of
file=phosphor-kernel-src.pl to rename the generated script. You can change the definition
linux_src_dir=/usr/src/linux to indicate where your linux kernel sources are. When you are done changing the scripts to your preferences make the script executable and execute it.
Now you will have a generated perl script that contains all
.c files in the specified linux source directory and randomly selects one without going through the linux source directory all the time. This saves you a lot of time and computing and disk I/O when the screensaver selects a random file. However you do need to remember to regenerate that script whenever you upgrade your linux kernel or else you may miss new files (and get errors on removed files). Now in my setup the generated perl script lives here:
Now you can configure your phosphor screensaver like this:
Mind the backticks. Whenever one file is done a new one is randomly selected. Enjoy. NERD!