I’ve been really getting into developing my KickTweet project and set up a Twitter account for it at http://twitter.com/KickTweet. I wanted to feed in my subversion commits so I did some searching.
What I found was twitvn a monstrous (50-ish ‘real lines) Python script that sends commits to Twitter. I find that ridiculous. So here is my version, it drops right into the post-commit script and could be reduced to 2-3 active lines.
1 2 3 4 5 6 | #!/bin/bash REPOS="$1" REV="$2" TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)" curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml |
Note that the use of the ‘${TWEET:0:139}’ is a definite bashism, and not portable.
Update (2008-09-22)
Little tidbit to add into the script right before the curl call. If you want ellipses on commit messages over 140 characters, use this version.
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash REPOS="$1" REV="$2" TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)" if [ "${#TWEET}" -gt 140 ]; then TWEET="${TWEET:0:137}..." fi curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml |
I had a bad morning today. I was working on a script that parses out log files and ran it from my desktop. It’s supposed to change to a specified directory and check for, then delete, any logs that are over a month old. Unfortunately I didn’t have that directory on my machine, and I didn’t exit the script after a failed directory change. Poof, there go my desktop documents.
As an impulse reaction I looked for something to replace ‘rm’, and found safeRM. I was not impressed. Why have a ‘dustbin’ folder if we already have that built into the desktop environment, i.e. the Trash can?
Here is my own brief script that (on openSuSE) moves things to the trash. Note that it is not set up for moving directories and does not emulate ‘rm’ entirely.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash TRASHDIR=~/.local/share/Trash X=1 NAME=$(basename $1) while [ -f $TRASHDIR/$NAME ]; do NAME=${NAME}_$X X=$(($X + 1)) done mv $NAME $TRASHDIR/files/ echo "[Trash Info]" > $TRASHDIR/info/$NAME.trashinfo echo "Path=$PWD/$1" >> $TRASHDIR/info/$NAME.trashinfo echo "DeletionDate=$(date +%Y-%m-%dT%H:%M:%S)" >> $TRASHDIR/info/$NAME.trashinfo |
By the time I got this far I decided that this wasn’t worth pursuing. I’ll just try to be more careful and will absolutely run backups. I thought I’d publish it anyway just in case someone wants a safeRM alternative or to be able to put things in the trash from the command line.
Posted September 9th, 2008 - PermalinkHere’s a modification of a bash script I made a while back to convert anything that mplayer can play into an mp3 file. Change bitrates and the like to taste.
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash # # any2mp3 # for i in *.$1; do mplayer -vc null -vo null -ao pcm:fast "$i" -ao pcm:file="${i%.$1}.wav" done for i in *.wav; do lame -h -V2 --vbr-new "$i" "${i%.wav}.mp3" done rm *.wav |
Say you are in a directory of m4a files, just run any2mp3.sh m4a and wait.
Posted March 18th, 2008 - PermalinkDo you ever spend 20 minutes figuring out the perfect way to do some arcane task on the command line, only to forget it and need it again in a month? I do. A lot.
I started keeping a directory with little plain text documents that had the command line I wanted inside them. I recently uploaded them to my static site and wrote a script to use them easier.
It’s real simple, just download the howto bash script in the following directory http://static.velvetcache.org/howtos/ and place it in your path. Now make a directory for your HowTo’s somewhere and put the whole path into a file in your home directory called “.howto”.
You should be able to call $ howto –sync and it will pull down a tar of the most current files, then expand it into your HowTo directory.
If you download the howto.tar.gz by itself, be warned that it is a tar bomb and will rudely scatter its files all over your directory.
Lastly, onceyou have some HowTo’s installed, just use $ howto -l to list out the possible choices, then $ howto print-unix-timestamp, replacing “print-unix-timestamp” with the name or number of the HowTo you want.
Below is the howto shell script, because I like including code in my posts whenever I can.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/bin/bash function printUsage { echo "Usage: howto [-l | --list] file-name" exit 1 } if [ $# -ne 1 ]; then printUsage fi if [ ! -f ~/.howto ]; then echo "No .howto file found in your home directory!" exit 1 fi HOWTODIR=$(cat ~/.howto) if [ "$1" == "--sync" ]; then LRECENT=$(cat $HOWTODIR/CURRENT) SRECENT=$(wget -O - http://static.velvetcache.org/howtos/CURRENT 2> /dev/null) if [ $? -ne 0 ]; then echo "Can't contact download server." exit 1 fi if [ "$LRECENT" != "$SRECENT" ]; then cd $HOWTODIR if [ $? -ne 0 ]; then echo "Can't change to the HowTo directory." exit 1 fi wget -O howtos.tar.gz http://static.velvetcache.org/howtos/howtos.tar.gz if [ $? -ne 0 ]; then echo "Can't download new files." exit 1 fi tar -zxf howtos.tar.gz if [ $? -ne 0 ] ; then echo "Can't untar the updates." exit 1 fi rm -f howtos.tar.gz exit 0 else echo 'Nothing new to download.' exit 0 fi fi if [ "$1" == "--list" ] || [ "$1" == "-l" ]; then COUNTER=0 for howto in `ls $HOWTODIR`; do echo "$COUNTER $howto" COUNTER=$(expr $COUNTER + 1) done exit 0 fi echo $1 | grep '^[0-9][0-9]*$' > /dev/null 2>&1 if [ $? -eq 0 ]; then COUNTER=0 for howto in `ls $HOWTODIR`; do if [ $COUNTER -eq $1 ]; then cat $HOWTODIR/$howto exit 0 fi COUNTER=$(expr $COUNTER + 1) done echo 'That HowTo was not found.' exit 1 elif [ ! -f "$HOWTODIR/$1" ]; then echo 'That HowTo was not found.' exit 1 fi cat $HOWTODIR/$1 exit 0 |
I’m releasing version 0.6 of Nix Monitor today. It’s gotten a bit bigger and harder to configure, so I wrote a kickin configurator script using Zenity for all my prompts. Check it out at http://kde-look.org/content/show.php/Nix+Monitor?content=67399
Posted November 13th, 2007 - Permalink