]> git.draconx.ca Git - fvwmconf.git/commitdiff
Merge branch 'master' of atropos:.fvwm
authorNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 23:42:32 +0000 (19:42 -0400)
committerNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 23:42:32 +0000 (19:42 -0400)
Conflicts:

scripts/mpdmenu.pl

18 files changed:
artemis/config
common/bindings
common/modifier
common/nickstheme
common/wallpaper
config
default [new symlink]
finial/config [new file with mode: 0644]
finial/rootmenu [new file with mode: 0644]
global/appspecific [new file with mode: 0644]
global/fullscreen
scripts/C/Makefile
scripts/C/xaspect.c
scripts/bgmenu.zsh [moved from scripts/bgmenu.sh with 82% similarity]
scripts/mpdmenu.pl
scripts/randombg.pl [new file with mode: 0755]
scripts/thumbnail.sh [deleted file]
scripts/thumbnail.zsh [new file with mode: 0755]

index 3e69f0c6c12036bde653af5997defb3bdc58a560..c0849d9f1286ac9f1336379ec8371b38d4d479b2 100644 (file)
@@ -3,10 +3,10 @@ Read common/bindings
 Read common/nickstheme
 
 # Bigger fonts must be set before including rootmenu
-Style * Font 'xft:M+1P+IPAG:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-Style * IconFont 'xft:M+1P+IPAG:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-MenuStyle * Font 'xft:M+1P+IPAG:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-MenuStyle * TitleFont 'xft:M+1P+IPAG:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+Style * Font 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+Style * IconFont 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * Font 'xft:Meiryo Short:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * TitleFont 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
 
 Read artemis/rootmenu
 Read common/wallpaper
index 4d0ce486d2a7132ab320c201461579b7404632e9..dd9f2e2b99caf7e80b9f92cc1898325951da3674 100644 (file)
@@ -37,7 +37,8 @@ Mouse 4 T N Windowshade True
 Mouse 5 T N Windowshade False
 
 # Console
-Key grave A C Exec exec $[TERMINAL]
+Key grave A C  Exec exec $[TERMINAL]
+Key grave A CM Exec exec $[TERMINAL] -e zsh -f
 Key F3 A M  Module FvwmConsole -terminal $[TERMINAL]
 Key F3 A M2 Module FvwmConsole -terminal $[TERMINAL]
 
index c7b770da57c2154552240d2fc31753e8ef365cb1..cbb89b174cc4878e59b4e878ad320646da636391 100644 (file)
@@ -13,4 +13,4 @@ DestroyFunc Mod_M3Func
 AddToFunc   Mod_M3Func
  + C Lower
  + D Maximize 100 0
- + M PipeRead '. $[FVWM_USERDIR]/scripts/resize.sh $[pointer.wx] $[pointer.wy] $[w.width] $[w.height]'
+ + M PipeRead 'exec $[FVWM_USERDIR]/scripts/resize.sh $[pointer.wx] $[pointer.wy] $[w.width] $[w.height]'
index 817a5a0509c410dfab651f8542494f28b277c857..25aaf7734ed09e829721a3e6e3229a1bebae4a24 100644 (file)
@@ -54,19 +54,20 @@ Colorset 4 fg white, bg #567ea2
 Style * ColorSet 1
 Style * HilightColorSet 2
 
-# Fonts.  Probably need to patch FVWM to support proper selection of Japanese
-# fonts...
-Style * Font 'xft:M+1P+IPAG:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-Style * IconFont 'xft:M+1P+IPAG:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-MenuStyle * Font 'xft:M+1P+IPAG:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
-MenuStyle * TitleFont 'xft:M+1P+IPAG:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+# "Meiryo Short" is a modified version of a font from Windows Vista.
+# Previous configs used M+1P+IPAG with reasonable results.
+# If FVWM supported multiple font selection, this would be nicer.
+Style * Font 'xft:Meiryo Short:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+Style * IconFont 'xft:Meiryo Short:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * Font 'xft:Meiryo Short:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * TitleFont 'xft:Meiryo Short:Bold:size=8:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
 
 MenuStyle * HilightBack, HilightTitleBack, Hilight3DOff
 MenuStyle * TrianglesSolid, TrianglesUseFore, TitleUnderlines1
 MenuStyle * SeparatorsLong, BorderWidth 1
 MenuStyle * ItemFormat "%.3s%.2|%2.4i%.5l%.5l%.5r%.5i%2.3>%1|"
 MenuStyle * MenuColorset 3, ActiveColorset 4, TitleColorset 8
