3 # Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net> |
3 # Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net> |
4 # |
4 # |
5 # Copy this script on your system and specify the path for mcabber |
5 # Copy this script on your system and specify the path for mcabber |
6 # by setting the 'extsay_script_path' option. |
6 # by setting the 'extsay_script_path' option. |
7 # |
7 # |
|
8 # Usage: extsay.sh [jid [winsplit [height]]] |
|
9 # |
8 # This script is free software. |
10 # This script is free software. |
9 # MiKael, 2010-04-02 |
11 # MiKael, 2010-04-03 |
10 |
12 |
11 FIFOPATH="$HOME/.mcabber/mcabber.fifo" |
13 FIFOPATH="$HOME/.mcabber/mcabber.fifo" |
12 |
14 |
13 tmpdir=${TMPDIR:=$TMP} |
15 tmpdir=${TMPDIR:=$TMP} |
14 tmpdir=${tmpdir:="/tmp"} |
16 tmpdir=${tmpdir:="/tmp"} |
15 editor=${EDITOR:="vi"} |
17 editor=${EDITOR:="vi"} |
16 |
18 |
17 jid="." |
19 jid="." |
18 |
20 |
19 # Use argument as a recipient JID, if it is provided |
21 # Use argument as a recipient JID, if it is provided |
20 [ $# -eq 1 ] && jid=$1 |
22 [ $# -ge 1 ] && jid=$1 |
|
23 [ $# -ge 2 ] && winsplit=$2 |
|
24 [ $# -ge 3 ] && winheight=$3 |
21 |
25 |
22 # Leave if the FIFO is not available |
26 # Leave if the FIFO is not available |
23 [ -p $FIFOPATH ] || exit 255 |
27 [ -p $FIFOPATH ] || exit 255 |
24 |
28 |
25 tf=$(mktemp $tmpdir/extsay-XXXXXX) || exit 255 |
29 tf=$(mktemp $tmpdir/extsay-$jid-XXXXXX) || exit 255 |
|
30 |
|
31 if [ x$winsplit = x"winsplit" ]; then |
|
32 screen -r -X other |
|
33 screen -r -X split |
|
34 screen -r -X focus down |
|
35 screen -r -X other |
|
36 |
|
37 [ $winheight -gt 0 ] && screen -r -X resize $winheight |
|
38 fi |
26 |
39 |
27 # This will not work if the editor runs in the background! |
40 # This will not work if the editor runs in the background! |
28 $editor $tf |
41 $editor $tf |
29 |
42 |
30 # Send the message using MCabber's pipe |
43 # Send the message using MCabber's pipe |
33 else |
46 else |
34 cmd="echo [extsay] The file has not been modified. Message cancelled." |
47 cmd="echo [extsay] The file has not been modified. Message cancelled." |
35 fi |
48 fi |
36 echo $cmd >> $FIFOPATH |
49 echo $cmd >> $FIFOPATH |
37 |
50 |
|
51 if [ x$winsplit = x"winsplit" ]; then |
|
52 screen -r -X remove |
|
53 fi |
|
54 |
38 # Do not remove the file too soon |
55 # Do not remove the file too soon |
39 setsid sh -c "cd / && sleep 20 && rm $tf & :" /dev/null 2>&1 < /dev/null |
56 setsid sh -c "cd / && sleep 20 && rm $tf & :" /dev/null 2>&1 < /dev/null |
40 |
57 |
41 exit 0 |
58 exit 0 |