Here are some small shell scripts I have written over time. Usually they are tested on Linux with a GNU userland but should work in any POSIX compatible environment.

This scripts are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You are free to do with them what ever you want.



bcd

Sort of “cd with bookmarks” for Zsh. You define bookmarks for directories in ~/.bcdrc and then use:

bcd some-bookmark

to cd to the directory associated with some-bookmark.

You can add a bookmark using:

bcdadd some-bookmark

To remove a bookmark use:

bcddel some-bookmark

Or just edit ~/.bcdrc with your favourite editor.

Format of ~/.bcdrc is:

name:directory

e.g.:

ul:/usr/local
uls:/usr/local/stow
nspool:/var/spool/news

With that you can use:

$ bcd uls

to cd to /usr/local/stow.

Calling bcd without arguments prints the bookmarks:

$ bcd
       ul --> /usr/local
      uls --> /usr/local/stow
   nspool --> /var/spool/news

bcd and bcddel come with completion for Zsh:

$ bcd ul<TAB>
Completing bcd bookmarks
       ul --> /usr/local
      uls --> /usr/local/stow

bcd needs Zsh but should work with any POSIX /bin/sh if you remove the completion stuff at the end of the file.

Download

bcd

Save the file as e.g. ~/zsh.d/bcd and add:

. ~/zsh.d/bcd

to your ~/.zshrc. Don’t try to execute the file. This will not work!


cntclass

Counts the class attributes used in a HTML document.

Needs xmllint distributed with libxml

Download

cntclass

Example

$ cntclass  http://www.florian-diesch.de
     1 autor
     1 nav
     1 navactiveitem
     1 navlevel0
     1 navopen
     1 validate
     2 section
     3 navlevel1
     4 navpassiveitem
     5 navitem

dave

Ask HAL about your hardware.

Calling dave with two arguments $1 and $2 lists all device objects for which key $1 has the string value $2.

Calling dave with three arguments $1, $2 and $3 lists the value of key $3 for all device objects for which key $1 has the string value $2.

Note that $2 always refers to string value so dave doesn’t work for keys that have values of other types. That’s a limitation of hal-find-by-property .

Needs hal-find-by-property, hal-get-property and lshal (all distributed with HAL).

Download

dave

Examples

$ dave block.device /dev/sda
udi = '/org/freedesktop/Hal/devices/storage_serial_SATA_WDC_WD800BB_22J_WD_WCAM9C068403'
 block.device = '/dev/sda'  (string)
 block.is_volume = false  (bool)
 block.major = 8  (0x8)  (int)
 block.minor = 0  (0x0)  (int)
 ...

$ dave linux.subsystem input info.product
ImPS/2 Logitech Wheel Mouse
Macintosh mouse button emulation
AT Translated Set 2 keyboard
PC Speaker
Power Button (CM)
Power Button (FF)

dvdtime

Prints the total play time if all tracks on a video DVD.

Needs lsdvd. Maybe it only works with GNU date (didn’t check if the needed features are defined by POSIX)

Download

dvdtime

Example

$ dvdtime /dev/dvd
libdvdread: Using libdvdcss version 1.2.10 for DVD access
01:10:57

ffprofiles

Prints the names of the currently used Firefox profiles. Tested with Firefox 3.0.x

Needs lsof, GNU xargs

Download

ffprofiles

Example

$ ffprofiles
default
test

gmotd

Displays messages from text files that have changed since its last run.

gmotd looks for files in /usr/local/share/gmodt and displays the ones that are newer than the file ~/.gmotd one by one. After all files are displayed ~/.gmotd is updated.

The folder for the message file can be changed in the script.

You may add this script to the user desktop’s autostart programs to display new messages (created by the admin, cron jobs, ...) after you login.

Needs zenity

Download

gmotd


openlnk

Open a Windows .lnk file in Linux. This script is the result of a discussion on ubuntuusers.de

By default it looks for the file on the same partition as the .lnk file. You can define a mapping between Windows drive letters and Linux mountpoints in ~/.openlnkrc that has to look similar to this:

C: /media/C
D: /some/other/mount point

The script parses .lnk files just by searching for something that looks like a Windows file name. It doesn’t deal well with non-ASCII characters in file names.

Files are opened using xdg-open.

Download

openlnk

Info

Microsoft now has published the file format for .lnk files (thanks to Vain for the link). So maybe someone wants to write a better version of this...


pypicats

Downloads the classifier list from PyPI, displays a list where you can select classifiers and prints the selected classifiers.

Needs zenity, tempfile and wget

Download

pypicats


sleepuntil

Sleep until a given time. See the date documentation for how to specify times.

Needs GNU date.

Download

sleepuntil

Examples

$ sleepuntil '0:00'
$ sleepuntil tomorrow
$ sleepuntil '0:01 1/1 next year'

switch-to-pid

Switches to a window of the application that has a give PID.

Needs wmctrl.

Download

switch-to-pid

Example

$ switch-to-pid $(pgrep firefox)

xkcddesktop

Fetches the current strip from xkcd and sets it as wallpaper for Gnome. The mouseover text is added at the bottom of the image.

Needs Gnome, wget, mktemp, ImageMagick

Download

xkcddesktop (last modified: 2009-11-06)