Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use IO::Socket::UNIX;
- use IO::Select;
- use URI::Encode;
- $|++;
- my $encoder = URI::Encode->new({encode_reserved => 0});
- my $client = IO::Socket::UNIX->new(
- Type => SOCK_STREAM(),
- Peer => "$ENV{HOME}/vlc.sock",
- ) || die $@;
- my $s = IO::Select->new();
- $s->add(\*STDIN);
- $s->add($client);
- my $target = ''; # target path here
- my $target_file;
- while( my @sock = $s->can_read() ) {
- my $sock = $sock[0];
- if( $sock == $client ) {
- $sock->flush();
- my $line = $sock->getline();
- print $sock ("\n");
- next unless( $line =~ m/(file.*?)\s/ );
- my $uri = $1;
- my $path = $encoder->decode( $uri );
- $path =~ s|file://||;
- $target_file = $path;
- print "\nCurrently working on: $target_file\n:";
- } else {
- my $command = $sock->getline();
- chomp $command;
- next unless( $command );
- print "\nGot from keyboard: $command\n";
- print "\tTarget: $target_file\n";
- my $target_path = "$target$command/";
- system( 'mkdir', '-p', $target_path ) unless( -d $target_path );
- system( 'mv', $target_file, $target_path );
- print "\tMoved to: $target_path\n\n";
- }
- }
Add Comment
Please, Sign In to add comment