]> git.draconx.ca Git - mpdhacks.git/commitdiff
mpdmenu: Use FindBin module to locate auxiliary scripts.
authorNick Bowler <nbowler@draconx.ca>
Thu, 27 Jun 2019 23:18:12 +0000 (19:18 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 29 Jun 2019 16:05:59 +0000 (12:05 -0400)
With this separated from my FVWM config, the other scripts can be
located using FindBin assuming everything lives in the same directory.

mpdmenu.pl

index 963934aadc12e28804a5097d8167ad93fb24e87e..be2c08fb46f8ed0f6cebb7a3f0651610e1fc7e9b 100755 (executable)
@@ -13,6 +13,7 @@ use strict;
 
 use Getopt::Long;
 use IO::Socket::INET6;
+use FindBin;
 
 use constant {
        MPD_MJR_MIN => 0,
@@ -25,6 +26,8 @@ use open qw(:std :utf8);
 binmode(STDOUT, ":utf8");
 use Encode;
 
+my $SELF = "$FindBin::Bin/$FindBin::Script";
+
 sub cmd
 {
        print "$_[0]\n";
@@ -115,7 +118,7 @@ if (defined $album) {
                $t_title  = sanitise($t_title, 0);
 
                my $cmd = sprintf "AddToMenu $menu \"%d\t%s - %s\""
-                                 ." Exec exec $FVWM/scripts/mpdexec.pl"
+                                 ." Exec exec $FindBin::Bin/mpdexec.pl"
                                  ." playid %d",
                                  $t_trackno, $t_artist, $t_title, $t_id;
 
@@ -150,7 +153,7 @@ if (defined $album) {
                my $key      = $_;
                my $a_album  = sanitise($key, 1);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
+               open THUMB, "-|", "$FindBin::Bin/thumbnail.zsh",
                                         "--small", "--music", $albums{$key};
                my $thumb = <THUMB>;
                close THUMB;
@@ -166,7 +169,7 @@ if (defined $album) {
                cmd("DestroyFunc MakeMenuMPDArt_$i");
                cmd("AddToFunc   MakeMenuMPDArt_$i
                     + I DestroyMenu MenuMPDArt_$i
-                    + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl "
+                    + I -PipeRead \"exec $SELF "
                           ."--menu MenuMPDArt_$i "
                           ."--album  ".shellify($key, 1)." "
                           ."--artist ".shellify($artist, 1)."\"");
@@ -251,7 +254,7 @@ if (defined $album) {
                $t_artist = sanitise($t_artist, 1);
                $t_title  = sanitise($t_title, 1);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
+               open THUMB, "-|", "$FindBin::Bin/thumbnail.zsh",
                                         "--small", "--music", $t_file;
                my $thumb = <THUMB>;
                close(THUMB);
@@ -261,7 +264,7 @@ if (defined $album) {
                $thumb = "%$thumb%" if (-f $thumb);
 
                cmd("AddToMenu $menu \"$thumb$t_artist - $t_title\""
-                   ." Exec exec $FVWM/scripts/mpdexec.pl"
+                   ." Exec exec $FindBin::Bin/mpdexec.pl"
                    ." playid $t_id");
        }
 } # end use locale workaround
@@ -300,7 +303,7 @@ if (defined $album) {
                }
                die("Failed data query\n") unless (keys(%entry) > 0);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
+               open THUMB, "-|", "$FindBin::Bin/thumbnail.zsh",
                                         "--image", "--music",  $entry{file};
                my $thumb = <THUMB>;
                my $scan  = <THUMB>;
@@ -328,25 +331,25 @@ if (defined $album) {
 
        if ($state eq "play" || $state eq "pause") {
                cmd("AddToMenu $menu \"\t\tNext%$icons/next.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl next");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl next");
                cmd("AddToMenu $menu \"\t\tPause%$icons/pause.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl pause");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl pause");
                cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl play");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl play");
                cmd("AddToMenu $menu \"\t\tStop%$icons/stop.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl stop");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl stop");
                cmd("AddToMenu $menu \"\t\tPrev%$icons/prev.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl previous");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl previous");
        } elsif ($state eq "stop") {
                cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" "
-                       ."Exec exec $FVWM/scripts/mpdexec.pl play");
+                       ."Exec exec $FindBin::Bin/mpdexec.pl play");
        } else {
                die("Unknown MPD state!\n");
        }
 
        cmd("AddToMenu $menu \"\" Nop");
        cmd("AddToMenu $menu \"\t\tShuffle%$icons/shuffle.svg:16x16%\" "
-               ."Exec exec $FVWM/scripts/mpdexec.pl shuffle");
+               ."Exec exec $FindBin::Bin/mpdexec.pl shuffle");
 
        cmd("DestroyMenu MenuMPDTitle");
        cmd("AddToMenu   MenuMPDTitle  DynamicPopUpAction MakeMenuMPDTitle");
@@ -358,14 +361,14 @@ if (defined $album) {
        cmd("DestroyFunc MakeMenuMPDTitle");
        cmd("AddToFunc   MakeMenuMPDTitle
             + I DestroyMenu MenuMPDTitle
-            + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl "
+            + I -PipeRead \"exec $SELF "
                           ."--menu MenuMPDTitle "
                           ."--title ".shellify($entry{Title}, 1)."\"");
 
        cmd("DestroyFunc MakeMenuMPDAlbum");
        cmd("AddToFunc   MakeMenuMPDAlbum
             + I DestroyMenu MenuMPDAlbum
-            + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl "
+            + I -PipeRead \"exec $SELF "
                           ."--menu MenuMPDAlbum "
                           ."--album  ".shellify($entry{Album}, 1)." "
                           ."--artist ".shellify($entry{Artist}, 1)."\"");
@@ -373,7 +376,7 @@ if (defined $album) {
        cmd("DestroyFunc MakeMenuMPDArtist");
        cmd("AddToFunc   MakeMenuMPDArtist
             + I DestroyMenu MenuMPDArtist
-            + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl "
+            + I -PipeRead \"exec $SELF "
                           ."--menu MenuMPDArtist "
                           ."--artist ".shellify($entry{Artist}, 1)."\"");