From 5f49d4a716d4e2a8b842d819c06662cf2198179a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Sat, 19 Apr 2014 04:26:15 +0200 Subject: [PATCH] Add scripts that create the output for status bar clicks. --- i3/i3/scripts/status.d/battery.bash | 94 ++++++++++++++++++++++++ i3/i3/scripts/status.d/conky_pacman.bash | 8 ++ i3/i3/scripts/status.d/pacman.bash | 6 ++ i3/i3/scripts/status.d/sysinfo.bash | 35 +++++++++ i3/i3/scripts/status.d/wireless.bash | 55 ++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 i3/i3/scripts/status.d/battery.bash create mode 100644 i3/i3/scripts/status.d/conky_pacman.bash create mode 100644 i3/i3/scripts/status.d/pacman.bash create mode 100644 i3/i3/scripts/status.d/sysinfo.bash create mode 100644 i3/i3/scripts/status.d/wireless.bash diff --git a/i3/i3/scripts/status.d/battery.bash b/i3/i3/scripts/status.d/battery.bash new file mode 100644 index 0000000..f178873 --- /dev/null +++ b/i3/i3/scripts/status.d/battery.bash @@ -0,0 +1,94 @@ +#!/bin/bash + +# shitty. this is used for both creating a part of the status conkyrc AND for +# creating nice output if you click on the status bar +# what i done depends on the first paramter + +PATH_WARN_1="$HOME/.i3/logs/batwarn1" +PATH_WARN_2="$HOME/.i3/logs/batwarn2" + +THRESHOLD1=25 +THRESHOLD2=5 + +acpi_output=$(acpi -b) +percent="$(echo "$acpi_output" | cut -d "," -f 2 | cut -d " " -f 2 | cut -d "%" -f 1)" +if [[ $percent == 100 ]] ; then + status="Full" +else + status="$(echo "$acpi_output" | cut -d "," -f 1 | cut -d " " -f 3)" +fi +time="$(echo "$acpi_output" | cut -d "," -f 3 | cut -d " " -f 2)" +shortstatus="$(echo $status | cut -c 1)" + +pretty() { + ( + echo "Status:|$status" + echo "Charge:|${percent}%" + if [[ $percent != 100 ]] ; then + echo "Time left:|$time" + fi + ) | column -t --separator="|" +} + +charging() { + [[ "$shortstatus" == "C" ]] +} + +discharging() { + [[ "$shortstatus" == "D" ]] +} + +threshold1() { + [[ $percent -le $THRESHOLD1 ]] +} + +threshold2() { + [[ $percent -le $THRESHOLD2 ]] +} + +conky() { + if discharging ; then + if threshold2 ; then + if [[ ! -f "$PATH_WARN_2" ]] ; then + echo > "$PATH_WARN_2" + notify-send --icon dialog-warning "Battery below 5%" + fi + elif threshold1 ; then + if [[ ! -f "$PATH_WARN_1" ]] ; then + echo > "$PATH_WARN_1" + notify-send --icon dialog-warning "Battery below 25%" + fi + fi + fi + + if charging ; then + [[ -f "$PATH_WARN_1" ]] && rm "$PATH_WARN_1" + [[ -f "$PATH_WARN_2" ]] && rm "$PATH_WARN_2" + #if [[ $percent -gt 25 ]] ; then + # [[ -f "$PATH_WARN_1" ]] && rm "$PATH_WARN_1" + #elif [[ $percent -gt 5 ]] ; then + # [[ -f "$PATH_WARN_2" ]] && rm "$PATH_WARN_2" + #fi + + fi + + if threshold2 ; then + color="#FF0000" # red + elif threshold1 ; then + color="#FFFF00" # yellow + else + color="#FFFFFF" # white + fi + + + + echo "{ \"full_text\" : \"  "${shortstatus} ${percent}% \" , \"color\" : \"$color\" , \"name\" : \"battery\" }, +} + +if [[ "$1" == "conky" ]] ; then + conky +else + pretty +fi + + diff --git a/i3/i3/scripts/status.d/conky_pacman.bash b/i3/i3/scripts/status.d/conky_pacman.bash new file mode 100644 index 0000000..2766079 --- /dev/null +++ b/i3/i3/scripts/status.d/conky_pacman.bash @@ -0,0 +1,8 @@ +#!/bin/bash + +updates=$(pacman -Quq | wc -l) +if [[ $updates == 0 ]] ; then + echo "no updates" +else + echo "$updates updates" +fi diff --git a/i3/i3/scripts/status.d/pacman.bash b/i3/i3/scripts/status.d/pacman.bash new file mode 100644 index 0000000..54ba9f4 --- /dev/null +++ b/i3/i3/scripts/status.d/pacman.bash @@ -0,0 +1,6 @@ +#!/bin/bash + +echo "Total packages: $(pacman -Qq | wc -l)" +echo "" +echo "Updates available:" +echo "$(pacman -Qu | column -t)" diff --git a/i3/i3/scripts/status.d/sysinfo.bash b/i3/i3/scripts/status.d/sysinfo.bash new file mode 100644 index 0000000..7f70664 --- /dev/null +++ b/i3/i3/scripts/status.d/sysinfo.bash @@ -0,0 +1,35 @@ +columnate() { + column -t --separator="|" +} + +freeoutput="$(free -m)" +memtotal=$(echo "$freeoutput" | head -2 | tail -1 | tr -s " " | cut -d " " -f 2) +memused=$(echo "$freeoutput" | head -3 | tail -1 | tr -s " " | cut -d " " -f 3) + + +(echo "Current user:|$(whoami)" +echo "Hostname:|$(hostname)" +echo "Uptime:|$(uptime --pretty | cut -d " " -f 2-)" +echo "Kernel:|$(uname -r)" +echo "Packages:|$(pacman -Qq | wc -l)") | columnate +echo "" +echo "CPU:" +(echo "Name:|$(lscpu | grep "Model name:" | tr -s " " | cut -d " " -f 3-)" +echo "Architecture:|$(uname -m)" +echo "Temp:|$(sensors -u | grep "temp1_input" | cut -d ":" -f 2 | cut -d "." -f 1 | cut -c 2-)°C" +echo "Load:|$(uptime | tr -s " " | cut -d " " -f 10 | tr -d ",")") | columnate +echo "" +echo "MEM:" +echo "${memused}MB / ${memtotal}MB ($(( $memused * 100 / $memtotal ))% used)" +echo "" +echo "PROCS:" +(echo "x x cpu% mem% x x x x x x command" ; ps aux | sort -nrk 3 | tr -s " " | cut -d " " -f -11 | uniq -uf 10 | head -10) | cut -d " " -f 3,4,11 | column -t +echo "" +echo "STORAGE:" +df -hT --type=btrfs --type=ext4 --total +echo "" +echo "SWAP:" +if [[ -z "$(swapon)" ]] ; then + echo "none" +fi + diff --git a/i3/i3/scripts/status.d/wireless.bash b/i3/i3/scripts/status.d/wireless.bash new file mode 100644 index 0000000..d12bd27 --- /dev/null +++ b/i3/i3/scripts/status.d/wireless.bash @@ -0,0 +1,55 @@ +#!/bin/bash +INTERFACE="wlp2s0" +TIMEFORMAT="+%F %R" + +iwconfig_output="$(iwconfig $INTERFACE)" + +columnize() { + column -t --separator="|" +} + +essid=$(echo "$iwconfig_output" | sed -n "1p" | awk -F '"' '{print $2}') +mode=$(echo "$iwconfig_output" | sed -n "1p" | awk -F " " '{print $3}') +freq=$(echo "$iwconfig_output" | sed -n "2p" | awk -F " " '{print $2}' | cut -d":" -f2) +mac=$(echo "$iwconfig_output" | sed -n "2p" | awk -F " " '{print $6}') +qual=$(echo "$iwconfig_output" | sed -n "6p" | awk -F " " '{print $2}' | cut -d"=" -f2) +lvl=$(echo "$iwconfig_output" | sed -n "6p" | awk -F " " '{print $4}' | cut -d"=" -f2) +rate=$(echo "$iwconfig_output" | sed -n "3p" | awk -F "=" '{print $2}' | cut -d" " -f1) + +ip=$(ip addr show $INTERFACE | grep "[[:space:]]*inet" | head -n 1 | tr -s " " | cut -d " " -f 3 | cut -d "/" -f 1) + +vnstat_output="$(vnstat --dumpdb)" +txhour=$(echo "$vnstat_output" | grep "^h;0;" | cut -d ";" -f 5) +rxhour=$(echo "$vnstat_output" | grep "^h;0;" | cut -d ";" -f 4) +txtoday=$(echo "$vnstat_output" | grep "^d;0;" | cut -d ";" -f 5) +rxtoday=$(echo "$vnstat_output" | grep "^d;0;" | cut -d ";" -f 4) +txtotal=$(echo "$vnstat_output" | grep "^totaltx;" | cut -d ";" -f 2) +rxtotal=$(echo "$vnstat_output" | grep "^totalrx;" | cut -d ";" -f 2) +vnstat_created="$(date --date=@$(echo "$vnstat_output" | grep "^created;" | cut -d ";" -f 2) "$TIMEFORMAT")" +vnstat_last_update="$(date --date=@$(echo "$vnstat_output" | grep "^updated;" | cut -d ";" -f 2) "$TIMEFORMAT")" + +echo "Interface $INTERFACE:" +( +echo "IP:|$ip" +echo "ESSID:|$essid" +echo "Mode:|$mode" +echo "Frequency:|$freq" +echo "MAC address:|$mac" +echo "Quality:|$qual" +echo "Signal level:|$lvl dBm" +echo "Bitrate:|$rate Mb/s" +) | columnize +echo "" +echo "Usage:" +( +echo "Hourly up:|${txhour} KiB" +echo "Hourly down:|${rxhour} KiB" +echo "Daily up:|${txtoday} MiB" +echo "Daily down:|${rxtoday} MiB" +echo "Total up:|${txtotal} MiB" +echo "Total down:|${rxtotal} MiB" +echo "" +echo "Database created at:|$vnstat_created" +echo "Last update at:|$vnstat_last_update" +) | columnize +