sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

index.md (6767B)


      1 Kris Maglione aka JG
      2 ====================
      3 
      4 I'm the maintainer of wmii.
      5 
      6 This is a place for me to post the random scripts that I'm compelled to write and consider useful.
      7 
      8 Scripts
      9 -------
     10 *Note:* I've updated most of these, and haven't posted the updates... I'll get around to it eventually.
     11 
     12 All of these scripts are written in rc, and require plan9port to run.
     13 
     14 * webpaste - A script which reads its standard input or the files
     15     on its command line and prints a URI where the data can be retrieved. Requires: curl.
     16 
     17 * pasteweb - Similar to webpaste, but reads the contents of your
     18    clipboard and replaces them with a URI where the contents can be retrieved.
     19    Requires: curl, and one of xclip, xsel, or sselp (in which case, it will print the URI)
     20 
     21 * plastfm - An rc script which connects to Last.FM and plays its stream with
     22    a command-line mp3 player. Commands are read from the standard input and song info is
     23    printed to the standard error. Requires: mpg123 or similar client. *This has been replaced
     24    by "last".*
     25 
     26 * eris.rc - This is an IRC bot, written in rc, of course, which prints mercurial
     27    commits to channels. The name comes from George Neis' python version. Requires: sic or similar.
     28 
     29 * hgnotify.rc - This is an mailing list bot which posts mercurial commits
     30    along with their diffs to a mailing list, or arbitrary mailing address. The sender, subject,
     31    and date all reflect those of the commit. Requires: A sendmail compatible MTA.
     32 
     33 * logger.rc - A simple IRC logger bot, which uses the httplog logger to handle
     34    log rotation. It also extracts lines beginning with 'BUG' and writes them to a separate file.
     35    Requires: httplog, sic.
     36 
     37 
     38 `wmii` Scripts
     39 ==============
     40 These are just some of the random wmii scripts I've written.
     41 I find them immensely useful, and they serve as good examples.
     42 Most use the `wmii.rc` script which I've written to make
     43 `rc.wmii` more straightforward, and plugins easier. But, I haven't
     44 released it yet, so bear with me.
     45 
     46 `rc.keymap`
     47 -----------
     48 A simple keymap-changer applet. It doesn't know any keyboard
     49 shortcuts for the moment.
     50 
     51     #!/bin/rc
     52     . 9.rc
     53     . wmii.rc keymap
     54 
     55     # Begin Configuration
     56     bar=s7~1keymap
     57     choices=(us dvorak)
     58     # End Configuration
     59 
     60     keymap=$choices(1)
     61 
     62     fn setkeymap {
     63         if(! ~ $"* '') {
     64             keymap=$"*
     65             setxkbmap $keymap
     66             echo km:$"keymap | wmiir create /rbar/$bar
     67         }
     68     }
     69 
     70     setkeymap $keymap
     71 
     72     fn Event-RightBarMouseDown {
     73         if(! $1 1 && ~ $2 $bar)
     74             setkeymap `{wi_9menu -initial $keymap $choices}
     75     }
     76 
     77     wi_eventloop
     78 
     79 `rc.vol`
     80 --------
     81 Adjust the volume with Alt-Plus/Alt-Minus (should use `$MODKEY`...).
     82 My first bar just happens to be named `agabaga`, because I picked
     83 a random word which started with a ages ago, and the name stuck.
     84 
     85     #!/bin/rc
     86     . 9.rc
     87     . wmii.rc
     88 
     89     # Begin Configuration
     90     numbars = 20
     91     mixer = pcm
     92     bar = agabaga
     93     delay = 2
     94     # End Configuration
     95 
     96     fn mset {
     97         var=$1; shift
     98         eval $var' = `{hoc -e $"*}'
     99     }
    100 
    101     mset div 100 / $numbars
    102 
    103     fn readvol { mixer $* | awk -F'[ :]+' '{print $7}' | head }
    104 
    105     xpid = ()
    106 
    107     fn changevol {
    108         diff = $1; shift
    109         cur = `{readvol $mixer}
    110         mset new $cur + '(' $diff ')'
    111 
    112         mixer $mixer $new >/dev/null
    113 
    114         awk -vnew'='$new -vdiv'='$div -vn'='$numbars \
    115             'BEGIN{ s=sprintf("% *s", new/div, "|");
    116                 gsub(/ /, "-", s);
    117                 printf "[% -*s] %d%%", n, s, new;
    118                 exit }' |
    119             wmiir write /rbar/$bar
    120 
    121         /bin/kill $xpid >[2]/dev/null # Let's hope this isn't reused...
    122         { sleep $delay; wmiir xwrite /rbar/$bar ' ' }& # Bug...
    123         xpid = $apid
    124     }
    125 
    126     fn Key-Mod1-^(KP_Add Shift-plus) {
    127         changevol $div
    128     }
    129 
    130     fn Key-Mod1-^(KP_Subtract Shift-minus) {
    131         changevol -$div
    132     }
    133 
    134     wi_eventloop
    135 
    136 `rc.mail`
    137 ---------
    138 A mail monitor. I've posted it elsewhere. It reads the names of
    139 windows on the mail tag and checks for mail in Maildirs with
    140 corresponding names. It treats `inbox` specially. This is posted
    141 elsewhere.
    142 
    143     #!/bin/rc
    144     . 9.rc
    145 
    146     # Configuration
    147     #How often to check
    148     delay=5
    149     maildir=$home/Maildir
    150     # End Configuration
    151 
    152     echo Start mail | wmiir write /event
    153 
    154     {   wmiir read /event &
    155         while(echo Tick)
    156             sleep $delay
    157     } | while(*=`{read}) 
    158         switch($1) {
    159         case Start
    160             if(~ $2 mail)
    161                 exit
    162         case Tick
    163             wmiir read /tag/mail/index |
    164             while(l = `{read}) {
    165                 b = `{echo $l | awk -F: '{print $3}'}
    166                 if(~ $b inbox)
    167                     b = ''
    168                 if(! ~ $#b 0 && test -d $maildir/.$b/new) {
    169                     if(~ `{ls -l $maildir/.$b/new | wc -l} 0)
    170                         wmiir xwrite /client/$l(2)^/ctl Urgent off
    171                     if not
    172                         wmiir xwrite /client/$l(2)^/ctl Urgent on
    173                 }
    174             }
    175         }
    176 
    177 `rc.status`
    178 -----------
    179 My date/time/load average bar. Straightforward.
    180 
    181     #!/bin/rc
    182     . 9.rc
    183     . wmii.rc rc.status
    184     # periodically print date and load average to the bar
    185 
    186     fn date { /bin/date $* }
    187 
    188     bar_load=s5load
    189     bar_date=s9date
    190     bar_time=time
    191     bars=($bar_date $bar_load)
    192 
    193     fn sigterm sigint {
    194         for(i in ($bars $bar_time))
    195             wmiir remove /rbar/$i >[2]/dev/null
    196         exit
    197     }
    198 
    199     for(i in $bars $bar_time)
    200         wmiir remove /rbar/$i >[2]/dev/null
    201 
    202     sleep 2
    203     for(i in $bars)
    204         echo -n $wmiinormcol | wmiir create /rbar/$i
    205     echo -n $wmiifocuscol | wmiir create /rbar/$bar_time
    206 
    207     {
    208         while (wmiir xwrite /rbar/$bar_time `{date +'%H:%M:%S %Z'}
    209             && wmiir xwrite /rbar/$bar_date  `{date +'%a, %e %b'}
    210             && wmiir xwrite /rbar/$bar_load `{uptime | sed 's/.*://; s/,//g'})
    211             sleep 1
    212     } >[2]/dev/null
    213 
    214 `rc.temp`
    215 ---------
    216 A temperature monitor for the bar. It has Fahrenheit along with
    217 Celsius, because I'm stuck using both (tell someone in the US that
    218 it's -3°C outside and expect little more than a blank stare).
    219 
    220 This one uses weatherget. It's in ports... I don't know where else
    221 to find it.
    222 
    223     #!/bin/rc
    224     . 9.rc
    225 
    226     # Begin Configuration
    227     zip=12345 # For those outside the us, this needn't be a zip code.
    228     bar=/rbar/s7temp
    229     pidf=$home/.wmii-3.5/pid.temp
    230 
    231     deg=°
    232     # End Configuration
    233 
    234     /usr/bin/kill `{cat $pidf} >[2]/dev/null
    235     echo $pid >$pidf
    236 
    237     wmiir create $bar </dev/null
    238 
    239     while() {
    240         {weatherget -s $zip -m; weatherget -s $zip -S} |
    241             awk '$1=="Temperature"{print $3"'$deg'"$4}' |
    242             tr '\012' ' ' |
    243             wmiir create $bar ||
    244             exit
    245         sleep 600
    246     }
    247