-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvtm-cmd
85 lines (73 loc) · 1.69 KB
/
dvtm-cmd
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
DO_RET=n
usage() {
echo "usage: dvtm-cmd [OPTIONS] CMD ARGS"
echo "OPTIONS:"
echo " -c PATH PATH to CMD FIFO (default is \$DVTM_CMD_FIFO)"
echo " -r PATH PATH to RET FIFO (default is \$DVTM_RET_FIFO)"
echo " -y PATH PATH to CPY FIFO (default is \$DVTM_CPY_FIFO)"
echo " -i PATH,- PATH to input file or \"-\" for stdin"
}
while [ $# -gt 0 ]; do
case $1 in
"-c")
FIFO_CMD=$2
shift 1
;;
"-r")
FIFO_RET=$2
shift 1
;;
"-y")
FIFO_CPY=$2
shift 1
;;
"-i")
INPUT=$2
shift 1
;;
*)
break
;;
esac
shift 1
done
[ -z "${FIFO_CMD}" ] && FIFO_CMD=${DVTM_CMD_FIFO}
[ -z "${FIFO_RET}" ] && FIFO_RET=${DVTM_RET_FIFO}
[ -z "${FIFO_CPY}" ] && FIFO_CPY=${DVTM_CPY_FIFO}
if [ ! -e "${FIFO_CMD}" ]; then
echo "error: cmd fifo does not exist"
usage
exit 1
fi
cmd_args="$@"
case $1 in
"settitle")
echo -ne "\033]0;$2\007"
exit 0
;;
"copybuf")
[ "${2}" == "put" ] && cat $INPUT > ${FIFO_CPY}
[ "${2}" == "get" ] && DO_RET=y
;;
"sendtext")
[ -n "${INPUT}" ] && {
cmd_args="${cmd_args} -"
cat $INPUT > ${FIFO_CPY}
}
;;
"capture")
DO_RET=y
;;
esac
echo "$cmd_args" > $FIFO_CMD
if [ "${DO_RET}" == "y" ]; then
if [ ! -e "${FIFO_RET}" ]; then
echo "error: ret fifo does not exist"
usage
exit 1
fi
read count < $FIFO_RET
[ -z "$count" ] && exit 0
[ $count -gt 0 ] && head -n $count $FIFO_RET
fi