Skip to content

Commit 2c867be

Browse files
author
Menachem Dov Mostowicz
committed
ssid: Get the SSID of current wifi connection
1 parent 21708ed commit 2c867be

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

ssid/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ssid
2+
3+
Show the SSID of the current wifi connection.
4+
If no instance is specified, wlan0 is used.
5+
6+
# Config
7+
8+
```
9+
[ssid]
10+
command=$SCRIPT_DIR/ssid
11+
#INTERFACE=wlan0
12+
interval=60
13+
```

ssid/i3blocks.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[ssid]
2+
command=$SCRIPT_DIR/ssid
3+
#INTERFACE=wlan0
4+
interval=60

ssid/ssid

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# Copyright (C) 2014 Alexander Keller <[email protected]>
3+
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#------------------------------------------------------------------------
18+
if [[ -z "$INTERFACE" ]] ; then
19+
INTERFACE="${BLOCK_INSTANCE:-wlan0}"
20+
fi
21+
#------------------------------------------------------------------------
22+
23+
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
24+
# connection (think desktop), the corresponding block should not be displayed.
25+
# Similarly, if the wifi interface exists but no connection is active, show
26+
# nothing
27+
[[ ! -d /sys/class/net/"${INTERFACE}"/wireless || \
28+
"$(cat /sys/class/net/"$INTERFACE"/operstate)" = 'down' ]] && exit
29+
30+
#------------------------------------------------------------------------
31+
32+
SSID=$(iw "$INTERFACE" info | awk '/ssid/ {print $2}')
33+
34+
#------------------------------------------------------------------------
35+
36+
echo "$SSID" # full text
37+
echo "$SSID" # short text
38+
echo "#00FF00" # color

0 commit comments

Comments
 (0)