summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.config/wmii-hg/rbar_wifi29
1 files changed, 25 insertions, 4 deletions
diff --git a/.config/wmii-hg/rbar_wifi b/.config/wmii-hg/rbar_wifi
index 1a4f71a..c77efa5 100755
--- a/.config/wmii-hg/rbar_wifi
+++ b/.config/wmii-hg/rbar_wifi
@@ -1,5 +1,17 @@
#!/usr/bin/env bash
+in_array() {
+ local needle straw haystack
+ needle=$1
+ haystack=("${@:2}")
+ for straw in "${haystack[@]}"; do
+ if [[ "$needle" = "$straw" ]]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
update() {
local id
id=$1
@@ -23,10 +35,19 @@ update() {
esac
parts+=("$(ifdata -pa "$iface")")
IFS='|'
- printf '%s\n' "${iface}:${parts[*]}"
- done | cat -n | while read -r n line; do
- printf "label %s\n" "$line" | write "${id}.${n}"
- done
+ printf '%s %s\n' "$iface" "${parts[*]}"
+ done | (
+ ifaces=()
+ while read -r iface data; do
+ ifaces+=("$iface")
+ printf "label %s\n" "${iface}:${data}" | write "${id}.${iface}"
+ done
+ for file in "${XDG_RUNTIME_DIR}"/wmii*/rbar/"${id}".*; do
+ if ! in_array "${file##*/"$id".}" "${ifaces[@]}"; then
+ rm -f -- "$file"
+ fi
+ done
+ )
sleep 1
done
}