-MenuStyle * VerticalTitleSpacing 3 2, VerticalItemSpacing 2 2
+MenuStyle * VerticalTitleSpacing 1 1, VerticalItemSpacing 1 2
 
 # Buttons: menu iconify maximize --title-- shade close
 Mouse 1 1 N Menu MenuWindow
index e96f33e8665a20c396801928a7cbf9d628acc0b7..acd270f073984f85bc12bc40e77bd79bd57640c0 100644 (file)
@@ -15,7 +15,7 @@ DestroyFunc MakeMenuWallpaper
 AddToFunc   MakeMenuWallpaper
  + I DestroyMenu recreate MenuWallpaper
  + I AddToMenu MenuWallpaper Wallpaper Title
- + I PipeRead '. $[FVWM_USERDIR]/scripts/bgmenu.sh $[BGROOT] MenuWallpaper'
+ + I PipeRead 'exec $[FVWM_USERDIR]/scripts/bgmenu.zsh $[BGROOT] MenuWallpaper'
 
 DestroyFunc SetWallpaper
 AddToFunc   SetWallpaper
diff --git a/config b/config
index 9a5a447e096964145fb82d06c1f5c0ee70b9a8bd..23c9f31e9da18588386449de14545a46566cee7f 100644 (file)
--- a/config
+++ b/config
@@ -4,21 +4,33 @@ ImagePath $[FVWM_USERDIR]/icons:$[FVWM_USERDIR]/pixmaps
 DestroyFunc InitFunction
 DestroyFunc StartFunction
 DestroyFunc ExitFunction
-SetEnv TERMINAL /home/nick/bin/urxvt.sh
+
+# Global environment
+SetEnv TERMINAL $[HOME]/bin/urxvt.sh
 PipeRead 'echo SetEnv HOST `hostname`'
 
+SetEnv MUSIC /home/music
+
+SetEnv XMODIFIERS '@im=uim'
+SetEnv GTK_IM_MODULE 'uim'
+SetEnv QT_IM_MODULE 'uim'
+
 # Global Features
 Read global/multiscreen
 Read global/fullscreen
 Read global/windowmenu
+Read global/appspecific
 
 # Machine-specific features
-Read $[HOST]/config
+PipeRead "[ -f '$[FVWM_USERDIR]/$[HOST]/config' ] \
+          && echo Read $[HOST]/config \
+         || echo Read default/config"
 
 # Virtual Desktops
 DesktopSize 6x1
 EdgeThickness 1
-EdgeResistance 1 0
+EdgeResistance 1
+Style * EdgeMoveDelay 1, EdgeMoveResistance 0
 EdgeScroll 0 0
 
 #####
