Shell Scripts¶
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:
zsh:$ bcd ul<TAB>
Completing bcd bookmarks
ul --> /usr/local
uls --> /usr/local/stow
bash:$ bcd ul<TAB>
ul uls
bcd
works with any POSIX /bin/sh if you remove the completion
stuff at the end of the file.
Download¶
Last modified: |
2012-05-18 01:58:00 |
Size: |
3,2K |
MD5: |
4ac441febc7df07c9ef0226a480cb9c2 |
SHA256: |
d6fd09f2a46c7de7447bdc5928101001a253886c6d1bb414df8007222ff2364b |
GPG signature: |
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¶
Last modified: |
2009-06-07 06:29:00 |
Size: |
534 |
MD5: |
d28890beb93f75cf210e26aa5a18f576 |
SHA256: |
1bbb57be570489f5aeb56bb5eef245ccc2851fc548a1ebdddbf53ba5b060940d |
GPG signature: |
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¶
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¶
Last modified: |
2009-06-07 06:29:00 |
Size: |
543 |
MD5: |
4805aa959da211a28e1a5761c0f11f76 |
SHA256: |
b168986795a214318c9300cc88b5f15490120ac3b04111a6cdf7a74f82cc7e8e |
GPG signature: |
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¶
Last modified: |
2009-08-25 20:11:00 |
Size: |
581 |
MD5: |
50b25cc2a8682359555fa37efaa6f76f |
SHA256: |
ffb4e30b1f7340ad65b0b4d980662333280481f37b02e1779fe34847349af65a |
GPG signature: |
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¶
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¶
Last modified: |
2009-06-08 07:32:00 |
Size: |
817 |
MD5: |
2271d1133b2a7de0599e055842e25273 |
SHA256: |
afbade1afe246037eb7d737172df40c5b63ace0e35c3b4b016b6a550ee22f97b |
GPG signature: |
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¶
Last modified: |
2009-07-17 23:01:00 |
Size: |
977 |
MD5: |
f510e6bd7bf6271a8c3ae9116a8e65ef |
SHA256: |
2ffcf44806b85b9b866396ac608f912ca29d05045b69362cffcacd4aca05e59e |
GPG signature: |
sleepuntil¶
Sleep until a given time. See the date documentation for how to specify times.
Needs GNU date.
Download¶
Last modified: |
2009-06-07 06:29:00 |
Size: |
518 |
MD5: |
f59773cbf32df38cd63feb30eab30b83 |
SHA256: |
0e02280232ffa6d8084c4ea463bcf8f879cce624ad4df0ee9e172d3beed88b66 |
GPG signature: |
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¶
Last modified: |
2009-06-07 06:29:00 |
Size: |
478 |
MD5: |
f7357713eb12a83472b097e8eb368f50 |
SHA256: |
92123a88653967accbb838409dc1015f077ceab4436bccaea17c35efbfde5653 |
GPG signature: |
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 wget, mktemp, ImageMagick and a desktop environment that uses Nautilus 3.x to manage the wallpaper (like Gnome3 or Unity)
Download¶
Last modified: |
2015-01-14 23:18:00 |
Size: |
1,1K |
MD5: |
a9244c3bac7bdb161bd4b35c0c256a91 |
SHA256: |
96fd6c7ebd88a9971d357834a86bf62e408f0f2ac0f90458291baa6f3b121aed |
GPG signature: |