2017-02-08 22:33:21 +01:00
|
|
|
#!/usr/bin/env bash
|
2009-04-08 17:30:18 +02:00
|
|
|
|
2015-07-14 00:20:31 +02:00
|
|
|
# Use bash's pipefail option to get errors during failure in a command
|
|
|
|
# pipeline. This is useful to get notified about an error from dbus-send
|
|
|
|
# when used with "|tail".
|
|
|
|
set -o pipefail
|
2009-04-18 12:26:31 +02:00
|
|
|
|
2016-10-09 22:36:03 +02:00
|
|
|
if [ -t 0 ] # is a tty.
|
2009-04-18 12:26:31 +02:00
|
|
|
then
|
2015-07-14 00:20:31 +02:00
|
|
|
# rlwrap provides readline functionality for "read", which is more enhanced
|
|
|
|
# than bash's "read" itself.
|
2016-10-07 23:32:58 +02:00
|
|
|
# It can be disabled/overridden using 'AWESOME_RLWRAP= awesome-client'.
|
|
|
|
if [ -z "${AWESOME_RLWRAP+x}" ]; then
|
|
|
|
AWESOME_RLWRAP="$(which rlwrap 2>/dev/null)"
|
|
|
|
fi
|
|
|
|
if [ -n "$AWESOME_RLWRAP" ]
|
2009-04-30 00:27:03 +02:00
|
|
|
then
|
2010-12-16 11:55:51 +01:00
|
|
|
if [ "$A_RERUN" = "" ]
|
|
|
|
then
|
2016-10-07 23:32:58 +02:00
|
|
|
A_RERUN="no" exec $AWESOME_RLWRAP $0 "$@"
|
2010-12-16 11:55:51 +01:00
|
|
|
fi
|
2015-07-14 00:20:31 +02:00
|
|
|
READ_CMD="read"
|
2010-12-16 11:55:51 +01:00
|
|
|
else
|
2015-07-14 00:20:31 +02:00
|
|
|
# No rlwrap: use bash's readline.
|
|
|
|
READ_CMD="read -e"
|
2009-06-12 09:14:29 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2009-04-08 17:30:18 +02:00
|
|
|
DBUS_SEND=dbus-send
|
|
|
|
|
2009-05-09 21:11:06 +02:00
|
|
|
which ${DBUS_SEND} > /dev/null
|
|
|
|
if test $? = 1
|
2009-04-08 17:30:18 +02:00
|
|
|
then
|
|
|
|
echo "E: Unable to find" ${DBUS_SEND}
|
2009-05-09 21:10:24 +02:00
|
|
|
exit 1
|
2009-04-08 17:30:18 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
DBUS_PATH=/
|
2016-12-21 02:03:03 +01:00
|
|
|
DBUS_DEST=org.awesomewm.awful
|
2009-06-15 20:52:40 +02:00
|
|
|
DBUS_METHOD=${DBUS_DEST}.Remote.Eval
|
2009-04-08 17:30:18 +02:00
|
|
|
|
2016-10-09 22:36:03 +02:00
|
|
|
FATAL_ERRORS=1
|
2009-04-08 17:30:18 +02:00
|
|
|
a_dbus_send()
|
|
|
|
{
|
2015-07-14 00:20:31 +02:00
|
|
|
$DBUS_SEND --dest=$DBUS_DEST --type=method_call --print-reply \
|
|
|
|
$DBUS_PATH $DBUS_METHOD string:"$1" | tail -n +2
|
|
|
|
ret=$?
|
2016-08-31 15:53:27 +02:00
|
|
|
if [ "$ret" != 0 ] && [ "$FATAL_ERRORS" != 0 ]; then
|
2015-07-14 00:20:31 +02:00
|
|
|
echo "E: $DBUS_SEND failed." >&2
|
|
|
|
exit $ret
|
|
|
|
fi
|
2009-04-08 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 12:58:54 +02:00
|
|
|
if [ $# -ne 0 ]
|
|
|
|
then
|
|
|
|
for arg in "$@" ; do
|
|
|
|
a_dbus_send "$arg"
|
|
|
|
done
|
2016-10-09 22:36:03 +02:00
|
|
|
elif [ -t 0 ]
|
2010-12-16 11:55:51 +01:00
|
|
|
then
|
2016-10-09 22:36:03 +02:00
|
|
|
FATAL_ERRORS=0
|
2015-07-14 00:20:31 +02:00
|
|
|
while $READ_CMD -p "awesome# " -r line
|
2010-12-16 11:55:51 +01:00
|
|
|
do
|
2015-07-25 23:33:40 +02:00
|
|
|
if [ "$line" = "" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2010-12-16 11:55:51 +01:00
|
|
|
a_dbus_send "$line"
|
|
|
|
done
|
|
|
|
else
|
2015-07-14 00:20:31 +02:00
|
|
|
a_dbus_send "$(cat)"
|
2010-12-16 11:55:51 +01:00
|
|
|
fi
|
2015-12-12 17:34:16 +01:00
|
|
|
|
|
|
|
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|