File: unix.pl

package info (click to toggle)
shell-fm 0.7%2Bgit20100414-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 444 kB
  • ctags: 305
  • sloc: ansic: 4,422; makefile: 135; python: 80; haskell: 76; sh: 67; perl: 19
file content (48 lines) | stat: -rwxr-xr-x 849 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl

# Shell.FM UNIX Socket Control
# Copyright (C) by Jonas Kramer. All rights reserved.
# Published under the terms of the GNU General Public License (GPL).
#
#   Usage: $0 <command>
#
# See the shell-fm(1) manual for a list of commands.


use strict;
use warnings;

use IO::Socket::UNIX;
use IO::File;


die "Usage: $0 <command>\n" unless @ARGV;


my $rc = new IO::File("$ENV{HOME}/.shell-fm/shell-fm.rc");

die "Can't open configuration. $!.\n" unless $rc;


my $path;

for($rc->getlines) {
	$path = $1 if /^\s*unix\s*=\s*([^#\s]+)/;
}

$rc->close;

die "No socket path found.\n" unless $path;


my $socket = new IO::Socket::UNIX($path);

die "Failed to create socket. $!.\n" unless $socket;

$socket->print("@ARGV\n") or die("Failed to send command. $!.\n");

my $reply = $socket->getline;

print $reply if $reply;

$socket->close;