summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/battery.sh60
-rwxr-xr-xscripts/eth.sh15
-rwxr-xr-xscripts/print_bash_color37
-rwxr-xr-xscripts/wifi.sh42
4 files changed, 154 insertions, 0 deletions
diff --git a/scripts/battery.sh b/scripts/battery.sh
new file mode 100755
index 0000000..05ac440
--- /dev/null
+++ b/scripts/battery.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+# dotfiles -- scripts/battery.sh
+# author: johannst
+
+bat="${BLOCK_INSTANCE:-BAT0}"
+[[ ! -f "/sys/class/power_supply/$bat/type" ]] && exit 0
+
+show_bat_use_design_capacity=0
+show_bat_status=0
+show_bat_color_output=0
+for arg in "$@"; do
+ case $arg in
+ -dc | --design_capacity) show_bat_use_design_capacity=1
+ ;;
+ -s | --status) show_bat_status=1
+ ;;
+ -c | --color) show_bat_color_output=1
+ ;;
+ *) # ignore unknown
+ ;;
+ esac
+done
+
+# Unknown, Charging, Discharging, Full
+BAT_STATUS=$(cat /sys/class/power_supply/$bat/status)
+BAT_NOW=$(cat /sys/class/power_supply/$bat/charge_now)
+[[ $show_bat_use_design_capacity == 1 ]] \
+ && BAT_FULL=$(cat /sys/class/power_supply/$bat/charge_full_design) \
+ || BAT_FULL=$(cat /sys/class/power_supply/$bat/charge_full)
+
+BAT_POWER=$(echo $BAT_NOW $BAT_FULL | awk '{ print int($1 * 100 / $2); }')
+
+OUT="$BAT_POWER%"
+[[ $show_bat_status == 1 ]] && \
+ case $BAT_STATUS in
+ Charging) OUT="$OUT (Charging)"
+ ;;
+ *) # only show charging state for now
+ ;;
+ esac
+
+echo "$OUT"
+
+[[ $show_bat_color_output == 1 ]] && \
+ # print twice, else colors not working?!
+ echo "$OUT"
+ if [[ $BAT_POWER -ge 80 ]]; then
+ # green
+ echo "#00FF00"
+ elif [[ $BAT_POWER -ge 60 ]]; then
+ # yellow
+ echo "#FFF600"
+ elif [[ $BAT_POWER -ge 40 ]]; then
+ # dark orange
+ echo "#FFAE00"
+ else
+ # red
+ echo "#FF0000"
+ fi
+
diff --git a/scripts/eth.sh b/scripts/eth.sh
new file mode 100755
index 0000000..2fb8b30
--- /dev/null
+++ b/scripts/eth.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+# dotfiles -- scripts/eth.sh
+# author: johannst
+
+if="${BLOCK_INSTANCE:-enp0s25}"
+[[ ! -d /sys/class/net/${if} ]] && exit 0
+
+# operstate: down, up
+[[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]] && exit 0
+
+# first ipv4 addr
+IP_ADDR=$(ip address show $if | grep 'inet ' | sed 's/\s\+inet \([0-9.]\+\)\/.*/\1/')
+
+echo "$IP_ADDR"
+
diff --git a/scripts/print_bash_color b/scripts/print_bash_color
new file mode 100755
index 0000000..43f6fcc
--- /dev/null
+++ b/scripts/print_bash_color
@@ -0,0 +1,37 @@
+#!/bin/bash
+# dotfiles -- print_bash_color
+# author: johannst
+
+#{{{ print colors 0-15 fg/bg
+# (colors can be generated with http://ciembor.github.io/4bit)
+
+fg=(' ' '1' '30' '1;30' '31' '1;31' '32' '1;32' '33' '1;33' '34' '1;34' '35' '1;35' '36' '1;36' '37' '1;37')
+bg=(' ' '40' '41' '42' '43' '44' '45' '46' '47')
+
+printf '%10s ' ""
+color_line=" m\e[m TEST \e[m"
+for b in ${bg[@]}; do
+ printf '%6s ' "${b}m"
+ color_line=$color_line" \e[${b}m TEST \e[m"
+done
+printf '\n'
+echo -e $"$color_line"
+for f in ${fg[@]}; do
+ printf '%5s' "${f}m"
+ color_line="\e[${f}m TEST \e[m"
+ for b in ${bg[@]}; do
+ color_line=$color_line" \e[${f};${b}m TEST \e[m"
+ done
+ echo -e "$color_line"
+done
+
+#}}}
+#{{{ print colors 0-255 fg
+
+for i in $(seq 0 255); do
+ color_line="\\e[38;5;${i}"
+ printf "\e[38;5;${i}m%11s " $color_line;
+ if [ $((((i+1)) % 16)) == 0 ]; then printf '\n'; fi
+done
+
+#}}}
diff --git a/scripts/wifi.sh b/scripts/wifi.sh
new file mode 100755
index 0000000..6f8417a
--- /dev/null
+++ b/scripts/wifi.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# dotfiles -- scripts/wifi.sh
+# author: johannst
+
+if="${BLOCK_INSTANCE:-wlp3s0}"
+[[ ! -d /sys/class/net/${if} ]] && exit 0
+
+show_ap_mac=0
+show_ap_quality=0
+show_ap_name=0
+for arg in "$@"; do
+ case $arg in
+ -aq | --ap_quality) show_ap_quality=1
+ ;;
+ -am | --ap_mac) show_ap_mac=1
+ ;;
+ -an | --ap_name) show_ap_name=1
+ ;;
+ *) # ignore unknown
+ ;;
+ esac
+done
+
+AP_NAME=$(iwgetid -r $if)
+AP_MAC=$(iwgetid -a $if | sed 's/.*\(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\{2\}\).*/\1/')
+AP_QUALITY=$(grep $if /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')%
+
+# first ipv4 addr
+IP_ADDR=$(ip address show $if | grep 'inet ' | sed 's/\s\+inet \([0-9.]\+\)\/.*/\1/')
+
+OUT="$IP_ADDR"
+if [[ $show_ap_name == 1 && $show_ap_quality == 1 ]]; then
+ OUT="$OUT ($AP_NAME $AP_QUALITY)"
+elif [[ $show_ap_name == 1 ]]; then
+ OUT="$OUT ($AP_NAME)"
+elif [[ $show_ap_quality == 1 ]]; then
+ OUT="$OUT ($AP_QUALITY)"
+fi
+[[ $show_ap_mac == 1 ]] && OUT="$OUT $AP_MAC"
+
+echo "$OUT"
+