author | Mikael Berthe <mikael@lilotux.net> |
Sun, 04 Apr 2010 16:00:35 +0200 | |
changeset 34 | 105fdf20c1c1 |
parent 32 | 1867a9047524 |
permissions | -rwxr-xr-x |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
1 |
#! /bin/sh |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 |
# |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 |
# Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net> |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
4 |
# |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 |
# Copy this script on your system and specify the path for mcabber |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 |
# by setting the 'extsay_script_path' option. |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 |
# |
24
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
8 |
# Usage: extsay.sh [jid [winsplit [height]]] |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
9 |
# |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
# This script is free software. |
24
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
11 |
# MiKael, 2010-04-03 |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 |
|
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
FIFOPATH="$HOME/.mcabber/mcabber.fifo" |
22
b6b45c2eb022
[extsay] Improve script portability
Mikael Berthe <mikael@lilotux.net>
parents:
21
diff
changeset
|
14 |
|
b6b45c2eb022
[extsay] Improve script portability
Mikael Berthe <mikael@lilotux.net>
parents:
21
diff
changeset
|
15 |
tmpdir=${TMPDIR:=$TMP} |
b6b45c2eb022
[extsay] Improve script portability
Mikael Berthe <mikael@lilotux.net>
parents:
21
diff
changeset
|
16 |
tmpdir=${tmpdir:="/tmp"} |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 |
editor=${EDITOR:="vi"} |
22
b6b45c2eb022
[extsay] Improve script portability
Mikael Berthe <mikael@lilotux.net>
parents:
21
diff
changeset
|
18 |
|
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 |
jid="." |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
|
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 |
# Use argument as a recipient JID, if it is provided |
24
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
22 |
[ $# -ge 1 ] && jid=$1 |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
23 |
[ $# -ge 2 ] && winsplit=$2 |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
24 |
[ $# -ge 3 ] && winheight=$3 |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
|
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
# Leave if the FIFO is not available |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
[ -p $FIFOPATH ] || exit 255 |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 |
|
27
4f1cbafb569c
[extsay] Remove resource from the jid used for the temporary file name
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
29 |
tf=$(mktemp $tmpdir/extsay-${jid%%/*}-XXXXXX) || exit 255 |
24
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
30 |
|
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
31 |
if [ x$winsplit = x"winsplit" ]; then |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
32 |
screen -r -X other |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
33 |
screen -r -X split |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
34 |
screen -r -X focus down |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
35 |
screen -r -X other |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
36 |
|
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
37 |
[ $winheight -gt 0 ] && screen -r -X resize $winheight |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
38 |
fi |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 |
|
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
40 |
# This will not work if the editor runs in the background! |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
41 |
$editor $tf |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
42 |
|
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 |
# Send the message using MCabber's pipe |
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 |
if [ -s $tf ]; then |
28 | 45 |
cmd="say_to -q -f $tf $jid" |
23
cf95a475825c
[extsay] Multiple improvements
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
46 |
else |
cf95a475825c
[extsay] Multiple improvements
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
47 |
cmd="echo [extsay] The file has not been modified. Message cancelled." |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
48 |
fi |
23
cf95a475825c
[extsay] Multiple improvements
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
49 |
echo $cmd >> $FIFOPATH |
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 |
|
32
1867a9047524
[extsay] This change fixes a resize issue on my system
Mikael Berthe <mikael@lilotux.net>
parents:
28
diff
changeset
|
51 |
# Do not remove the file too soon |
1867a9047524
[extsay] This change fixes a resize issue on my system
Mikael Berthe <mikael@lilotux.net>
parents:
28
diff
changeset
|
52 |
setsid sh -c "cd / && sleep 20 && rm $tf & :" /dev/null 2>&1 < /dev/null |
1867a9047524
[extsay] This change fixes a resize issue on my system
Mikael Berthe <mikael@lilotux.net>
parents:
28
diff
changeset
|
53 |
|
24
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
54 |
if [ x$winsplit = x"winsplit" ]; then |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
55 |
screen -r -X remove |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
56 |
fi |
81cbb47f1aa6
[extsay] Add options to split the screen window
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
57 |
|
21
9798e3aaa851
Add module extsayng, rename previous one to extsay_old
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
58 |
exit 0 |