Skip to content

Instantly share code, notes, and snippets.

@ssledz
Last active February 9, 2017 09:07
Show Gist options
  • Save ssledz/fce7dbde2582e2144213b85bf6908876 to your computer and use it in GitHub Desktop.
Save ssledz/fce7dbde2582e2144213b85bf6908876 to your computer and use it in GitHub Desktop.
mcabber eventcmd for awesome wm
#!/bin/bash
DBG=0
dbg() {
[[ $DBG == 1 ]] && (1>&2 echo "[DEBUG] : "$1)
}
info() {
echo "[INFO] : $1"
}
warn() {
echo "[WARN] : $1"
}
err() {
(1>&2 echo "[ERROR] : $1")
}
show_help() {
cat << EOF
Usage: ${0##*/} -t title -m message -y timeout -s screen -b background -f foreground -n margin -w width [-d] [-h]
Make notification in awesome wm.
-t tile Title.
-m message
-y timeout Timeout, exmaple 0
-s screen Screen, example 2
-b background Background in format #535d9a
-f foreground Foreground in format #FFFFFF
-n margin Maring, example 8
-w width Width, example 302
-d Dry run.
-h Print this help.
EOF
}
dry_run=0
tile=
message=
timeout=0
screen=2
bg=#427142
fg=#FFFFFF
margin=8
width=302
while getopts "t:m:y:s:b:f:n:w:dh" opt; do
case $opt in
t)
title=$OPTARG
;;
m)
message=$OPTARG
;;
y)
timeout=$OPTARG
;;
s)
screen=$OPTARG
;;
b)
bg=$OPTARG
;;
f)
fg=$OPTARG
;;
n)
margin=$OPTARG
;;
w)
width=$OPTARG
;;
d)
dry_run=1
;;
h)
show_help
exit 0
;;
\?)
echo
echo " Invalid option: -$OPTARG" >&2
show_help
exit 1
;;
*)
echo
show_help
exit 2
;;
esac
done
required=(title message)
for req in ${required[@]}; do
[[ -z ${!req} ]] && echo && echo " Please specify $req" && show_help && exit 1
done
[[ $dry_run -eq 1 ]] && info "Dry run"
msg="local naughty = require(\"naughty\"); naughty.notify({ \
title = \"$title\",\
text = \"$message\",\
timeout = $timeout,\
screen = $screen,\
bg = \"$bg\",\
fg = \"$fg\",\
margin = $margin,\
width = $width,\
run = function (notification) notification.die() end })"
echo -e $msg | /usr/bin/awesome-client -
#!/bin/bash
AW_ALERT=~/.mcabber/aw-alert.sh
LOG=~/.mcabber/eventcmd.log
EVENT_LOG=~/.mcabber/event.log
exec >> $LOG 2>&1
DBG=0
dbg() {
[[ $DBG == 0 ]] && echo "[DEBUG] : "$1
}
info() {
echo "[INFO] : $1"
}
warn() {
echo "[WARN] : $1"
}
err() {
echo "[ERROR] : $1"
}
event_type=$1
arg1=$2
arg2=$3
filename=$4
dbg "$event_type $arg1 $arg2 $filename"
echo "$event_type $arg1 $arg2 $filename" >> $EVENT_LOG
title="mcabber"
timeout=10000
new_message_in() {
local jid=$1
dbg "./aw-alert.sh -y $timeout -t \"$title\" -m \"New message from $jid.\" -w 700"
$AW_ALERT -y $timeout -t "$title" -m "New message from $jid." -w 700
}
status_message() {
local jid=$1
local status=$2
dbg "./aw-alert.sh -y $timeout -t \"$title\" -m \"Status changed for $jid to $status.\" -w 700"
$AW_ALERT -y $timeout -t "$title" -m "Status changed for $jid to $status." -w 700
}
if [ $event_type = "MSG" ]; then
case "$arg1" in
IN)
# Incoming message from buddy $arg2
new_message_in "$arg2"
if [ -n "$filename" -a -f "$filename" ]; then
# We could process filename here...
echo > /dev/null
fi
;;
MUC)
# Groupchat message in room $arg2
if [ -n "$filename" -a -f "$filename" ]; then
echo > /dev/null
# We could process filename here...
fi
;;
OUT)
# Outgoing message for buddy $arg2
;;
esac
elif [ $event_type = "STATUS" ]; then
# Buddy $arg2 status is $arg1 (_, O, I, F, D, N, A)
status_message "$arg2" "$arg1"
echo > /dev/null
elif [ $event_type = "UNREAD" ]; then
# $arg1 contains 4 numbers separated with space chars:
# Nr of unread buffers, nr of unread buffers with attention sign,
# nr of MUC unread buffers, nr of MUC unread buffers with attention sign.
echo > /dev/null
fi
@ssledz
Copy link
Author

ssledz commented Feb 8, 2017

The ~/.mcabber/mcabberrc file has the following options set to get this to work:

set events_command = ~/.mcabber/eventcmd
set eventcmd_use_nickname = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment