From 6d6c4cbf5e70092b30c3496e9003d454ef80f857 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 27 Jun 2019 19:18:12 -0400 Subject: [PATCH] mpdmenu: Use FindBin module to locate auxiliary scripts. With this separated from my FVWM config, the other scripts can be located using FindBin assuming everything lives in the same directory. --- mpdmenu.pl | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mpdmenu.pl b/mpdmenu.pl index 963934a..be2c08f 100755 --- a/mpdmenu.pl +++ b/mpdmenu.pl @@ -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 = ; 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 = ; 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 = ; my $scan = ; @@ -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)."\""); -- 2.43.0