diff options
-rw-r--r-- | debian/changelog | 3 | ||||
-rwxr-xr-x | mpinsert | 42 |
2 files changed, 36 insertions, 9 deletions
diff --git a/debian/changelog b/debian/changelog index d98847e..dc6546a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ mpdtoys (0.15) UNRELEASED; urgency=low * mprompt: Add -t switch, enabling a terse output mode where the output is intended to be piped to a speech synth such as esound. + * mpinsert: Add -n switch, which prints the playlist position of + added items. This is useful if you want to insert an item and then jump + to it. -- Joey Hess <joeyh@debian.org> Sat, 11 Apr 2009 17:08:10 -0400 @@ -10,19 +10,29 @@ mpinsert - insert song after currently playing song =head1 SYNOPSIS -mpinsert [song ..] +mpinsert [-n] [song ...] =head1 DESCRIPTION -B<mpinsert> inserts a song into the playlist directly after the currently -playing song. +B<mpinsert> inserts a song (or songs) into the playlist directly after +the currently playing song. If no songs are specified on the command line, it will read a list from stdin. +=head1 OPTIONS + +=over 4 + +=item -n + +Print the playlist position number that each song was inserted at. + +=back + =head1 AUTHOR -Copyright 2007 Joey Hess <joey@kitenet.net> +Copyright 2007-2009 Joey Hess <joey@kitenet.net> Licensed under the GNU GPL version 2 or higher. @@ -30,6 +40,16 @@ http://kitenet.net/~joey/code/mpdtoys =cut +use Getopt::Long; +my $shownum=0; +GetOptions( + "n" => \$shownum, +) || usage(); + +sub usage { + die "Usage: mpinsert [-n] [song ...]\n"; +} + my @list=@ARGV; if (! @list) { while (<>) { @@ -47,13 +67,17 @@ foreach my $item (reverse @list) { die "no item specified to insert\n"; } $pl->add($item); + my @items=$pl->as_items; + if (! @items) { + die "failed!"; + } + my $pos=$#items; # move from end to just after current if ($current) { - my @items=$pl->as_items; - if (! @items) { - die "failed!"; - } - $pl->move($#items, $current->pos+1); + $pos=$current->pos+1; + $pl->move($#items, $pos); } + + print STDOUT ($pos+1)."\n" if $shownum; } |