diff --git a/default b/default
new file mode 120000 (symlink)
index 0000000..bb48baf
--- /dev/null
+++ b/default
@@ -0,0 +1 @@
+atropos
\ No newline at end of file
diff --git a/finial/config b/finial/config
new file mode 100644 (file)
index 0000000..1b32a61
--- /dev/null
@@ -0,0 +1,28 @@
+# Global definitions
+SetEnv MUSIC /stuff/music
+
+# Import common features
+Read common/bindings
+Read common/nickstheme
+
+# Bigger fonts must be set before including rootmenu
+Style * Font 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+Style * IconFont 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * Font 'xft:Meiryo Short:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+MenuStyle * TitleFont 'xft:Meiryo Short:Bold:size=9:minspace=true:rgba=rgb:antialias=true:encoding=iso10646-1'
+
+Read finial/rootmenu
+Read common/wallpaper
+Read common/panels
+Read common/modifier
+
+# Bindings for the modifier key
+Mouse 1 WFT 4  Mod_M1Func
+Mouse 2 WFT 4  Mod_M2Func
+Mouse 3 WFT 4  Mod_M3Func
+Mouse 1 WFT 42 Mod_M1Func
+Mouse 2 WFT 42 Mod_M2Func
+Mouse 3 WFT 42 Mod_M3Func
+
+# Struts for the pager.
+EwmhBaseStruts 0 0 0 42
diff --git a/finial/rootmenu b/finial/rootmenu
new file mode 100644 (file)
index 0000000..6d13d18
--- /dev/null
@@ -0,0 +1,43 @@
+MenuStyle * !TitleWarp
+
+CopyMenuStyle * MenuMPD
+MenuStyle MenuMPD ItemFormat "%.2|%3.5l%.5l%2.3>%-65.5r%.5i%1|"
+
+DestroyMenu MenuFvwmRoot
+AddToMenu   MenuFvwmRoot
++ DynamicPopupAction MakeMenuFvwmRoot
+
+DestroyFunc MakeMenuFvwmRoot
+AddToFunc   MakeMenuFvwmRoot
++ I DestroyMenu recreate MenuFvwmRoot
++ I PipeRead 'echo AddToMenu MenuFvwmRoot "$USER@`hostname`" Title'
++ I AddToMenu MenuFvwmRoot "Terminal%terminal.svg:16x16%" Exec exec $[TERMINAL]
++ I AddToMenu MenuFvwmRoot "Firefox%firefox.png%" Exec exec firefox
++ I PipeRead "xlsclients -a | grep ' gmpc$' >/dev/null || echo\
+       AddToMenu MenuFvwmRoot 'GMPC%gmpc.png%' Exec exec gmpc"
++ I AddToMenu MenuFvwmRoot "" Nop
++ I AddToMenu MenuFvwmRoot "Network%network.svg:16x16%" Popup MenuNetwork
++ I AddToMenu MenuFvwmRoot "" Nop
++ I AddToMenu MenuFvwmRoot "Wallpaper%wallpaper.svg:16x16%" Popup MenuWallpaper
++ I AddToMenu MenuFvwmRoot "Music%music.svg:16x16%" Popup MenuMPD
++ I AddToMenu MenuFvwmRoot "" Nop
++ I AddToMenu MenuFvwmRoot "Restart FVWM%reload.svg:16x16%" Restart
++ I AddToMenu MenuFvwmRoot "Exit FVWM%logout.svg:16x16%"\
+       Module FvwmForm FvwmForm-QuitVerify
+
+DestroyMenu MenuNetwork
+AddToMenu   MenuNetwork
++ "Pan Newsreader%pan.png%" Exec exec env LC_ALL=en_CA.UTF-8 pan
+
+DestroyMenu MenuMPD
+AddToMenu   MenuMPD
++ DynamicPopUpAction   MakeMenuMPD
++ DynamicPopDownAction KillMenuMPD
+ChangeMenuStyle MenuMPD MenuMPD
+
+DestroyFunc MakeMenuMPD
+AddToFunc   MakeMenuMPD
++ I DestroyMenu recreate MenuMPD
++ I PipeRead "exec $[FVWM_USERDIR]/scripts/mpdmenu.pl --menu MenuMPD"
+
+Mouse 3 R A Menu MenuFvwmRoot
diff --git a/global/appspecific b/global/appspecific
new file mode 100644 (file)
index 0000000..c96079b
--- /dev/null
@@ -0,0 +1 @@
+Style "Guild Wars" StaysOnTop
index 42df8579d2eeef09d5f2fd7c97359c49b44c475e..deb5e41b5fba8d0148c4762cabbfa107d87b7838 100644 (file)
@@ -1,4 +1,4 @@
-Key F10 W A DoFullScreen
+Key F10 W C DoFullScreen
 
 DestroyFunc Fullscreen
 AddToFunc   FullScreen
