Search this site

[prev]  Page 2 of 3  [next]





better screen session completion in zsh

function screen-sessions {
   typeset -a sessions
   for i in /tmp/screens/S-${USER}/*(p:t);  do


compctl -K screen-sessions screen
Completion chops off the PID of the screen session, so i can do:
screen -x log[TAB]
and it will complete to 'screen -x logwatch'


zsh compctl

Got bored after doing some homework tonight and added a few more completions to my zsh config. The top two are yanked from petef's zshrc
compctl -g '/u9/psionic/Mail/*(/:t)' -P '+' folder
compctl -g '/var/db/pkg/*(/:t)' pkg_delete pkg_info
compctl -g "/tmp/screens/S-${USER}/*(p:t)" screen
compctl -g "*(-/D)" + -g "*.class(.:r)" java
What do they do? (Listed in order)
  • for the program 'folder' complete to any directory in /u9/psionic/Mail/ and drop the path above it (like basename(1)). Also prefix it with a '+' character.
    fury(~) [1] !127! % folder +TAB
    drafts      exec        inbox       lists       old         rtp         spam        
    duplicates  foo         jason       main        outbox      security    work        
  • complete package names under freebsd for pkg_delete and pkg_info
    nightfall(~/foo/project) [1021] % pkg_info TAB
    ORBit2-2.12.1_1               isc-dhcp3-server-3.0.1.r14_6  png-1.2.6
    adns-1.0_1                    jad-1.5.8c                    portupgrade-20041226_1
    aspell-0.60.2                 jpeg-6b_3                     ruby-1.8.2_3
    ... the list goes on ...
  • complete screen sessions
    nightfall(~/foo/project) [1022] !1! % screen -x TAB
    11950.ttyp6.nightfall  16783.ttyp2.nightfall  16852.ttypa.nightfall  709.ttyp8.nightfall
    16146.ttypn.nightfall  16801.ttyp4.nightfall  17336.ttyp0.nightfall  741.ttypc.nightfall
  • complete java class names without the '.class' extension
    nightfall(~/foo/project/os1/step1) [1024] % java sys/TAB
    ExitCode  Kernel    Panic

ipfallowme - Me vs Annoying IPF Rules

The dev box at work has a new, more strict set of ipf rules now. In an effort not to have to change the global rule set, I wrote a little script to pick out your ip from an ssh session and add a few rules based on that ip.

There are probably already scripts that do this out there, but I didn't bother looking.

How it works:
- Create a rule file
- Make sure none of these rules are in the existing ipf rule set
- Apply the generated ruleset (won't overwrite or delete any existing rules)
- Wait until you kill the process or logout if you've backgrounded it, then remove the new rules you added.

Click here to view ipfallowme

grep -A (after), -B (before) context without gnu grep (-C too...)

This essentially does grep -C 5 REGEX $FILE. This was a boredom-induced hack
grep -sn REGEX $FILE | \
awk -F: '{print $1}' | \
xapply -f 'A=$((%1-5)); B=$((%1+5)); echo "-----"; \
   sed -ne "${A},${B}p" '$FILE'; \
   echo "---"' - 

CD Collections, cd to mp3

It's hard to listen to what I want when I want when I have to search through cd booklets for the damn song, so I wrote a script that will rip the cd, grab the track information from cddb, and encode it in ARTIST/ALBUM/TRACKNAME.mp3 format with proper id3 tags. It ejects the cd when ripping is done so you know when to put a new cd in.

zsh's preexec() and tcsh's postcmd

These are definately two of the most useful things I've ever run across in shelllyland. What they do is execute a function or alias (zsh or tcsh, respectively) just after you type something in at the command prompt.

This wonderful feature lets you change the xterm title just before execution of a potentially "long" process. This is most helpful for glancing at xterm titles and figuring out what is going on in the terminal. I don't have this setup for tcsh, however it is quite simple and is mentioned in tcsh's manpage. Search for 'alias postcmd'

Here is my zsh setup particular to this topic:


preexec() {
	xterm_title $1

xterm_title() {
	case $TERM in
				echo -n "^[]0;$* @ $HOST^G"

Now every time you execute a command (vim Foo.html, for instance), the xterm title will be updated with whatever command @ hostname.

Yet another random number generator

I was bored...

dd if=/dev/urandom bs=1 count=30 2> /dev/null | \
perl -e 'read(STDIN,$foo,5); print unpack("J",$foo) % 6 . "\n";'

pimp, lame, ssh, and streaming!

So since pimp has a cheap shoutcast server thing, I decided to use that to play music while I'm at home.

Playing normal mp3s uses too much bandwidth to waste on my DSL connection (~20-30k/s with 128-160kbit mp3s). So, I decided to use lame as a middleman to down-encode the shoutcasted output from pimp. The following is a little script that uses netcat to connect to the shoutcasty thing aswell as act as a server elsewhere for the down-encoded mp3 data to be sent off.


foo() {
	killall nc
	exit 1

trap foo int 
nc -lp 8081 |&

echo "ICY 200 OK" >&p
echo >&p

nc whack 8080 | lame --mp3input -b 64 - - >&p

I probably don't need to use co-processes, but they're fun, so whatever. Run this script then run mplayer against whatever machine it's on. So what I do is, run the script, then mplayer:

whack(~) > ./projects/pimp/pimp &
whack(~) > ./mp3foo
... over on my laptop ...
nightfall(~) > mplayer http://whack:8081

Poof! Instant mp3 shenanigans. Instead of averaging 24K/s I average 7.5K/s while playing streamed mp3s - what's better is I can still control what song is being played throug pimp's telnet interface and I don't have to waste time downloading every individual song I want to listen to.

Furthermore, here's a nice oneliner to do inbound(download) bandwidth monitoring:

netstat -w 1 | perl -e 'while (<>) { next unless m/^\s+\S+\s+\S+\s+(\d+)/; \
	$b++; $a += $1; print "Total/Avg/Cur = $a / " . ($a / $b) . " / $1\n"; }'

Pimp, topkeys, etc...

Did a bit of coding this weekend. PiMP got some pretty major feature upgrades including stream support (think shoutcast). I still need to work on the server<->player protocol aswell as the client<->server protocol. I've got a list of hot features I'm going to add to it as soon as I get more time including iTunes shares support, non-mp3 multimedia support, a graphical frontend, a curses frontend, etc.

I also made some neat changes to is a handy script I wrote so I could control XMMS with my media/internet buttons on my microsoft keyboard. I no longer use this keyboard and instead use the number pad (which is generally useless to me normally). With this update I added support for multiple interfaces. The two I have written so far are for xmms and bottlerocket. You can toggle between the two (and a dynamic list of others that I may write.
If you want to give it a shot, you'll need atleast and, over there on the right. and other moduley things should go in ~/.topkeys/ requires xmms, obviously. requires bottlerocket to be installed, get it from freshmeat.

I also wrote a new perl module this weekend called HTTP::Handle. I needed this to make connecting to shoutcast and other mp3 streams less painful, I think it's a good start. I'll update it with some new features sometime soon.

nmh mail archiver

I went over quota. My mail backlog was 132 megs so it was time to archive mail.

This was built specifically for my needs but it'll work for any mh mailbox pending you know what to do...

mailarch script

Partial output from my run... (I only started using NMH in July)

fury(~) [34] > ./bin/mailarch
.archive+ has 3057 messages  (1-3469); cur=143; (others).
Jan.2003.tar:  scanning... no email this month.
Feb.2003.tar:  scanning... no email this month.
Mar.2003.tar:  scanning... no email this month.
Apr.2003.tar:  scanning... no email this month.
May.2003.tar:  scanning... no email this month.
Jun.2003.tar:  scanning... no email this month.
Jul.2003.tar:  scanning... tarring... bzipping... -  69 mail
Aug.2003.tar:  scanning... tarring... bzipping... -  140 mail
Sep.2003.tar:  scanning... tarring... bzipping... -  27 mail
Oct.2003.tar:  scanning... tarring... bzipping... -  246 mail
Nov.2003.tar:  scanning... tarring... bzipping... -  25 mail
Dec.2003.tar:  scanning... tarring... bzipping... -  189 mail
Jan.2004.tar:  scanning... tarring... bzipping... -  617 mail
Feb.2004.tar:  scanning... tarring... bzipping... -  811 mail
Mar.2004.tar:  scanning... tarring... bzipping... -  932 mail
Apr.2004.tar:  scanning... no email this month.
May.2004.tar:  scanning... no email this month.
Jun.2004.tar:  scanning... no email this month.
Jul.2004.tar:  scanning... no email this month.
Aug.2004.tar:  scanning... no email this month.
Sep.2004.tar:  scanning... no email this month.
Oct.2004.tar:  scanning... no email this month.
Nov.2004.tar:  scanning... no email this month.
Dec.2004.tar:  scanning... no email this month.