/
esend.sh
executable file
·106 lines (94 loc) · 1.81 KB
/
esend.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
strlen () {
str="`echo $1`"
echo ${#str}
}
mkmsg () {
echo "|`strlen "$1"`|$1"
}
print_usage () {
echo $0: $1
echo USAGE: $0 '[[host] port] message'
echo You can also try
echo ' $' $0 [[host] port] register
echo and then
echo ' $' $0 [[host] port] example
echo to see an example.
}
check_arguments () {
[[ $port =~ [0-9]+ ]]
}
which nc &> /dev/null
if [ ! $? -eq 0 ]
then
echo "This utility needs the nc (netcat) command."
exit 1
fi
case $# in
1)
host='localhost'
port=5000
msg=$1
;;
2)
host='localhost'
port=$1
msg=$2
;;
3)
host=$1
port=$2
msg=$3
;;
*)
print_usage "wrong number of arguments $#"
exit 1
;;
esac
example_registration='(:register "esend.sh"
:handler-fn (lambda (id data)
(let ((buf (get-buffer-create "*esend.sh example*")))
(with-current-buffer buf
;;(set-buffer buf)
(erase-buffer)
(insert data)))))'
example_msg='(:id "esend.sh"
:notification (:text "esend.sh"
:face :success
:mouse-1 (lambda nil (interactive) (switch-to-buffer "*esend.sh example*"))
:help "Example tooltip")
:data "Some example data")
'
foo=`nc -h 2>&1`
nc_impl=GNU
echo $foo | grep 'OpenBSD' > /dev/null && nc_impl=BSD
echo $foo | grep 'nmap' > /dev/null && nc_impl=NMAP
case $nc_impl in
"BSD")
NC="nc"
;;
"NMAP")
NC="nc"
;;
"GNU")
NC="nc -c"
;;
esac
check_arguments
case $msg in
"register")
msg=$example_registration
;;
"example")
msg=$example_msg
;;
esac
if [ $? -eq 0 ]
then
m=`mkmsg "$msg"`
echo Sending "'$m'" to $host:$port
echo $m | $NC $host $port
else
print_usage "wrong argument format: port = $port"
fi
# mkmsg $1 | nc