wifi 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. # Copyright (C) 2014 Alexander Keller <github@nycroth.com>
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. #------------------------------------------------------------------------
  14. INTERFACE="${BLOCK_INSTANCE:-wlan0}"
  15. #------------------------------------------------------------------------
  16. # As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
  17. # connection (think desktop), the corresponding block should not be displayed.
  18. [[ ! -d /sys/class/net/${INTERFACE}/wireless ]] ||
  19. [[ "$(cat /sys/class/net/$INTERFACE/operstate)" = 'down' ]] && exit
  20. #------------------------------------------------------------------------
  21. QUALITY=$(grep $INTERFACE /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')
  22. #------------------------------------------------------------------------
  23. echo $QUALITY% # full text
  24. echo $QUALITY% # short text
  25. # color
  26. if [[ $QUALITY -ge 80 ]]; then
  27. echo "#00FF00"
  28. elif [[ $QUALITY -lt 80 ]]; then
  29. echo "#FFF600"
  30. elif [[ $QUALITY -lt 60 ]]; then
  31. echo "#FFAE00"
  32. elif [[ $QUALITY -lt 40 ]]; then
  33. echo "#FF0000"
  34. fi