index 5d615419fccd772ef756bfffbb8cc030ac6f2d9e..ee422c60f42dbeca8607da75985d7837acd16aa4 100644 (file)
@@ -1,10 +1,12 @@
-CFLAGS  = -O2 -Wall -Wextra -Wno-sign-compare
+CFLAGS  = -O2 -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers
 LDFLAGS = 
 
-CC = c89
+CC = c99
 LD = $(CC)
 
 all: xaspect
+clean:
+       rm -f *.o xaspect
 
 .c.o:
        $(CC) -c -o $@ $(CFLAGS) $<
index 0dbc83dd1cb89a92a736746395498b063fc5db8a..3e07caac52727d80b63c5cce18d7e6bd8a83aad8 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
+#include <inttypes.h>
 #include <xcb/xcb.h>
 
 #define MKASPECT(w, h) { (double)w/h, #w ":" #h }
@@ -13,7 +14,7 @@ static struct aspect {
 } aspects[] = {
        MKASPECT(16, 10),
        MKASPECT(16, 9),
-       MKASPECT(8, 5),
+       MKASPECT(8, 3),
        MKASPECT(5, 4),
        MKASPECT(4, 3)
 };
@@ -57,17 +58,38 @@ char *testaspect(xcb_screen_t *screen)
        return best;
 }
 
