This page presents code associated with the module/unit named above.
#!/bin/sh
# this is a proof-of-concept demo
# and shows that MQTT might work for chat
# however, shell scripting is not the way to
# do that and should not be modified further
host=$1
port=$2
channel=$3
name=$4
password=$5
PATH=/usr/bin:/bin
c="chat-${USER}"
tmux new-session -s $c -n chat -d \
"trap '' INT;
while read -p 'Chat: ' m; do
mosquitto_pub \
-h $host -p $port \
-u $name -P $password \
-t $channel \
-m \"\$(date -u +%H:%M) ${USER}: \${m}\"
done"
mosquitto_sub \
-h $host -p $port \
-u $name -P $password \
-t $channel \
| tmux split-window -t $c:chat -I -b -d -l 90% &
chld=$!
echo $chld
tmux set-option -t $c:chat status-right ' #{=21:pane_title} %b-%d' \; \
set-option -t $c:chat pane-border-status top \; \
select-pane -t $c:chat.0 -T chat \; \
select-pane -t $c:chat.1 -T ${USER} \; \
# set-hook -t $c:chat.1 pane-exited "kill-pane -t $c:chat.0"
tmux attach-session -t $c
kill -HUP $chld
exit 0