Mirror of Awesome WM window manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

awesome-client 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env bash
  2. # Use bash's pipefail option to get errors during failure in a command
  3. # pipeline. This is useful to get notified about an error from dbus-send
  4. # when used with "|tail".
  5. set -o pipefail
  6. if [ -t 0 ] # is a tty.
  7. then
  8. # rlwrap provides readline functionality for "read", which is more enhanced
  9. # than bash's "read" itself.
  10. # It can be disabled/overridden using 'AWESOME_RLWRAP= awesome-client'.
  11. if [ -z "${AWESOME_RLWRAP+x}" ]; then
  12. AWESOME_RLWRAP="$(which rlwrap 2>/dev/null)"
  13. fi
  14. if [ -n "$AWESOME_RLWRAP" ]
  15. then
  16. if [ "$A_RERUN" = "" ]
  17. then
  18. A_RERUN="no" exec "$AWESOME_RLWRAP" "$0" "$@"
  19. fi
  20. READ_ARGS=""
  21. else
  22. # No rlwrap: use bash's readline.
  23. READ_ARGS="-e"
  24. fi
  25. fi
  26. DBUS_SEND=dbus-send
  27. which ${DBUS_SEND} > /dev/null
  28. if test $? = 1
  29. then
  30. echo "E: Unable to find" ${DBUS_SEND}
  31. exit 1
  32. fi
  33. DBUS_PATH=/
  34. DBUS_DEST=org.awesomewm.awful
  35. DBUS_METHOD=${DBUS_DEST}.Remote.Eval
  36. FATAL_ERRORS=1
  37. a_dbus_send()
  38. {
  39. $DBUS_SEND --dest=$DBUS_DEST --type=method_call --print-reply \
  40. $DBUS_PATH $DBUS_METHOD string:"$1" | tail -n +2
  41. ret=$?
  42. if [ "$ret" != 0 ] && [ "$FATAL_ERRORS" != 0 ]; then
  43. echo "E: $DBUS_SEND failed." >&2
  44. exit $ret
  45. fi
  46. }
  47. print_help()
  48. {
  49. echo "Usage: awesome-client [-h|--help] [command [command...]]
  50. awesome window manager remote execution
  51. awesome-client is a remote command line interface to awesome.
  52. It communicates with awesome via D-Bus, allowing remote execution of Lua code.
  53. Run without a command to enter REPL (read-eval-print-loop) mode.
  54. For examples see \`man awesome-client\`."
  55. }
  56. if [ $# -ne 0 ]
  57. then
  58. # check for command-line arguments
  59. ARGS=()
  60. for arg in "$@"; do
  61. if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then
  62. print_help
  63. exit 0
  64. else
  65. ARGS+=("$arg")
  66. fi
  67. done
  68. # run arguments
  69. for arg in "${ARGS[@]}"; do
  70. a_dbus_send "$arg"
  71. done
  72. elif [ -t 0 ]
  73. then
  74. FATAL_ERRORS=0
  75. while read $READ_ARGS -p "awesome# " -r line
  76. do
  77. if [ "$line" = "" ]; then
  78. continue
  79. fi
  80. a_dbus_send "$line"
  81. done
  82. else
  83. a_dbus_send "$(cat)"
  84. fi
  85. # vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80