Skip to content

Commit

Permalink
wifi: add default block
Browse files Browse the repository at this point in the history
  • Loading branch information
kb100 committed Dec 10, 2017
1 parent 454581f commit f857ee6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wifi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# wifi

Show the strength of your wifi connection.
If no instance is specified, wlan0 is used.

![](wifi.png)

# Config

```
[wifi]
command=$SCRIPT_DIR/wifi
label=wifi:
#instance=wlp3s0
interval=60
```
5 changes: 5 additions & 0 deletions wifi/i3blocks.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[wifi]
command=$SCRIPT_DIR/wifi
label=wifi:
#instance=wlp3s0
interval=60
46 changes: 46 additions & 0 deletions wifi/wifi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Copyright (C) 2014 Alexander Keller <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#------------------------------------------------------------------------

INTERFACE="${BLOCK_INSTANCE:-wlan0}"

#------------------------------------------------------------------------

# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${INTERFACE}/wireless ]] ||
[[ "$(cat /sys/class/net/$INTERFACE/operstate)" = 'down' ]] && exit

#------------------------------------------------------------------------

QUALITY=$(grep $INTERFACE /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')

#------------------------------------------------------------------------

echo $QUALITY% # full text
echo $QUALITY% # short text

# color
if [[ $QUALITY -ge 80 ]]; then
echo "#00FF00"
elif [[ $QUALITY -ge 60 ]]; then
echo "#FFF600"
elif [[ $QUALITY -ge 40 ]]; then
echo "#FFAE00"
else
echo "#FF0000"
fi
Binary file added wifi/wifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f857ee6

Please sign in to comment.