April 16th, 2007 | Filed under Bash scripts, Unix
Ah-ha! So THAT’s the difference between .bash_profile and .bashrc.
A web programmer’s notebook.
Ah-ha! So THAT’s the difference between .bash_profile and .bashrc.
Just noticed that Thunderbird has a new message filtering criteria: “From: email address in my address book.”
That, coupled with Thunderbird’s ability to add the address of anyone you send a message to automatically to your address book, opens up the possibility of filtering mail from people that you’ve communicated with before into “Known” folder, and mail from folks you don’t into “Unknown” folder.
(I’ve been jonesing for something like this for awhile; a helpful Lifehacker commenter pointed out that it’s possible.)
So to get this system going, first I had to populate my address book with all the email addresses I’ve sent mail to before. This one-liner on my IMAP server’s sent-mail file, cobbled together with a lot of help from this Ask Metafilter thread, does the trick:
grep "^To: " mail/sent-mail | grep "@" | \
sed 's,.* <*\([^ ]*@[^ >]*\).*,\1,’ | \
sort | uniq -i | sed ’s/,.*$//’ > correspondents.txt
(Mind you, this Python version is a lot more elegant, but it kept timing out on me. I have a big sent-mail folder.)
From there, import correspondents.txt as a new address book and set up your filter in Thunderbird.
Awesome.
(Also only interesting to me: The ~10k messages I sent from my personal email address in the last 2 years were to less than 2000 recipients, for an average of about 5 messages per correspondent.)
$ wc -l correspondents.txt
1823 correspondents.txt
I had no idea one could write a bash completion script - that makes the Tab key fill in possible custom commands or arguments when you’re at a prompt - but one of my todo.txt developers did, and wrote one that completes todo.sh arguments or your existing projects, contexts or priorities. Which totally blew my doors off.
I’m probably going to be embarrassed about this post in the morning, but I re-figured out how to customize my terminal prompt, and I got something that I like which I’ll post here for the next time I get a new computer and have to Google the whole thing up again.
In ~/.bashrc (Mac: ~/.bash_profile), add:
function prompt
{
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
export PS1="${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${GRAY}
$ "
}
prompt
Then:
$ source .bashrc
Which makes it look something like this:
gina@amelia ~/Documents
$
But with pretty colors.
That is all.
Now that I’m running an open source project with a mailing list of developers much more skilled than I am, I’ve got folks emailing in code patches in the form of .diff files. Having never dealt with .diff’s before (I know, I know, Windows baby here) I dove into the GNU diffutils manual. This kind of stuff still scares the crap out of me, but:
$ patch todo.sh todocolour.diff
Applied the submitted file differences to the source code, and I was able to run my unit tests straightaway without hand-adding edited code line by line.
Patch added the changed lines to the original file (todo.sh) and created a todo.sh.orig file as well. If it fails on merging any file differences, it creates a todo.sh.rej file.
Simple, useful and handy.
Awhile back I threw together a monster bash script, todo.sh, which reads and writes to a personal todo.txt file.
Using a bunch of sed and grep recipes for editing, adding, slicing and dicing by project, context and priority (ala Getting Things Done), this is the only todo manager I’ve ever stuck with for more than a month. Here’s a 3-minute or so screencast of how todo.sh works:
Note: I aliased todo.sh to t here to reduce typing strain.
The AIM bot I mentioned earlier executes todo.sh as well, so you can IM your todo.txt from the office or your phone. Imagine IM’ing your bot list @shopping to get your grocery shopping list on your phone from the aisle at Ralph’s.
Anyway, all the todo.txt script shenanigans I’ve been hacking together are now located at their very own domain, todotxt.com.
I’ve got a rant about the current state of organizational software and the wonderful experience of leading an open source project that’s garnered quite a few Lifehacker.com reader contributors, but that’ll be another post.