X-Git-Url: https://git.draconx.ca/gitweb/mpdhacks.git/blobdiff_plain/adba02b582138375bfd3adc9f68c0cd398827e7a..e49c1f846176562de0978ba1cd445b50b1094a2d:/mpdmenu.pl?ds=sidebyside diff --git a/mpdmenu.pl b/mpdmenu.pl index a12eb4c..3a84f78 100755 --- a/mpdmenu.pl +++ b/mpdmenu.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Copyright © 2008,2010,2012,2019 Nick Bowler +# Copyright © 2008,2010,2012,2020 Nick Bowler # # Silly little script to generate an FVWM menu with various bits of MPD # status information and controls. @@ -24,6 +24,9 @@ use Scalar::Util qw(reftype); use List::Util qw(any max); use FindBin; +use lib "$FindBin::Bin"; +use MPDHacks; + use constant { MPD_MJR_MIN => 0, MPD_MNR_MIN => 21, @@ -42,29 +45,10 @@ my ($topmenu, $menu); my $mode = "top"; my %artistids; -# Quotes the argument so that it is presented as a single argument to MPD -# at the protocol level. This also works OK for most FVWM arguments. -sub escape { - my $s = @_[0] // $_; - - # No way to encode literal newlines in the protocol, so we - # convert any newlines in the arguments into a space, which - # can help with quoting. - $s =~ s/\n/ /g; - - if (/[ \t\\"]/) { - $s =~ s/[\\"]/\\$&/g; - return "\"$s\""; - } - - $s =~ s/^\s*$/"$&"/; - return $s; -} - # Submit a command to the MPD server; each argument to this function # is quoted and sent as a single argument to MPD. sub mpd_exec { - my $cmd = join(' ', map { escape } @_); + my $cmd = join(' ', map { MPD::escape } @_); print $sock "$cmd\n"; } @@ -74,7 +58,7 @@ sub fvwm_cmd_unquoted { } sub fvwm_cmd { - fvwm_cmd_unquoted(map { escape } @_); + fvwm_cmd_unquoted(map { MPD::escape } @_); } # Quotes the argument in such a way that it is passed unadulterated by @@ -243,8 +227,8 @@ sub top_track_cover { my $cover = mpd_cover_filename($file); $cover = fvwm_shell_literal($cover // $file); - fvwm_cmd_unquoted("AddToMenu", escape($menu), - escape($entry->{thumb}), + fvwm_cmd_unquoted("AddToMenu", MPD::escape($menu), + MPD::escape($entry->{thumb}), "Exec", "exec", "geeqie", $cover); } }