Abstract: We use the Zephyr (MIT messaging sytem) client Barnowl to set our zsig as a randomly selected line from a file consisting of zsigs separated by newlines.
Random Zsig: Intro
Highly recommend background reading: /help.c - barnowl - Trac and the "intro" file at /docs - barnowl - Trac.OR view it inside barnowl.
:help
and :show quickstart
pulls each up respectively. A "zsig" appears after your kusername in Zephyr (see my previous post if you don't know what Zephyr is). By default, if your name is Jane Lillian Doe, your zsig is (Jane L Doe). For instance, if you're on Zephyr, you might see
2013 / personal / jdoe 22:16 (Jane L Doe)
...hey I'm talking here.
A good percentage of people keep it that way, or remove the middle initial. Another set of people leave it at some interesting quote. To do so, as mentioned in the previous entry, :set zsig 'this is a very interesting quote'
However, I had too much time on my hands earlier on in the summer, and so I set up a random zsig generator. It's very simple, actually, 'cos Barnowl is awesome :) Unfortunately, the documentation that I could find online all seemed outdated.Well, the basic theory is that you can write some code that prints stuff out (stdout), and setup Barnowl to run that code, take the stdout, and pipe it to your zsig. (The wikipedia article is kind of technical on "piping", if it doesn't make sense just follow along).
Note: Unless you've gone and figured out Screen, don't start up Barnowl until you need to (I'll mention when).
Here we go!
- Remote connect to Athena.
ssh kusername@linux.mit.edu
- Create a file of zsigs, each separated by a newline. Use "nano" instead of "vi" if you're not familiar with vi, and modify the second set of instructions accordingly. For instance
vi zsigs
i #Enter into Insert mode a zsig random zsig2 random234 :wq #Write the file and quit
- Create a file to store your code
vi .zrandom
- Write a program, for instance:
If you want to use another language (e.g. perl or C), or check out what version is running on Athena, check out What Runs Where on Athena: Languages | IS&T for how to indicate on the first line the language you want.#!/usr/athena/bin/python import random zfile = open('.zsigs') linelist = zfile.read().splitlines() zfile.close() print random.choice(linelist)
The Above Program, Explained
Since I don't program much if at all, I relied on Google to write this program. This progam imports the modulerandom
, which has pre-written functions such as the random.choice()
used later. It opens a file ("~/zsigs") where I've written a list of zsigs I want to choose from randomly. These zsigs are separated by newlines, and so I read each line into a list. For instance, if I add a print linelist
in there, I get this: ['zsig one', '2--this is a random zsig', 'foo', 'etc.']
Once I have it in list form, I can use random.choice()
to randomly choose one of the items in the list. Meanwhile, I exit the "zsigs" file once I am done reading from it. Note: You can test your program, for instance in my case:
nouyang@dr-wily:~$ python .zrandom
www.google.com/search?q=*RECURSION*
The second line should be one of the zsigs from your list. Setting Up Barnowl
Now, there's two ways to accomplish the same thing. We have to set it so that, when Barnowl starts up, it sets your zsig as an empty string. Then, we tell it to run the Barnowl command "zsigproc" and tell it where our zsig program is located. (If you have anything in "zsig" it will take precedence over your "zsigproc" variable). [1]Note: To check what you've set variables as, use
:print variablename
Method 1: Manually
This really shouldn't be first, but when I set up my zsig generator I did it this way, and I learned a bit about Barnowl this way. Skip below for the easier method if you just want to get something working.- Edit the file that Barnowl reads when it starts up. Again, use nano instead of vi if you're not familiar with vi, and modify the second set of instructions accordingly.
vi .owl/startup
i #Enter "Insert" mode set zsig '' set zsigproc '~/.zrandom' # The file where our zsig program is located [Esc] #Escape into command mode :wq #Write the file and quit
- Then open up Barnowl
add barnowl; barnowl
Voila! That's it.
- You can check that Barnowl is setup correctly. This should output
zsigproc = '~/.zrandom'
Also, zsig should be set to an empty string. This should output:print zsigproc
zsig = ''
:print zsig
If you want to force Barnowl to reload the startup file,
:source "~/.owl/startup"
Also, you can zwrite yourself to check that everything's working.
Method 2: Easier
- Open up Barnowl
add barnowl; barnowl
- Use the "
:startup
" command in Barnowl to write to the "~/.owl/startup" file (or wherever you decided to put the file) [2]:startup set zsig '' :startup set zsigproc '~/.zrandom'
- Force Barnowl to reload the startup file
:source "~/.owl/startup"
- Optional: Check that the correct startup file is loaded
:show startup
Footnotes
[1] From /help.c - barnowl - Trac,zsig - zephyr signature (default: '')
zsigproc - name of a program to run that will generate zsigs (default: '<null>')
[2] If you run :help startup
inside Barnowl, you get startup - run a command and set it to be run at every Owl startup
No comments:
Post a Comment