diff options
Diffstat (limited to 'basics/.local')
| -rwxr-xr-x | basics/.local/bin/battery-monitor | 42 | ||||
| -rwxr-xr-x | basics/.local/bin/dmenu_pass | 5 | ||||
| -rwxr-xr-x | basics/.local/bin/locate-config | 4 | ||||
| -rwxr-xr-x | basics/.local/bin/statusbar/cpu | 54 | ||||
| -rwxr-xr-x | basics/.local/bin/statusbar/memory | 4 | ||||
| -rwxr-xr-x | basics/.local/bin/statusbar/swap | 8 | ||||
| -rwxr-xr-x | basics/.local/bin/sync-mirrors | 15 | ||||
| l--------- | basics/.local/share/dotfiles/dotfiles | 1 | ||||
| l--------- | basics/.local/share/dotfiles/edit-config.d/alacritty | 1 | ||||
| l--------- | basics/.local/share/dotfiles/edit-config.d/dunst | 1 | ||||
| l--------- | basics/.local/share/dotfiles/edit-config.d/kitty | 1 | ||||
| l--------- | basics/.local/share/dotfiles/edit-config.d/ranger | 1 | ||||
| l--------- | basics/.local/share/dotfiles/edit-config.d/rofi | 1 |
13 files changed, 112 insertions, 26 deletions
diff --git a/basics/.local/bin/battery-monitor b/basics/.local/bin/battery-monitor index 1dfa7b6..cfcd41c 100755 --- a/basics/.local/bin/battery-monitor +++ b/basics/.local/bin/battery-monitor @@ -12,30 +12,28 @@ cap=$([ "$state" = "Charging" ] && printf "%d-%d\n" "${max}" "${now}" | bc || ec remaining=$( printf "%d/%d\n" "${cap}" "${volt}" | bc -l ) current_rate=$( printf "%d/%d\n" "${rate}" "${volt}" | bc -l ) -echo $( [ "${current_rate}" != "0" ] && echo "not zero" || echo "is zero" ) +#echo $( [ "${current_rate}" != "0" ] && echo "not zero" || echo "is zero" ) seconds=$( [ "${current_rate}" != "0" ] && printf "3600*%f/%f\n" "${remaining}" "${current_rate}" | bc || echo "0") time_remaining=$( date -ud "@${seconds}" "+%H:%M:%S" ) -echo "percentage ${percentage}%" -echo "state ${state}" -echo "rate ${rate}" -echo "volt ${volt}" -echo "now ${now}" -echo "max ${max}" -echo "cap ${cap}" -echo "remaining ${remaining}" -echo "current_rate ${current_rate}" -echo "seconds ${seconds}" -echo "time ${time_remaining}" +#echo "percentage ${percentage}%" +#echo "state ${state}" +#echo "rate ${rate}" +#echo "volt ${volt}" +#echo "now ${now}" +#echo "max ${max}" +#echo "cap ${cap}" +#echo "remaining ${remaining}" +#echo "current_rate ${current_rate}" +#echo "seconds ${seconds}" +#echo "time ${time_remaining}" -exit 0 battery_level=`acpi -b | cut -d ' ' -f 4 | grep -o '[0-9]*'` battery_level=$(head -n1 /sys/class/power_supply/BAT0/capacity) battery_state=$(acpi | grep 'Battery' | sed 's/Battery\s[0-9]*: //' | sed 's/, [0-9][0-9]*\%.*//') battery_state=$(head -n1 /sys/class/power_supply/BAT0/status) battery_remaining=$(acpi | grep -oh '[0-9:]* remaining' | sed 's/:\w\w remaining$/ Minutes/' | sed 's/00://' | sed 's/:/h /') -kk if [ ! -f "/tmp/.battery" ]; then echo "$battery_level" > /tmp/.battery @@ -43,31 +41,31 @@ if [ ! -f "/tmp/.battery" ]; then exit fi -previous_battery_level=$(cat /tmp/.battery | head -n 1) -previous_battery_state=$(cat /tmp/.battery | tail -n 1) +previous_battery_level=$(head -n 1 < /tmp/.battery) +previous_battery_state=$(tail -n 1 < /tmp/.battery) echo "$battery_level" > /tmp/.battery echo "$battery_state" >> /tmp/.battery checkBatteryLevel() { - if [ $battery_state != "Discharging" ] || [ "${battery_level}" == "${previous_battery_level}" ]; then + if [ "$battery_state" != "Discharging" ] || [ "${battery_level}" = "${previous_battery_level}" ]; then exit fi - if [ $battery_level -le 4 ]; then + if [ "$battery_level" -le 4 ]; then sudo systemctl suspend - elif [ $battery_level -le 7 ]; then + elif [ "$battery_level" -le 7 ]; then notify-send "Low Battery" "(${time_remaining}) Your computer will suspend soon unless plugged into a power outlet." -u critical - elif [ $battery_level -le 10 ]; then + elif [ "$battery_level" -le 10 ]; then notify-send "Low Battery" "${battery_level}% (${time_remaining}) of battery remaining." -u normal fi } checkBatteryStateChange() { - if [ "$battery_state" != "Discharging" ] && [ "$previous_battery_state" == "Discharging" ]; then + if [ "$battery_state" != "Discharging" ] && [ "$previous_battery_state" = "Discharging" ]; then notify-send "Charging" "Battery is now plugged in." -u low fi - if [ "$battery_state" == "Discharging" ] && [ "$previous_battery_state" != "Discharging" ]; then + if [ "$battery_state" = "Discharging" ] && [ "$previous_battery_state" != "Discharging" ]; then notify-send "Power Unplugged" "Your computer has been disconnected from power." -u low fi } diff --git a/basics/.local/bin/dmenu_pass b/basics/.local/bin/dmenu_pass new file mode 100755 index 0000000..02250be --- /dev/null +++ b/basics/.local/bin/dmenu_pass @@ -0,0 +1,5 @@ +#!/bin/sh + +prompt=${1:-Password} + +dmenu -P -p "$prompt" <&- diff --git a/basics/.local/bin/locate-config b/basics/.local/bin/locate-config index 26fd2cb..2f8dc3d 100755 --- a/basics/.local/bin/locate-config +++ b/basics/.local/bin/locate-config @@ -2,11 +2,11 @@ set -e -config_dir="$HOME/.local/share/config-files" +config_dir="$HOME/.local/share/dotfiles/edit-config.d" p="Config:" -sel=$(find "$config_dir" -writable -type l | cut -d "/" -f 7- | sort -d | dmenu -p "$p" -l 20) +sel=$(find "$config_dir" -writable -type l | cut -d "/" -f 8- | sort -d | dmenu -p "$p" -l 20) ec=$? [ "$ec" -ne 0 ] && exit $ec diff --git a/basics/.local/bin/statusbar/cpu b/basics/.local/bin/statusbar/cpu new file mode 100755 index 0000000..6a89024 --- /dev/null +++ b/basics/.local/bin/statusbar/cpu @@ -0,0 +1,54 @@ +#!/bin/bash + +# TODO: finish it + +# /proc/stat format: +# cpu[n] user nice system idle iowait irq softirq steal guest guest_nice + +# format user nice system idle steal total +# total = user + nice + system + idle + steal +prevstat=$(awk ' +/^cpu[0-9]+/ {print $2, $3, $4, $5, $9, ($2 + $3 + $4 + $5 + $9)}' /proc/stat) + +sleep 0.5 + + +stat=$(awk ' +/^cpu[0-9]+/ {print $2, $3, $4, $5, $9, ($2 + $3 + $4 + $5 + $9)}' /proc/stat) + + +num_cpu=$(echo "$stat" | wc -l) + +get_load() { + line=${1:-1} + last=$(echo "$stat" | sed "${line}q;d") + prev=$(echo "$prevstat" | sed "${line}q;d") + read -r u n s last_idle st last_total <<< "$last" + #echo "$u $n $s $last_idle $st $last_total" + read -r u n s prev_idle st prev_total <<< "$prev" + #echo "$u $n $s $prev_idle $st $prev_total" + diff=$(echo "$last_total $prev_total" | awk '{printf "%d", $1 - $2}') + [ "$diff" = "0" ] && return + percentage=$(echo "$diff $last_idle $prev_idle" | awk '{printf "%.2f", 100.0 * (($1 - ($2 - $3)) / $1)}') + echo -e "$percentage" +} + +total_load=0 + +for i in $(seq 1 "$num_cpu"); do + load=$(get_load "$i") + total_load=$(echo "$total_load $load" | awk '{printf "%.2f", $1 + $2}') +done + +total_percentage=$(echo "$total_load $num_cpu" | awk '{printf "%.2f", ($1 / $2) + 0.5}') +echo -e "$total_percentage" + +#read -r cpu a b c previdle rest < /proc/stat +#prevtotal=$((a+b+c+previdle)) +#sleep 0.5 +#read -r cpu a b c idle rest < /proc/stat +#total=$((a+b+c+idle)) +#cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) )) +#echo -e "$cpu" + +exit 0 diff --git a/basics/.local/bin/statusbar/memory b/basics/.local/bin/statusbar/memory index 7a952d8..77f462b 100755 --- a/basics/.local/bin/statusbar/memory +++ b/basics/.local/bin/statusbar/memory @@ -13,8 +13,8 @@ print Total ":" Available ":" Free ":" Buffers ":" Cached ":" SReclaimable ":" S echo "$meminfo" | while IFS=: read -r t a f b c sr sh; do - memfree=$(echo "$a $t" | awk '{printf "%.3f", ($1 / $2) * 100}') - memused=$(echo "$memfree" | awk '{printf "%.3f", (100 - $1)}') + memfree=$(echo "$a $t" | awk '{printf "%.2f", ($1 / $2) * 100}') + memused=$(echo "$memfree" | awk '{printf "%.2f", (100 - $1)}') # Percentage values # TODO: other values, controllable by flags? diff --git a/basics/.local/bin/statusbar/swap b/basics/.local/bin/statusbar/swap new file mode 100755 index 0000000..787ed23 --- /dev/null +++ b/basics/.local/bin/statusbar/swap @@ -0,0 +1,8 @@ +#!/bin/sh + +awk ' +/^SwapTotal:/ {Total=$2/(1024 * 1024)} +/^SwapFree:/ {Free=$2/(1024 * 1024)} +/^SwapCached:/ {Cached=$2/(1024 * 1024)} +END { +printf "%.2f %.2f %.2f %.2f\n", Total, Free, Cached, (Total - Free)}' /proc/meminfo diff --git a/basics/.local/bin/sync-mirrors b/basics/.local/bin/sync-mirrors new file mode 100755 index 0000000..dc5fb0c --- /dev/null +++ b/basics/.local/bin/sync-mirrors @@ -0,0 +1,15 @@ +#!/bin/sh + +sudo reflector \ + -c "Australia" \ + -c "New Zealand" \ + -c "Hong Kong" \ + -c "Singapore" \ + -c "Philipines" \ + -c "Malaysia" \ + -c "Indonesia" \ + -c "Thailand" \ + -c "Vietnam" \ + -c "China" \ + --age 12 --fastest 30 --latest 30 --verbose --save /etc/pacman.d/mirrorlist + diff --git a/basics/.local/share/dotfiles/dotfiles b/basics/.local/share/dotfiles/dotfiles new file mode 120000 index 0000000..11a54ed --- /dev/null +++ b/basics/.local/share/dotfiles/dotfiles @@ -0,0 +1 @@ +../../../../
\ No newline at end of file diff --git a/basics/.local/share/dotfiles/edit-config.d/alacritty b/basics/.local/share/dotfiles/edit-config.d/alacritty new file mode 120000 index 0000000..959d41c --- /dev/null +++ b/basics/.local/share/dotfiles/edit-config.d/alacritty @@ -0,0 +1 @@ +../../../../.config/alacritty/alacritty.yml
\ No newline at end of file diff --git a/basics/.local/share/dotfiles/edit-config.d/dunst b/basics/.local/share/dotfiles/edit-config.d/dunst new file mode 120000 index 0000000..91aecb1 --- /dev/null +++ b/basics/.local/share/dotfiles/edit-config.d/dunst @@ -0,0 +1 @@ +../../../../.config/dunst/dunstrc
\ No newline at end of file diff --git a/basics/.local/share/dotfiles/edit-config.d/kitty b/basics/.local/share/dotfiles/edit-config.d/kitty new file mode 120000 index 0000000..c860ad6 --- /dev/null +++ b/basics/.local/share/dotfiles/edit-config.d/kitty @@ -0,0 +1 @@ +../../../../.config/kitty/kitty.conf
\ No newline at end of file diff --git a/basics/.local/share/dotfiles/edit-config.d/ranger b/basics/.local/share/dotfiles/edit-config.d/ranger new file mode 120000 index 0000000..61a6f81 --- /dev/null +++ b/basics/.local/share/dotfiles/edit-config.d/ranger @@ -0,0 +1 @@ +../../../../.config/ranger/rc.conf
\ No newline at end of file diff --git a/basics/.local/share/dotfiles/edit-config.d/rofi b/basics/.local/share/dotfiles/edit-config.d/rofi new file mode 120000 index 0000000..3e3a50f --- /dev/null +++ b/basics/.local/share/dotfiles/edit-config.d/rofi @@ -0,0 +1 @@ +../../../../.config/rofi/config
\ No newline at end of file |
