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.
Sort of “cd with bookmarks” for Zsh. You define bookmarks for directories in ~/.bcdrc and then use:
to cd to the directory associated with some-bookmark.
You can add a bookmark using:
To remove a bookmark use:
Or just edit ~/.bcdrc with your favourite editor.
Format of ~/.bcdrc is:
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.
Counts the class attributes used in a HTML document.
Needs xmllint distributed with libxml
$ 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
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).
$ 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)
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)
$ dvdtime /dev/dvd libdvdread: Using libdvdcss version 1.2.10 for DVD access 01:10:57
Prints the names of the currently used Firefox profiles. Tested with Firefox 3.0.x
Needs lsof, GNU xargs
$ ffprofiles default test
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.
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.
Downloads the classifier list from PyPI, displays a list where you can select classifiers and prints the selected classifiers.
Needs zenity, tempfile and wget
Sleep until a given time. See the date documentation for how to specify times.
Needs GNU date.
$ sleepuntil '0:00' $ sleepuntil tomorrow $ sleepuntil '0:01 1/1 next year'
Switches to a window of the application that has a give PID.
$ switch-to-pid $(pgrep firefox)