mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
4ce16084ff
Commit78abb4a54c
made awesome-client fail with a non-zero exit code when sending a command that it got from stdin failed. Commitf0f31bc305
added the possibility to specify commands to run as arguments to awesome-client. However, the exit code was still zero even when such a command failed. This commit makes awesome-client signal errors with its exit code even for code specified via arguments. Note that this means that following arguments will not be executed if some argument fails. I do not know if this is the best behaviour or not, but I am implementing it like this here due to its simplicity to implement. Signed-off-by: Uli Schlachter <psychon@znc.in>
73 lines
1.5 KiB
Bash
Executable file
73 lines
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# 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
|
|
|
|
tty 2>&1 > /dev/null
|
|
ISATTY=$?
|
|
|
|
if [ "$ISATTY" = 0 ]
|
|
then
|
|
# rlwrap provides readline functionality for "read", which is more enhanced
|
|
# than bash's "read" itself.
|
|
RLWRAP=$(which rlwrap 2>/dev/null)
|
|
if [ "$RLWRAP" != "" ]
|
|
then
|
|
if [ "$A_RERUN" = "" ]
|
|
then
|
|
A_RERUN="no" exec $RLWRAP $0 "$@"
|
|
fi
|
|
READ_CMD="read"
|
|
else
|
|
# No rlwrap: use bash's readline.
|
|
READ_CMD="read -e"
|
|
fi
|
|
fi
|
|
|
|
DBUS_SEND=dbus-send
|
|
|
|
which ${DBUS_SEND} > /dev/null
|
|
if test $? = 1
|
|
then
|
|
echo "E: Unable to find" ${DBUS_SEND}
|
|
exit 1
|
|
fi
|
|
|
|
DBUS_PATH=/
|
|
DBUS_DEST=org.naquadah.awesome.awful
|
|
DBUS_METHOD=${DBUS_DEST}.Remote.Eval
|
|
|
|
a_dbus_send()
|
|
{
|
|
$DBUS_SEND --dest=$DBUS_DEST --type=method_call --print-reply \
|
|
$DBUS_PATH $DBUS_METHOD string:"$1" | tail -n +2
|
|
ret=$?
|
|
if [ "$ret" != 0 ] && [ "$FATAL_ERRORS" != 0 ]; then
|
|
echo "E: $DBUS_SEND failed." >&2
|
|
exit $ret
|
|
fi
|
|
}
|
|
|
|
FATAL_ERRORS="$ISATTY"
|
|
if [ $# -ne 0 ]
|
|
then
|
|
FATAL_ERRORS="1"
|
|
for arg in "$@" ; do
|
|
a_dbus_send "$arg"
|
|
done
|
|
elif [ "$ISATTY" = 0 ]
|
|
then
|
|
while $READ_CMD -p "awesome# " -r line
|
|
do
|
|
if [ "$line" = "" ]; then
|
|
continue
|
|
fi
|
|
a_dbus_send "$line"
|
|
done
|
|
else
|
|
a_dbus_send "$(cat)"
|
|
fi
|
|
|
|
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|