summaryrefslogtreecommitdiff
path: root/mybar
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-12-01 23:59:31 +0100
committerKevin Chabowski <kevin@kch42.de>2013-12-01 23:59:31 +0100
commitb3eaf4d3e1e3031054fadbc47eb749f47f901e83 (patch)
treebb595da73ea856a77e15420b43d3b43c003963dd /mybar
downloaddotfiles-b3eaf4d3e1e3031054fadbc47eb749f47f901e83.tar.gz
dotfiles-b3eaf4d3e1e3031054fadbc47eb749f47f901e83.tar.bz2
dotfiles-b3eaf4d3e1e3031054fadbc47eb749f47f901e83.zip
Initial commit
Diffstat (limited to 'mybar')
-rwxr-xr-xmybar/mybar.awk135
-rwxr-xr-xmybar/mybar.sh63
-rwxr-xr-xmybar/wifi.awk22
3 files changed, 220 insertions, 0 deletions
diff --git a/mybar/mybar.awk b/mybar/mybar.awk
new file mode 100755
index 0000000..d16dbf1
--- /dev/null
+++ b/mybar/mybar.awk
@@ -0,0 +1,135 @@
+#!/bin/awk -f
+
+BEGIN {
+ date=""
+ cpu=""
+ mem=""
+ battery=""
+ window=""
+ wminfo=""
+ redshift=""
+ wifi=""
+
+ cpu_pused=0
+ cpu_ptotal=0
+}
+$1 == "date" {
+ date = $2 " " $3 " " $4
+}
+$1 == "cpu" {
+ used=$2+$3+$4+$7+$8;
+ total=used+$5+$6;
+
+ if(total - cpu_ptotal != 0) {
+ tmp=int(100*(used-cpu_pused)/(total-cpu_ptotal));
+ } else {
+ tmp=0
+ }
+ if(tmp > 100) {
+ tmp=0
+ }
+ cpu_pused=used
+ cpu_ptotal=total
+
+ if(tmp < 10) {
+ sp = " "
+ } else if(tmp < 100) {
+ sp = " "
+ } else {
+ sp = ""
+ }
+ f = int((tmp+5) / 10)
+ tmp = "CPU: " sp tmp "%"
+ cpu = "\\u3" substr(tmp, 1, f) "\\u4" substr(tmp, 1+f, 10-f) "\\ur"
+}
+$1 == "window" {
+ window=substr($0, 7, length($0)-6);
+}
+$1 == "mem" {
+ if($2 < 10) {
+ sp = " "
+ } else if($2 < 100) {
+ sp = " "
+ } else if($2 < 1000){
+ sp = " "
+ } else {
+ sp = ""
+ }
+ tmp = "Mem:" sp $2 "MB"
+ f = int(($2 / 4096 * 10) + .5)
+ mem = "\\u3" substr(tmp, 1, f) "\\u4" substr(tmp, 1+f, 10-f) "\\ur"
+}
+$1 == "bspwm" {
+ #wminfo=substr($0, 7, length($0)-6)
+ split(substr($0, 7, length($0)-6), info, ":")
+
+ wminfo=" \\u5"
+ sep=""
+ for(i in info) {
+ raw=info[i]
+ k=substr(raw, 1, 1)
+ v=substr(raw, 2, length(raw)-1)
+
+ add = ""
+ if(k=="u") add = "\\b2" v
+ else if(k=="U") add = "\\u3\\b2" v
+ else if(k=="f") add = "\\f1" v
+ else if(k=="F") add = "\\f1\\u3" v
+ else if(k=="o") add = v
+ else if(k=="O") add = "\\u3" v
+
+ if(add != "") {
+ wminfo = wminfo sep add "\\fr\\u5\\br"
+ sep = " "
+ }
+ }
+ wminfo = wminfo "\\ur"
+}
+$1 == "redshift" {
+ if($2 == "-x") {
+ redshift = "\\u2"
+ } else {
+ redshift = ""
+ }
+}
+$1 == "bat" {
+ val=$3
+ if($2 == "Full") {
+ val=100
+ }
+ if($2 == "Charging") {
+ tmp="-charging-"
+ } else {
+ tmp="Bat:"
+
+ if(val < 10) {
+ sp=" "
+ } else if(val < 100) {
+ sp=" "
+ } else {
+ sp=" "
+ }
+ tmp=tmp sp val "%"
+ }
+ f = int((val+5) / 10)
+ battery = "\\u3" substr(tmp, 1, f) "\\u4" substr(tmp, 1+f, 10-f) "\\ur"
+ if((val < 5) && ($2 != "Charging")) {
+ battery="\\b2" battery "\\br"
+ }
+}
+$1 == "wifi" {
+ if($2 == "-") {
+ wifi=""
+ } else {
+ tmp=$2
+ if(length(tmp) > 10) {
+ tmp=substr(tmp, 1, 8) ".."
+ }
+ f = int(($3+5) / 10)
+ wifi = "\\u3" substr(tmp, 1, f) "\\u4" substr(tmp, 1+f, 10-f) "\\ur"
+ }
+}
+{
+ print "\\l" wminfo "\\c" window "\\r" wifi " " battery " " mem " " cpu " " redshift "R\\ur " date " "
+ fflush()
+}
diff --git a/mybar/mybar.sh b/mybar/mybar.sh
new file mode 100755
index 0000000..5adc11e
--- /dev/null
+++ b/mybar/mybar.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+update_wminfo() {
+ bspc control --subscribe | while read line; do
+ echo "bspwm $line"
+ done
+}
+
+update_time() {
+ while true; do
+ date '+date %a. %Y-%b-%d %H:%M'
+ sleep 1
+ done
+}
+
+update_mem() {
+ while true; do
+ awk '
+$1 == "MemTotal:" { total=$2; }
+$1 == "MemFree:" { free=$2; }
+$1 == "Buffers:" { buf=$2; }
+$1 == "Cached:" { cache=$2; }
+END { print "mem " int((total - free - buf - cache) / 1024); }' < /proc/meminfo
+ sleep 2
+ done
+}
+
+update_cpu() {
+ while true; do
+ grep '^cpu\s' < /proc/stat
+ sleep 2
+ done
+}
+
+update_bat() {
+ while true; do
+ battery -f "bat %s %d"
+ sleep 2
+ done
+}
+
+update_wifi() {
+ while true; do
+ wicd-cli -y -d | ~/mybar/wifi.awk
+ sleep 2
+ done
+}
+
+trap 'trap - TERM; kill 0' INT TERM QUIT EXIT
+
+update_wminfo > "$BAR_FIFO" &
+update_time > "$BAR_FIFO" &
+update_mem > "$BAR_FIFO" &
+update_cpu > "$BAR_FIFO" &
+
+if test $(hostname) = "kch42-notebook"; then
+ update_bat > "$BAR_FIFO" &
+ update_wifi > "$BAR_FIFO" &
+fi
+
+xtitle -sf 'window %s' > "$BAR_FIFO" &
+
+cat "$BAR_FIFO" | ~/mybar/mybar.awk | bar
diff --git a/mybar/wifi.awk b/mybar/wifi.awk
new file mode 100755
index 0000000..90d3f9d
--- /dev/null
+++ b/mybar/wifi.awk
@@ -0,0 +1,22 @@
+#!/bin/awk -f
+
+BEGIN {
+ FS=":"
+ essid="-"
+ qual="0"
+}
+$1 == "Essid" {
+ split($2, parts, " ")
+ sep=""
+ essid = ""
+ for(i in parts) {
+ essid = sep parts[i]
+ sep="_"
+ }
+}
+$1 == "Quality" {
+ qual = $2
+}
+END {
+ print "wifi " essid " " qual
+}