+struct options {
+       char *displayname;
+       int showdimensions;
+} *parseoptions(int argc, char **argv)
+{
+       static struct options opts = { 0 };
+       int i;
+
+       for (i = 1; i < argc; i++) {
+               if (strcmp(argv[i], "-display") == 0) {
+                       if (++i < argc) {
+                               opts.displayname = argv[i];
+                               continue;
+                       }
+                       fprintf(stderr, "-display requires an argument\n");
+               } else if (strcmp(argv[i], "-dimensions") == 0) {
+                       opts.showdimensions = 1;
+               }
+       }
+
+       return &opts;
+}
+
 int main(int argc, char **argv)
 {
        xcb_connection_t *display;
        xcb_screen_t     *screen;
-       char *dpynam = NULL;
        int screen_num;
 
-       if (argc > 2 && strcmp(argv[1], "-display") == 0)
-               dpynam = argv[2];
+       struct options *opts = parseoptions(argc, argv);
        
-       display = xcb_connect(dpynam, &screen_num);
+       display = xcb_connect(opts->displayname, &screen_num);
        if (xcb_connection_has_error(display)) {
                fprintf(stderr, "Failed to open display.\n");
                xcb_disconnect(display);
@@ -81,6 +103,10 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
+       if (opts->showdimensions) {
+               printf("%" PRIu16 "x%" PRIu16 "-",
+                      screen->width_in_pixels, screen->height_in_pixels);
+       }
        printf("%s\n", testaspect(screen));
 
        xcb_disconnect(display);
similarity index 82%
rename from scripts/bgmenu.sh
rename to scripts/bgmenu.zsh
index ec6ae8f050dbc21f57551b2404be80041a5f8921..f6ac8ef22d0cf7cf943b72fedbe8e98c539d6e02 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/zsh
 # Generates an FVWM menu for selecting the PNG images found in a given
 # directory.  Thumbnails for the images are generated on the fly using convert
 # from ImageMagick, and stored in the .thumbs subdirectory.  The menu items
@@ -6,7 +6,7 @@
 
 menu="MenuWallpaper"
 func="SetWallpaper"
-thumber="$HOME/.fvwm/scripts/thumbnail.sh"
+thumber="$FVWM_USERDIR/scripts/thumbnail.zsh"
 
 if [ ! -d "$1" ]; then
        echo "usage: $0 <directory> [menuname]" 1>&2
@@ -14,7 +14,7 @@ if [ ! -d "$1" ]; then
 fi
 [ -n "$2" ] && menu="$2"
 
-for i in "$1"/*.png; do
+for i in "$1"/*$($FVWM_USERDIR/scripts/C/xaspect).png; do
        thumb="`$thumber --size x160 "$i"`"
        echo "AddToMenu $menu \"`basename "${i%.png}"`*$thumb*\" $func \"$i\""
 done
index 4639211c0a62f00b946c4e254dddf2dc60e90a29..ebd4c319a3883ffe8eb9c024e5ad4ee4aebeeed1 100755 (executable)
@@ -3,7 +3,7 @@
 use strict;
 
 use Getopt::Long;
-use IO::Socket;
+use IO::Socket::INET6;
 
 use constant {
        MPD_MJR_MIN => 0,
@@ -46,7 +46,7 @@ $artist = decode_utf8($artist) if defined($artist);
 $title  = decode_utf8($title)  if defined($title);;
 
 # Connect to MPD.
-my $sock = new IO::Socket::INET(
+my $sock = new IO::Socket::INET6(
        PeerAddr => $host,
        PeerPort => $port,
        Proto => 'tcp'
@@ -138,11 +138,11 @@ if (defined $album) {
                my $key      = $_;
                my $a_album  = sanitise($key);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--small", "--music", $albums{$key};
                my $thumb = <THUMB>;
                close THUMB;
-               die("Incompetent use of thumbnail.sh") if ($?);
+               die("Incompetent use of thumbnail.zsh") if ($?);
 
                $thumb =~ s/\n//sg;
                $thumb = "%$thumb%" if (-f $thumb);
@@ -234,11 +234,11 @@ if (defined $album) {
                $t_artist = sanitise($t_artist);
                $t_title  = sanitise($t_title);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--small", "--music", $t_file;
                my $thumb = <THUMB>;
                close(THUMB);
-               die("Incompetent use of thumbnail.sh") if ($?);
+               die("Incompetent use of thumbnail.zsh") if ($?);
 
                $thumb =~ s/\n//sg;
                $thumb = "%$thumb%" if (-f $thumb);
@@ -281,7 +281,7 @@ if (defined $album) {
                }
                die("Failed data query\n") unless (keys(%entry) > 0);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--image", "--music",  $entry{file};
                my $thumb = <THUMB>;
                my $scan  = <THUMB>;
diff --git a/scripts/randombg.pl b/scripts/randombg.pl
new file mode 100755 (executable)
index 0000000..941ebe7
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $FVWM = (defined $ENV{FVWM_USERDIR}) ? $ENV{FVWM_USERDIR}
+                                        : $ENV{HOME}."/.fvwm";
+
+die ("usage: randombg.pl <directory>") if (! -d $ARGV[0]);
+
+open XASPECT, "-|", "$FVWM/scripts/C/xaspect", "-dimensions";
+my $aspect = <XASPECT>;
+close XASPECT;
+die ("Incompetent use of xaspect") if ($?);
+
+$aspect =~ s/(^\s*)|(\s*$)//g;
+
+opendir WALLPAPER, $ARGV[0];
+my @dir = grep(/\Q$aspect\E\.png$/, readdir WALLPAPER);
+closedir WALLPAPER;
+
+print $ARGV[0] . "/" . $dir[int(rand(@dir))] . "\n";
diff --git a/scripts/thumbnail.sh b/scripts/thumbnail.sh
deleted file mode 100755 (executable)
index 958092c..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-
-music=/home/music
-thumbs="$HOME/.fvwm/.thumbs"
-
-if [ ! -d "$thumbs" ]; then
-       mkdir "$thumbs" || exit 1
-fi
-
-size="x128"
-printimg=""
-ismusic=""
-
-while [ "${1#--}" != "$1" -a "$1" != "-" ]; do
-       if [ "$1" = "--small" ]; then
-               size="56"
-       elif [ "$1" = "--size" ]; then
-               size="$2"
-               shift
-       elif [ "$1" = "--music" ]; then
-               ismusic="yes"
-       elif [ "$1" = "--image" ]; then
-               printimg="yes"
-       else
-               echo "unrecognised option: $1" 1>&2
-               exit 1
-       fi
-       shift
-done
-[ "$1" = "-" ] && shift
-
-if ! expr match "$size" '^\([0-9]*\(x[0-9]\+\)\?\)$' &>/dev/null; then
-       echo "invalid size specification: $size" 1>&2
-       exit 1
-fi
-
-if [ -z "$1" ]; then
-       echo "usage: thumbnail.sh [--small|--size <spec>] [--image] [--music] path" 1>&2
-       exit 1
-fi
-
-if [ -n "$ismusic" ]; then
-       path="$music/`dirname "${1#$music}"`/cover.jpg"
-       [ ! -f "$path" ] && path="${path%jpg}png"
-else
-       path="$1"
-fi
-
-[ ! -f "$path" ] && exit 0
-
-image="`readlink -f -- "$path"`"
-[ ! -f "$image" ] && exit 0
-
-thumb="$thumbs/`echo -n $image | md5sum - | cut -d ' ' -f 1`_$size.png"
-if [ -f "$thumb" ]; then
-       mtime_s="`stat -c %Y -- "$image"`"
-       mtime_t="`stat -c %Y -- "$thumb"`"
-       if [ "$mtime_s" -gt "$mtime_t" ]; then
-               convert -scale "$size" "$image" "$thumb"
-       fi
-else
-       convert -scale "$size" "$image" "$thumb"
-fi
-
-echo "$thumb"
-[ -n "$printimg" ] && echo "$image"
-exit 0
diff --git a/scripts/thumbnail.zsh b/scripts/thumbnail.zsh
new file mode 100755 (executable)
index 0000000..62294b6
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/zsh
+
+if [[ -z "$MUSIC" ]]; then
+       MUSIC=/home/music
+fi
+
+thumbs="$HOME/.fvwm/.thumbs"
+
+if ! [[ -d "$thumbs" ]]; then
+       mkdir "$thumbs" || exit 1
+fi
+
+size="x128"
+printimg=""
+ismusic=""
+
+while [[ "${1#--}" != "$1" && "$1" != "-" ]]; do
+       if   [[ "$1" == "--small" ]]; then
+               size="56"
+       elif [[ "$1" == "--size"  ]]; then
+               size="$2"
+               shift
+       elif [[ "$1" = "--music"  ]]; then
+               ismusic="yes"
+       elif [[ "$1" = "--image"  ]]; then
+               printimg="yes"
+       else
+               echo "unrecognised option: $1" 1>&2
+               exit 1
+       fi
+       shift
+done
+[ "$1" = "-" ] && shift
+
+if ! [[ "$size" =~ '^([0-9]*(x[0-9]+)?)$' ]]; then
+       echo "invalid size specification: $size" 1>&2
+       exit 1
+fi
+
+if [[ -z "$1" ]]; then
+       echo "usage: thumbnail.zsh [--small|--size <spec>] [--image] [--music] path" 1>&2
+       exit 1
+fi
+
+if [[ -n "$ismusic" ]]; then
+       imgpath="$MUSIC/$(dirname "${1#$MUSIC}")/cover.jpg"
+       [[ ! -f "$imgpath" ]] && imgpath="${imgpath%jpg}png"
+else
+       imgpath="$1"
+fi
+
+[[ ! -f "$imgpath" ]] && exit 0
+
+image="$(readlink -f -- "$imgpath")"
+[[ ! -f "$image" ]] && exit 0
+
+thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"
+if [[ -f "$thumb" ]]; then
+       mtime_s="$(stat -c %Y -- "$image")"
+       mtime_t="$(stat -c %Y -- "$thumb")"
+       if [ "$mtime_s" -gt "$mtime_t" ]; then
+               convert -scale "$size" "$image" "$thumb"
+       fi
+else
+       convert -scale "$size" "$image" "$thumb"
+fi
+
+echo "$thumb"
+[ -n "$printimg" ] && echo "$image"
+exit 0