diff options
| author | Syndamia <kamen@syndamia.com> | 2022-07-19 11:33:00 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2022-07-19 11:33:00 +0300 |
| commit | fdcd93a83cc66b2b475b76beb5f87e50e0483e9f (patch) | |
| tree | 7af56bc5ca1006b32802e7ca8d15b28ca74cc347 /scripts | |
| parent | b526d5c377ffe3ee38949ee6728377981578d190 (diff) | |
| download | dotfiles-fdcd93a83cc66b2b475b76beb5f87e50e0483e9f.tar dotfiles-fdcd93a83cc66b2b475b76beb5f87e50e0483e9f.tar.gz dotfiles-fdcd93a83cc66b2b475b76beb5f87e50e0483e9f.zip | |
Moved scripts to their own folder and renamed .cfgs folder to .confs
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/app-mem.sh | 29 | ||||
| -rwxr-xr-x | scripts/battery-status.sh | 57 | ||||
| -rwxr-xr-x | scripts/dunst-toggler-applet.sh | 26 | ||||
| -rwxr-xr-x | scripts/terminal.sh | 5 | ||||
| -rwxr-xr-x | scripts/toggle-desktop.sh | 7 | ||||
| -rwxr-xr-x | scripts/toggle-repo.sh | 7 |
6 files changed, 131 insertions, 0 deletions
diff --git a/scripts/app-mem.sh b/scripts/app-mem.sh new file mode 100755 index 0000000..35384c9 --- /dev/null +++ b/scripts/app-mem.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Huge thanks to https://askubuntu.com/a/549534/1085672 and https://www.zyxware.com/articles/4446/show-total-memory-usage-by-each-application-in-your-ubuntu-or-any-gnu-linux-system + +ps -A --sort -rss -o comm,pmem,rss | awk ' + NR == 1 { print; next } + { a[$1] += $2; b[$1] += $3; } + END { + for (i in a) { + size_in_bytes = b[i] * 1024 + split("B KB MB GB TB PB", unit) + human_readable = 0 + if (size_in_bytes == 0) { + human_readable = 0 + j = 0 + } + else { + for (j = 5; human_readable < 1; j--) + human_readable = size_in_bytes / (2^(10*j)) + } + printf "%-20s\t%s\t%.2f%s\t%s\n", i, a[i], human_readable, unit[j+2], b[i] + } + } +' | awk 'NR>1' | sort -rnk4 | awk ' + BEGIN {printf "%-20s\t%%MEM\tSIZE\n", "COMMAND"} + { + printf "%-20s\t%s\t%s\n", $1, $2, $3 + } +' | head -n 10 diff --git a/scripts/battery-status.sh b/scripts/battery-status.sh new file mode 100755 index 0000000..efbc2a2 --- /dev/null +++ b/scripts/battery-status.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +if [[ "$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep native-path | awk '{print $2}')" == '(null)' ]]; then + exit +fi + +battery_notify () { + # if battery percentage is equal to given one, if battery percentage inside /tmp/battery.tmp is not equal to given one and if power indicator is the given on + if [ ${__bat_per} -eq $1 ] && ! grep -q $1 "/tmp/battery.tmp" && [[ ${__bat_power} = $2 ]]; then + # Send notification and rewrite battery.tmp file with current percentage + notify-send -u critical -i battery-low -t 99999999 "$3" + echo $1 > /tmp/battery.tmp + fi +} + +# If upower command is available +if command -v upower > /dev/null 2>&1 ; then + + # Get battery power indicator (charging/discharging/fully charged) and stop script if there is no value for it (if there is no battery in device) + __bat_power=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}') + if [[ -n ${__bat_per} ]]; then + exit + fi + + # Set the battery power indicator icon + __bat_power_ind="" + if [[ ${__bat_power} = "charging" ]]; then __bat_power_ind="" + elif [[ ${__bat_power} = "discharging" ]]; then __bat_power_ind="" + elif [[ ${__bat_power} = "fully-charged" ]]; then __bat_power_ind="" + fi + + # Get the battery percentage, time until the battery is empty and time until the battery is full + __bat_per=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | awk '{print $2}' | sed "s|%||g") + __time_empt=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to empty" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]') + __time_full=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to full" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]') + + # Print the battery power indicator icon, percentage and time until empty or time until full + echo -n " ${__bat_power_ind} ${__bat_per}%" + if [[ ${__bat_power} = "discharging" ]]; then + echo " ${__time_empt}" + else + echo " ${__time_full}" + fi + + # Create the temporary battery file, if it doesn't exist + if [ ! -f "/tmp/battery.tmp" ]; then + touch /tmp/battery.tmp + fi + + # Setup for battery notifications + battery_notify 100 'fully-charged' 'Battery 100%' + battery_notify 80 'charging' 'Battery 80%' + battery_notify 20 'discharging' 'Battery 20%' + battery_notify 15 'discharging' 'Battery 15%' + battery_notify 10 'discharging' 'Battery 10%' + battery_notify 5 'discharging' 'Battery 5%' +fi diff --git a/scripts/dunst-toggler-applet.sh b/scripts/dunst-toggler-applet.sh new file mode 100755 index 0000000..e9f253e --- /dev/null +++ b/scripts/dunst-toggler-applet.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +function update { + while :; do + curr_status=$(dunstctl is-paused) + + if [[ "$curr_status" != "$prev_status" ]]; then + prev_status=$curr_status + + if [[ "$curr_status" == "true" ]]; then + echo icon:/usr/share/icons/tabler-icon-bell-off.png + echo tooltip:Notifications OFF + else + echo icon:/usr/share/icons/tabler-icon-bell.png + echo tooltip:Notifications ON + fi + fi + + sleep 0.2 + done +} + +update | \ +yad --notification \ + --listen \ + --command="dunstctl set-paused toggle" diff --git a/scripts/terminal.sh b/scripts/terminal.sh new file mode 100755 index 0000000..2fb7853 --- /dev/null +++ b/scripts/terminal.sh @@ -0,0 +1,5 @@ +#!/bin/bash +terminator --new-tab --working-directory="$(pwd)" + +# To set it as default on cinnamon: +# gsettings set org.cinnamon.desktop.default-applications.terminal exec /home/kamen/Commonwealth/terminal.sh diff --git a/scripts/toggle-desktop.sh b/scripts/toggle-desktop.sh new file mode 100755 index 0000000..b5906bc --- /dev/null +++ b/scripts/toggle-desktop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if xprop -root _NET_SHOWING_DESKTOP | egrep '= 1' > /dev/null; then + wmctrl -k off +else + wmctrl -k on +fi diff --git a/scripts/toggle-repo.sh b/scripts/toggle-repo.sh new file mode 100755 index 0000000..ffbcb57 --- /dev/null +++ b/scripts/toggle-repo.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [[ -d ".git" ]]; then + sudo mv .git .git.disabled +else + sudo mv .git.disabled .git +fi |
