From ee361f87765bee2d8f0910e27e01217a2f800add Mon Sep 17 00:00:00 2001 From: ene Date: Sun, 12 Mar 2023 16:05:37 +0100 Subject: Fix(hm/conf/yambar): Update to new shell lib version --- home-manager/config/yambar/default.nix | 6 +-- home-manager/config/yambar/scripts/disk | 24 ++++++++++ home-manager/config/yambar/scripts/disk.sh | 26 ----------- home-manager/config/yambar/scripts/grades-average | 17 +++++++ .../config/yambar/scripts/grades-average.sh | 15 ------ home-manager/config/yambar/scripts/network | 49 ++++++++++++++++++++ home-manager/config/yambar/scripts/network.sh | 53 ---------------------- home-manager/config/yambar/scripts/sound-volume | 22 +++++++++ home-manager/config/yambar/scripts/sound-volume.sh | 22 --------- 9 files changed, 115 insertions(+), 119 deletions(-) create mode 100755 home-manager/config/yambar/scripts/disk delete mode 100644 home-manager/config/yambar/scripts/disk.sh create mode 100755 home-manager/config/yambar/scripts/grades-average delete mode 100644 home-manager/config/yambar/scripts/grades-average.sh create mode 100755 home-manager/config/yambar/scripts/network delete mode 100644 home-manager/config/yambar/scripts/network.sh create mode 100755 home-manager/config/yambar/scripts/sound-volume delete mode 100644 home-manager/config/yambar/scripts/sound-volume.sh (limited to 'home-manager/config/yambar') diff --git a/home-manager/config/yambar/default.nix b/home-manager/config/yambar/default.nix index 4600dcfb..db77600e 100644 --- a/home-manager/config/yambar/default.nix +++ b/home-manager/config/yambar/default.nix @@ -25,20 +25,20 @@ in { volume_script = makeScript { dependencies = builtins.attrValues {inherit (pkgs) pulseaudio gawk;}; - file = ./scripts/sound-volume.sh; + file = ./scripts/sound-volume; }; grade_average_script = makeScript { dependencies = [ grades.outputs.packages.${system}.default ]; - file = ./scripts/grades-average.sh; + file = ./scripts/grades-average; }; cpu_script = yambar_cpu.app.${system}.default.program; memory_script = yambar_memory.app.${system}.default.program; disk_script = makeScript { dependencies = builtins.attrValues {inherit (pkgs) gawk btrfs-progs coreutils;}; - file = ./scripts/disk.sh; + file = ./scripts/disk; }; }; } diff --git a/home-manager/config/yambar/scripts/disk b/home-manager/config/yambar/scripts/disk new file mode 100755 index 00000000..dad41feb --- /dev/null +++ b/home-manager/config/yambar/scripts/disk @@ -0,0 +1,24 @@ +#! /usr/bin/env dash +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +# . ~/.local/lib/shell/lib +. %SHELL_LIBRARY_PATH + +# Main loop +while true; do + # vars + used_space=$(btrfs filesystem usage /srv 2> /dev/null | awk '{if ( /Used:/ ) { print $2 } } ' | head -n1) + all_space=$(btrfs filesystem usage /srv 2> /dev/null | awk '{if ( /Device size:/ ) { print $3 } } ' | head -n1 | tr -d "GiB") + + + # Check space available (4) and percentage used (5) + spaceperc=$(echo "$(echo "$used_space" | tr -d "GiB" )" "$all_space" | awk '{div=$1/$2;div *= 100; printf"%2d%%\n",div }') + + echo "diskspace|string|$used_space" + echo "diskperc|string|$spaceperc" + echo "" + sleep 1 +done + +if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi +# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/disk.sh b/home-manager/config/yambar/scripts/disk.sh deleted file mode 100644 index a6e35241..00000000 --- a/home-manager/config/yambar/scripts/disk.sh +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/env dash -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -# . ~/.local/lib/shell/lib -. %SHELL_LIBRARY_PATH - - -# Main loop -while true; do - # vars - used_space=$(btrfs filesystem usage /srv 2> /dev/null | awk '{if ( /Used:/ ) { print $2 } } ' | head -n1) - all_space=$(btrfs filesystem usage /srv 2> /dev/null | awk '{if ( /Device size:/ ) { print $3 } } ' | head -n1 | tr -d "GiB") - - - # Check space available (4) and percentage used (5) - spaceperc=$(echo "$(echo "$used_space" | tr -d "GiB" )" "$all_space" | awk '{div=$1/$2;div *= 100; printf"%2d%%\n",div }') - - echo "diskspace|string|$used_space" - echo "diskperc|string|$spaceperc" - echo "" - sleep 1 -done - - - -# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/grades-average b/home-manager/config/yambar/scripts/grades-average new file mode 100755 index 00000000..98e06858 --- /dev/null +++ b/home-manager/config/yambar/scripts/grades-average @@ -0,0 +1,17 @@ +#! /usr/bin/env dash +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +# . ~/.local/lib/shell/lib +. %SHELL_LIBRARY_PATH + +while true; do + grade=$(grades list average | awk '{print $2}'); + + echo "grade|string|$grade"; + echo ""; + + sleep 1; +done + +if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi +# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/grades-average.sh b/home-manager/config/yambar/scripts/grades-average.sh deleted file mode 100644 index 72e180bd..00000000 --- a/home-manager/config/yambar/scripts/grades-average.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env dash -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -. %SHELL_LIBRARY_PATH - - -while true; do - grade=$(grades list average | awk '{print $2}'); - - echo "grade|string|$grade"; - echo ""; - - sleep 1; -done -# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/network b/home-manager/config/yambar/scripts/network new file mode 100755 index 00000000..45c164df --- /dev/null +++ b/home-manager/config/yambar/scripts/network @@ -0,0 +1,49 @@ +#! /usr/bin/env dash +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +# . ~/.local/lib/shell/lib +. %SHELL_LIBRARY_PATH + +retest=120 +retest_if_con_fails=10 +backend=nmcli + +case "$backend" in + "nmcli") # Test for connectivity with nmcli + while true; do + connection_status=$(nmcli networking connectivity) + if [ "$connection_status" = "full" ]; then + echo "internet|string|Connected" + echo "" + sleep $retest + else + echo "internet|string|Disconnected" + echo "" + sleep $retest_if_con_fails + fi + done + ;; + "ping") # Test for connectivity with ping + ip_address='8.8.8.8' + ping_number=3 + + while true; do + + ping_result=$(mktmp) + ping $ip_address -c $ping_number -q | awk 'BEGIN {FS="/"} END {print $5}' > $ping_result + + if [ "$(cat $ping_result | wc -l)" -eq 0 ]; then + echo "med|string|No connection" + echo "" + sleep $retest_if_con_fails + else + echo "med|string|$(cat $ping_result) ms" + echo "" + sleep $retest + fi + done + ;; +esac + +if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi +# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/network.sh b/home-manager/config/yambar/scripts/network.sh deleted file mode 100644 index 9d797e15..00000000 --- a/home-manager/config/yambar/scripts/network.sh +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env dash -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -#. ~/.local/lib/shell/lib -. %SHELL_LIBRARY_PATH - -LIB_TEMP_DIR_FOR_SCRIPT=$(mktemp -d) - -retest=120 -retest_if_con_fails=10 -backend=nmcli - -case "$backend" in - "nmcli") # Test for connectivity with nmcli - while true; do - connection_status=$(nmcli networking connectivity) - if [ "$connection_status" = "full" ]; then - echo "internet|string|Connected" - echo "" - sleep $retest - else - echo "internet|string|Disconnected" - echo "" - sleep $retest_if_con_fails - fi - done - ;; - "ping") # Test for connectivity with ping - ip_address='8.8.8.8' - ping_number=3 - - while true; do - - ping_result=$(mktmp) - ping $ip_address -c $ping_number -q | awk 'BEGIN {FS="/"} END {print $5}' > $ping_result - - if [ "$(cat $ping_result | wc -l)" -eq 0 ]; then - echo "med|string|No connection" - echo "" - sleep $retest_if_con_fails - else - echo "med|string|$(cat $ping_result) ms" - echo "" - sleep $retest - fi - done - ;; -esac - - - -if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi -# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/sound-volume b/home-manager/config/yambar/scripts/sound-volume new file mode 100755 index 00000000..8a9cf0d2 --- /dev/null +++ b/home-manager/config/yambar/scripts/sound-volume @@ -0,0 +1,22 @@ +#! /usr/bin/env dash +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +# . ~/.local/lib/shell/lib +. %SHELL_LIBRARY_PATH + +while true; do + volume=$(pactl get-sink-volume 0 | awk 'BEGIN { FS="/" } {gsub("%","",$2); gsub(" ","",$2)} {printf $2}') + + if [ "$volume" -eq 0 ]; then + echo "muted|bool|true" + else + echo "volume|string|$volume" + echo "muted|bool|false" + fi + echo "" + + sleep 1; +done + +if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi +# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/sound-volume.sh b/home-manager/config/yambar/scripts/sound-volume.sh deleted file mode 100644 index 8fc0107f..00000000 --- a/home-manager/config/yambar/scripts/sound-volume.sh +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env dash -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -# . ~/.local/lib/shell/lib -. %SHELL_LIBRARY_PATH - -while true; do - volume=$(pactl get-sink-volume 0 | awk 'BEGIN { FS="/" } {gsub("%","",$2); gsub(" ","",$2)} {printf $2}') - - if [ "$volume" -eq 0 ]; then - echo "muted|bool|true" - else - echo "volume|string|$volume" - echo "muted|bool|false" - fi - echo "" - - sleep 1; -done - - -# vim: ft=sh -- cgit 1.4.1