Merge pull request #80 from AlexanderPavlenko/master
[shell-fm.git] / scripts / unix.pl
blob38b96eb814ea5066434bfff238278834118258da
1 #!/usr/bin/perl
3 # Shell.FM UNIX Socket Control
4 # Copyright (C) by Jonas Kramer. All rights reserved.
5 # Published under the terms of the GNU General Public License (GPL).
7 # Usage: $0 <command>
9 # See the shell-fm(1) manual for a list of commands.
12 use strict;
13 use warnings;
15 use IO::Socket::UNIX;
16 use IO::File;
19 die "Usage: $0 <command>\n" unless @ARGV;
22 my $rc = new IO::File("$ENV{HOME}/.shell-fm/shell-fm.rc");
24 die "Can't open configuration. $!.\n" unless $rc;
27 my $path;
29 for($rc->getlines) {
30 $path = $1 if /^\s*unix\s*=\s*([^#\s]+)/;
33 $rc->close;
35 die "No socket path found.\n" unless $path;
38 my $socket = new IO::Socket::UNIX($path);
40 die "Failed to create socket. $!.\n" unless $socket;
42 $socket->print("@ARGV\n") or die("Failed to send command. $!.\n");
43 $socket->print("detach\n");
45 my $reply = $socket->getline;
47 print $reply if $reply;
49 $socket->close;