summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-05-09 17:05:49 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-05-09 17:05:49 -0400
commit1f9d74c0ca917a6ef764b8011d5f65ae67360de2 (patch)
tree6bfd96a9c6c2bbc441979c1d23383dc6bc507620
parent0e97b2e6bce092bd85e0a53afcab3b6455cc79c7 (diff)
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.
-rw-r--r--debian/changelog3
-rwxr-xr-xmpinsert42
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
diff --git a/mpinsert b/mpinsert
index 480d7cf..eef85f2 100755
--- a/mpinsert
+++ b/mpinsert
@@ -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;
}