File: zcontrol

package info (click to toggle)
shell-fm 0.7%2Bgit20100414-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 444 kB
  • ctags: 305
  • sloc: ansic: 4,422; makefile: 135; python: 80; haskell: 76; sh: 67; perl: 19
file content (29 lines) | stat: -rwxr-xr-x 770 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
#!/usr/bin/env zsh
# zcontrol, shell-fm remote control script. Copyright (C) 2006 by Jonas Kramer.
# Published under the terms of the GNU General Public License (GPL).

setopt extendedglob
export BIND="127.0.0.1" PORT="54311"

if [[ $# -eq 0 || "$1" != (skip|love|ban|quit|play) ]]; then
	print "Usage: $0 (skip|love|ban|quit|play) [argument]" >&2
	exit -1
fi

if [[ -r "$HOME/.shell-fm/shell-fm.rc" ]]; then
	for LINE in ${(f)"$(<$HOME/.shell-fm/shell-fm.rc)"}; do
		LINE="${LINE%%\#*}"
		if [[ "$LINE" == (#b)(bind|port)[\ ]#"="[\ ]#(#b)([^\ ]##)* ]]; then
			export ${(U)match[1]}="$match[2]"
		fi
	done
fi

zmodload zsh/net/tcp
if ! ztcp "$BIND" "$PORT"; then
	print "Couldn't connect to [$BIND:$PORT]." >&2
	exit -1
fi

print -u $REPLY "$1" $@[2,-1]
ztcp -c $REPLY