diff --git a/home/desktop-sway.nix b/home/desktop-sway.nix
index e78f417..bf90962 100644
--- a/home/desktop-sway.nix
+++ b/home/desktop-sway.nix
@@ -459,5 +459,50 @@ border-size=1
};
};
};
+
+ xdg.configFile."i3blocks/bin/wifi".source = ./sway-i3block/wifi;
+ xdg.configFile."i3blocks/bin/battery".source = ./sway-i3block/battery;
+ xdg.configFile."i3blocks/config".text = ''
+align=center
+separator=false
+# separator_block_width=15
+markup=pango
+# color=#f8f8f2
+color=#e4e4e4
+
+[root]
+label=💽
+command=df -h / | awk 'FNR==2 { gsub(/[A-Za-z]/, ""); printf " %iG\n", $4 }'
+interval=3
+
+[memory]
+label=💾
+command=free --giga | awk 'FNR==2{ printf " %iG\n", $7 }'
+interval=2
+
+[wifi]
+label=
+command=~/.config/i3blocks/bin/wifi
+interval=5
+color=#589df6
+
+[volume]
+command=if ponymix -t sink is-muted; then echo '🔇'; else if test $(ponymix -t sink get-volume) -gt 50; then echo -n "🔊"; else echo -n "🔉"; fi; echo "$(ponymix -t sink get-volume)%"; fi
+interval=1
+
+[mic]
+command=if ponymix -t source is-muted; then echo ''; else echo " $(ponymix -t source get-volume)%"; fi
+interval=1
+
+[battery]
+command=~/.config/i3blocks/bin/battery
+interval=2
+color=#ff5555
+
+[time]
+label=⏰
+command=date '+%T'
+interval=1
+ '';
};
}
diff --git a/home/sway-i3block/battery b/home/sway-i3block/battery
new file mode 100755
index 0000000..9137c00
--- /dev/null
+++ b/home/sway-i3block/battery
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2016 James Murphy
+# Licensed under the GPL version 2 only
+#
+# A battery indicator blocklet script for i3blocks
+
+import re
+from subprocess import check_output
+
+status = check_output(['acpi'], universal_newlines=True)
+
+if not status:
+ # stands for no battery found
+ fulltext = "🔞🔋"
+ percentleft = 100
+else:
+ # if there is more than one battery in one laptop, the percentage left is
+ # available for each battery separately, although state and remaining
+ # time for overall block is shown in the status of the first battery
+ batteries = status.split("\n")
+ state_batteries=[]
+ commasplitstatus_batteries=[]
+ percentleft_batteries=[]
+ time = ""
+ for battery in batteries:
+ if battery!='':
+ state_batteries.append(battery.split(": ")[1].split(", ")[0])
+ commasplitstatus = battery.split(", ")
+ if not time:
+ time = commasplitstatus[-1].strip()
+ # check if it matches a time
+ time = re.match(r"(\d+):(\d+)", time)
+ if time:
+ time = ":".join(time.groups())
+ timeleft = " ({})".format(time)
+ else:
+ timeleft = ""
+
+ p = int(commasplitstatus[1].rstrip("%\n"))
+ if p>0:
+ percentleft_batteries.append(p)
+ commasplitstatus_batteries.append(commasplitstatus)
+ state = state_batteries[0]
+ commasplitstatus = commasplitstatus_batteries[0]
+ if percentleft_batteries:
+ percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries))
+ else:
+ percentleft = 0
+
+ # stands for charging
+ #FA_LIGHTNING = "\uf0e7"
+ #FA_LIGHTNING = "⚡"
+ FA_LIGHTNING = "⚡"
+
+ # stands for plugged in
+ #FA_PLUG = "\uf1e6"
+ #FA_PLUG = "🔌"
+ FA_PLUG = "🔌"
+
+ # stands for using battery
+ #FA_BATTERY = "\uf240"
+ FA_BATTERY = "🔋"
+
+ # stands for unknown status of battery
+ #FA_QUESTION = "\uf128"
+ FA_QUESTION = "❔"
+
+
+ if state == "Discharging":
+ fulltext = FA_BATTERY + " "
+ elif state == "Full":
+ fulltext = FA_PLUG + " "
+ timeleft = ""
+ elif state == "Unknown":
+ fulltext = FA_BATTERY + " " + FA_QUESTION + " "
+ timeleft = ""
+ else:
+ fulltext = FA_LIGHTNING + " " + FA_PLUG + " "
+
+ percentcolor = "#FFFFFF"
+
+ if percentleft < 10:
+ # exit code 33 will turn background red
+ percentcolor = "#FFFFFF"
+ elif percentleft < 20:
+ percentcolor = "#FF3300"
+ elif percentleft < 30:
+ percentcolor = "#FF6600"
+ elif percentleft < 40:
+ percentcolor = "#FF9900"
+ elif percentleft < 50:
+ percentcolor = "#FFCC00"
+ elif percentleft < 60:
+ percentcolor = "#FFFF00"
+ elif percentleft < 70:
+ percentcolor = "#FFFF33"
+ elif percentleft < 80:
+ percentcolor = "#FFFF66"
+
+ fulltext += '{}%'.format(percentcolor, percentleft)
+ fulltext += timeleft
+
+print(fulltext)
+print(fulltext)
+if percentleft < 10:
+ exit(33)
diff --git a/home/sway-i3block/wifi b/home/sway-i3block/wifi
new file mode 100755
index 0000000..1a2525e
--- /dev/null
+++ b/home/sway-i3block/wifi
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (C) 2014 Alexander Keller
+
+# 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 .
+
+#------------------------------------------------------------------------
+
+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
+
+COLOR_MAC="${COLOR_MAC:-grey}"
+COLOR_FREQ="${COLOR_FREQ:-white}"
+COLOR_SIGNAL="${COLOR_SIGNAL:-#589df6}"
+COLOR_BANDWIDTH="${COLOR_BANDWIDTH:-grey}"
+
+echo -n " ";
+iw dev $INTERFACE link | head -8 | grep -vE '(SSID|TX|RX)' \
+ | sed -e "s/.*to .*\([0-9a-f:]\{5\}\) .on.*/\1<\/span>/g; s/^\s//g" \
+ | tr -d "\n" \
+ | sed -e "s/freq: / /g; s/signal: /<\/span> /g; s/mrx bitrate: \([0-9\.]*\).*tx bitrate: \([0-9\.]*\).*/<\/span> \1\/\2<\/span>/g;"
+echo ""