From 6e77d5a081004fb9fe0d47950bd031119c29e9c2 Mon Sep 17 00:00:00 2001 From: ene Date: Sat, 4 Mar 2023 15:00:11 +0100 Subject: Feat(hm/config/yambar): Update the scripts and better paths --- flake.nix | 22 +++- home-manager/config/yambar/config/config.yml | 14 ++- home-manager/config/yambar/default.nix | 39 ++++++- home-manager/config/yambar/scripts/amixer-monitor | 24 ---- home-manager/config/yambar/scripts/cpu | 126 --------------------- home-manager/config/yambar/scripts/dfspace | 23 ---- home-manager/config/yambar/scripts/disk.sh | 26 +++++ home-manager/config/yambar/scripts/grades-average | 12 -- .../config/yambar/scripts/grades-average.sh | 15 +++ home-manager/config/yambar/scripts/meminfo | 37 ------ home-manager/config/yambar/scripts/network.sh | 53 +++++++++ home-manager/config/yambar/scripts/nmclitest | 23 ---- .../config/yambar/scripts/old/amixer-monitor | 24 ++++ home-manager/config/yambar/scripts/old/cpu | 126 +++++++++++++++++++++ home-manager/config/yambar/scripts/old/dfspace | 23 ++++ .../config/yambar/scripts/old/grades-average | 12 ++ home-manager/config/yambar/scripts/old/meminfo | 37 ++++++ home-manager/config/yambar/scripts/old/nmclitest | 23 ++++ home-manager/config/yambar/scripts/old/pingtest | 28 +++++ home-manager/config/yambar/scripts/old/yambar-tray | 27 +++++ .../config/yambar/scripts/old/yambar-tray-width | 28 +++++ home-manager/config/yambar/scripts/pingtest | 28 ----- home-manager/config/yambar/scripts/sound-volume.sh | 22 ++++ home-manager/config/yambar/scripts/yambar-tray | 27 ----- .../config/yambar/scripts/yambar-tray-width | 28 ----- 25 files changed, 510 insertions(+), 337 deletions(-) delete mode 100755 home-manager/config/yambar/scripts/amixer-monitor delete mode 100755 home-manager/config/yambar/scripts/cpu delete mode 100755 home-manager/config/yambar/scripts/dfspace create mode 100644 home-manager/config/yambar/scripts/disk.sh delete mode 100755 home-manager/config/yambar/scripts/grades-average create mode 100644 home-manager/config/yambar/scripts/grades-average.sh delete mode 100755 home-manager/config/yambar/scripts/meminfo create mode 100644 home-manager/config/yambar/scripts/network.sh delete mode 100755 home-manager/config/yambar/scripts/nmclitest create mode 100755 home-manager/config/yambar/scripts/old/amixer-monitor create mode 100755 home-manager/config/yambar/scripts/old/cpu create mode 100755 home-manager/config/yambar/scripts/old/dfspace create mode 100755 home-manager/config/yambar/scripts/old/grades-average create mode 100755 home-manager/config/yambar/scripts/old/meminfo create mode 100755 home-manager/config/yambar/scripts/old/nmclitest create mode 100755 home-manager/config/yambar/scripts/old/pingtest create mode 100755 home-manager/config/yambar/scripts/old/yambar-tray create mode 100755 home-manager/config/yambar/scripts/old/yambar-tray-width delete mode 100755 home-manager/config/yambar/scripts/pingtest create mode 100644 home-manager/config/yambar/scripts/sound-volume.sh delete mode 100755 home-manager/config/yambar/scripts/yambar-tray delete mode 100755 home-manager/config/yambar/scripts/yambar-tray-width diff --git a/flake.nix b/flake.nix index 81e185eb..e3a1ec5e 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,14 @@ url = "git+https://git.sils.li/ene/river-lesser-init.git"; inputs.nixpkgs.follows = "nixpkgs"; }; + yambar_cpu = { + url = "git+https://git.sils.li/ene/yambar_cpu.git"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + yambar_memory = { + url = "git+https://git.sils.li/ene/yambar_memory.git"; + inputs.nixpkgs.follows = "nixpkgs"; + }; user_js = { url = "github:arkenfox/user.js"; @@ -61,6 +69,8 @@ strip_js_comments, shell-library, river_init_lesser, + yambar_memory, + yambar_cpu, ... } @ inputs: let sysLib = import ./lib {inherit pkgs shell-library;}; @@ -76,7 +86,17 @@ }; }; in { - nixosConfigurations = import ./flake/nixosConfigurations {inherit inputs system pkgs sysLib river_init_lesser;}; + nixosConfigurations = import ./flake/nixosConfigurations { + inherit + inputs + system + pkgs + sysLib + river_init_lesser + yambar_memory + yambar_cpu + ; + }; packages."${system}" = { install = import ./bootstrap/install { inherit pkgs; diff --git a/home-manager/config/yambar/config/config.yml b/home-manager/config/yambar/config/config.yml index f9b044c0..adf38f3d 100644 --- a/home-manager/config/yambar/config/config.yml +++ b/home-manager/config/yambar/config/config.yml @@ -147,7 +147,7 @@ bar: carrier: {empty: {}} - script: # Sound volume - path: /home/dt/.config/yambar/scripts/amixer-monitor + path: @volume_script@ content: map: on-click: /bin/sh -c "pavucontrol" @@ -158,25 +158,29 @@ bar: deco: *bgcurg ~muted: string: {text: "  {volume}% ", deco: *combutil} + - script: # Grade average - path: /home/dt/.config/yambar/scripts/grades-average + path: @grade_average_script@ poll-interval: 10 content: string: text: "  {grade} " deco: *combmem + #- backlight: # name: intel_backlight # content: # - string: {text: "  {percent}% ", deco: *combutil} + - script: # CPU - path: /home/dt/.config/yambar/scripts/cpu + path: @cpu_script@ content: string: text: "  {cpu}% " deco: *combmem + - script: # Memory info - path: /home/dt/.config/yambar/scripts/meminfo + path: @memory_script@ content: map: conditions: @@ -189,7 +193,7 @@ bar: text: "  {memperc}% " deco: *combmem - script: # Disk space - path: /home/dt/.config/yambar/scripts/dfspace + path: @disk_script@ content: string: text: "  {diskspace}({diskperc})" diff --git a/home-manager/config/yambar/default.nix b/home-manager/config/yambar/default.nix index e288d8ef..75f2afdc 100644 --- a/home-manager/config/yambar/default.nix +++ b/home-manager/config/yambar/default.nix @@ -1,10 +1,43 @@ { config, + sysLib, pkgs, + grades, + yambar_cpu, + yambar_memory, ... -}: { - xdg.configFile."yambar/config.yml".source = ./config/config.yml; - xdg.configFile."yambar/scripts".source = ./scripts; +}: let + makeScript = { + file, + dependencies, + ... + }: + sysLib.makeShellScriptWithLibrary { + name = "${builtins.baseNameOf file}"; + script = file; + dependencies = dependencies ++ (builtins.attrValues {inherit (pkgs) dash;}); + } + + "/bin/${builtins.baseNameOf file}"; +in { + xdg.configFile."yambar/config.yml".source = builtins.substitueAll { + src = ./config/config.yml; + + volume_script = makeScript { + dependencies = builtins.attrValues {inherit (pkgs) pactl gawk;}; + file = ./scripts/sound-volume.sh; + }; + grade_average_script = makeScript { + dependencies = [grades]; + file = ./scripts/grades-average.sh; + }; + cpu_script = yambar_cpu; + memory_script = yambar_memory; + + disk_script = makeScript { + dependencies = builtins.attrValues {inherit (pkgs) gawk btrfs-progs coreutils;}; + file = ./scripts/disk.sh; + }; + }; } # vim: ts=2 diff --git a/home-manager/config/yambar/scripts/amixer-monitor b/home-manager/config/yambar/scripts/amixer-monitor deleted file mode 100755 index 9e75acfa..00000000 --- a/home-manager/config/yambar/scripts/amixer-monitor +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# An improved amixer script that actually detects volume beyond 100% - - -SLEEPTIME=1 - - -while true; do - - volume=$(pactl get-sink-volume 0 | awk 'BEGIN { FS="/"} {print $2 }' | tr -d "%" | tr -d ' ') - - if [ "$volume" -eq 0 ]; then - echo "muted|bool|true" - - else - # Read sink volume in percentages - echo "volume|string|$volume" - echo "muted|bool|false" - fi - - echo "" - sleep "$SLEEPTIME" - -done diff --git a/home-manager/config/yambar/scripts/cpu b/home-manager/config/yambar/scripts/cpu deleted file mode 100755 index bae820d0..00000000 --- a/home-manager/config/yambar/scripts/cpu +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/bash -# I didn't write this script; this is almost directly copied from the dnkl/yambar github. - - -# cpu.sh - measures CPU usage at a configurable sample interval -# -# Usage: cpu.sh INTERVAL_IN_SECONDS -# -# This script will emit the following tags on stdout (N is the number -# of logical CPUs): -# -# Name Type -# -------------------- -# cpu range 0-100 -# cpu0 range 0-100 -# cpu1 range 0-100 -# ... -# cpuN-1 range 0-100 -# -# I.e. ‘cpu’ is the average (or aggregated) CPU usage, while cpuX is a -# specific CPU’s usage. -# -# Example configuration (update every second): -# -# - script: -# path: /path/to/cpu.sh -# args: [1] -# content: {string: {text: "{cpu}%"}} -# - -interval=2 - -case ${interval} in - ''|*[!0-9]*) - echo "interval must be an integer" - exit 1 - ;; - *) - ;; -esac - -# Get number of CPUs, by reading /proc/stat -# The output looks like: -# -# cpu A B C D ... -# cpu0 A B C D ... -# cpu1 A B C D ... -# cpuN A B C D ... -# -# The first line is a summary line, accounting *all* CPUs -IFS=$'\n' readarray -t all_cpu_stats < <(grep -e "^cpu" /proc/stat) -cpu_count=$((${#all_cpu_stats[@]} - 1)) - -# Arrays of ‘previous’ idle and total stats, needed to calculate the -# difference between each sample. -prev_idle=() -prev_total=() -for i in $(seq ${cpu_count}); do - prev_idle+=(0) - prev_total+=(0) -done - -prev_average_idle=0 -prev_average_total=0 - -while true; do - IFS=$'\n' readarray -t all_cpu_stats < <(grep -e "^cpu" /proc/stat) - - usage=() # CPU usage in percent, 0 <= x <= 100 - - average_idle=0 # All CPUs idle time since boot - average_total=0 # All CPUs total time since boot - - for i in $(seq 0 $((cpu_count - 1))); do - # Split this CPUs stats into an array - stats=($(echo "${all_cpu_stats[$((i + 1))]}")) - - # man procfs(5) - user=${stats[1]} - nice=${stats[2]} - system=${stats[3]} - idle=${stats[4]} - iowait=${stats[5]} - irq=${stats[6]} - softirq=${stats[7]} - steal=${stats[8]} - guest=${stats[9]} - guestnice=${stats[10]} - - # Guest time already accounted for in user - user=$((user - guest)) - nice=$((nice - guestnice)) - - idle=$((idle + iowait)) - - total=$((user + nice + system + irq + softirq + idle + steal + guest + guestnice)) - - average_idle=$((average_idle + idle)) - average_total=$((average_total + total)) - - # Diff since last sample - diff_idle=$((idle - prev_idle[i])) - diff_total=$((total - prev_total[i])) - - usage[i]=$((100 * (diff_total - diff_idle) / diff_total)) - - prev_idle[i]=${idle} - prev_total[i]=${total} - done - - diff_average_idle=$((average_idle - prev_average_idle)) - diff_average_total=$((average_total - prev_average_total)) - - average_usage=$((100 * (diff_average_total - diff_average_idle) / diff_average_total)) - - prev_average_idle=${average_idle} - prev_average_total=${average_total} - - echo "cpu|range:0-100|${average_usage}" - for i in $(seq 0 $((cpu_count - 1))); do - echo "cpu${i}|range:0-100|${usage[i]}" - done - - echo "" - sleep "${interval}" -done diff --git a/home-manager/config/yambar/scripts/dfspace b/home-manager/config/yambar/scripts/dfspace deleted file mode 100755 index 0b262481..00000000 --- a/home-manager/config/yambar/scripts/dfspace +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# Sleep seconds -timer="60" - -# Main loop -while true; do - - # vars - used_space=$(btrfs filesystem usage / 2> /dev/null | awk '{if ( /Used:/ ) { print $2 } } ' | head -n1) - all_space=$(btrfs filesystem usage / 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 $timer - -done - diff --git a/home-manager/config/yambar/scripts/disk.sh b/home-manager/config/yambar/scripts/disk.sh new file mode 100644 index 00000000..568ac71e --- /dev/null +++ b/home-manager/config/yambar/scripts/disk.sh @@ -0,0 +1,26 @@ +#! /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 / 2> /dev/null | awk '{if ( /Used:/ ) { print $2 } } ' | head -n1) + all_space=$(btrfs filesystem usage / 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 deleted file mode 100755 index a04b958c..00000000 --- a/home-manager/config/yambar/scripts/grades-average +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -. ~/.local/lib/shell/lib - -grade=$(grades list average | awk '{print $2}'); - -echo "grade|string|$grade"; -echo ""; - - -if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi diff --git a/home-manager/config/yambar/scripts/grades-average.sh b/home-manager/config/yambar/scripts/grades-average.sh new file mode 100644 index 00000000..72e180bd --- /dev/null +++ b/home-manager/config/yambar/scripts/grades-average.sh @@ -0,0 +1,15 @@ +#!/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/meminfo b/home-manager/config/yambar/scripts/meminfo deleted file mode 100755 index 0156e94c..00000000 --- a/home-manager/config/yambar/scripts/meminfo +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# Checks memory usage - -# Number of seconds to retest -timer=5 - -# Main loop -while true; do - - mem_total=$(LANG=C free -b|awk '/^Mem:/{print $2}') - mem_used=$(LANG=C free -b|awk '/^Mem:/{print $3}') - swap_total=$(LANG=C free -b|awk '/^Swap:/{print $2}') - swap_used=$(LANG=C free -b|awk '/^Swap:/{print $3}') - - - memperc=$(echo "$mem_used" "$mem_total" | awk '{ div = 100 * ($1 / $2)} { printf "%.0f ", div }' | tr -d ' ' ) - swapperc=$(echo "$swap_used" "$swap_total" | awk '{ - if ( $1 == 0 || $2 == 0 ) { - print "%" - } else { - div = 100 * ($1 / $2); - printf "%.0f ", div -} -}' | tr -d ' ' ) - - -echo "memperc|string|$memperc" -if [ "$swapperc" = "%" ];then - echo "swapstate|bool|false" -else - echo "swapperc|string|$swapperc" - echo "swapstate|bool|true" -fi -echo "" -sleep "$timer" - -done diff --git a/home-manager/config/yambar/scripts/network.sh b/home-manager/config/yambar/scripts/network.sh new file mode 100644 index 00000000..9d797e15 --- /dev/null +++ b/home-manager/config/yambar/scripts/network.sh @@ -0,0 +1,53 @@ +#! /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/nmclitest b/home-manager/config/yambar/scripts/nmclitest deleted file mode 100755 index 3e8bc73a..00000000 --- a/home-manager/config/yambar/scripts/nmclitest +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# Test for connectivity with nmcli - -Timer=${1:-120} # Number of seconds to retest -Timer2=${2:-10} # Number of seconds to retest if connection fails - -# Main loop -while true; do - - CONN=$(nmcli networking connectivity) - - if [[ "$CONN" == "full" ]]; then - echo "internet|string|Connected" - echo "" - sleep $Timer - else - echo "internet|string|Disconnected" - echo "" - sleep $Timer2 - fi - -done - diff --git a/home-manager/config/yambar/scripts/old/amixer-monitor b/home-manager/config/yambar/scripts/old/amixer-monitor new file mode 100755 index 00000000..9e75acfa --- /dev/null +++ b/home-manager/config/yambar/scripts/old/amixer-monitor @@ -0,0 +1,24 @@ +#!/bin/sh +# An improved amixer script that actually detects volume beyond 100% + + +SLEEPTIME=1 + + +while true; do + + volume=$(pactl get-sink-volume 0 | awk 'BEGIN { FS="/"} {print $2 }' | tr -d "%" | tr -d ' ') + + if [ "$volume" -eq 0 ]; then + echo "muted|bool|true" + + else + # Read sink volume in percentages + echo "volume|string|$volume" + echo "muted|bool|false" + fi + + echo "" + sleep "$SLEEPTIME" + +done diff --git a/home-manager/config/yambar/scripts/old/cpu b/home-manager/config/yambar/scripts/old/cpu new file mode 100755 index 00000000..bae820d0 --- /dev/null +++ b/home-manager/config/yambar/scripts/old/cpu @@ -0,0 +1,126 @@ +#!/bin/bash +# I didn't write this script; this is almost directly copied from the dnkl/yambar github. + + +# cpu.sh - measures CPU usage at a configurable sample interval +# +# Usage: cpu.sh INTERVAL_IN_SECONDS +# +# This script will emit the following tags on stdout (N is the number +# of logical CPUs): +# +# Name Type +# -------------------- +# cpu range 0-100 +# cpu0 range 0-100 +# cpu1 range 0-100 +# ... +# cpuN-1 range 0-100 +# +# I.e. ‘cpu’ is the average (or aggregated) CPU usage, while cpuX is a +# specific CPU’s usage. +# +# Example configuration (update every second): +# +# - script: +# path: /path/to/cpu.sh +# args: [1] +# content: {string: {text: "{cpu}%"}} +# + +interval=2 + +case ${interval} in + ''|*[!0-9]*) + echo "interval must be an integer" + exit 1 + ;; + *) + ;; +esac + +# Get number of CPUs, by reading /proc/stat +# The output looks like: +# +# cpu A B C D ... +# cpu0 A B C D ... +# cpu1 A B C D ... +# cpuN A B C D ... +# +# The first line is a summary line, accounting *all* CPUs +IFS=$'\n' readarray -t all_cpu_stats < <(grep -e "^cpu" /proc/stat) +cpu_count=$((${#all_cpu_stats[@]} - 1)) + +# Arrays of ‘previous’ idle and total stats, needed to calculate the +# difference between each sample. +prev_idle=() +prev_total=() +for i in $(seq ${cpu_count}); do + prev_idle+=(0) + prev_total+=(0) +done + +prev_average_idle=0 +prev_average_total=0 + +while true; do + IFS=$'\n' readarray -t all_cpu_stats < <(grep -e "^cpu" /proc/stat) + + usage=() # CPU usage in percent, 0 <= x <= 100 + + average_idle=0 # All CPUs idle time since boot + average_total=0 # All CPUs total time since boot + + for i in $(seq 0 $((cpu_count - 1))); do + # Split this CPUs stats into an array + stats=($(echo "${all_cpu_stats[$((i + 1))]}")) + + # man procfs(5) + user=${stats[1]} + nice=${stats[2]} + system=${stats[3]} + idle=${stats[4]} + iowait=${stats[5]} + irq=${stats[6]} + softirq=${stats[7]} + steal=${stats[8]} + guest=${stats[9]} + guestnice=${stats[10]} + + # Guest time already accounted for in user + user=$((user - guest)) + nice=$((nice - guestnice)) + + idle=$((idle + iowait)) + + total=$((user + nice + system + irq + softirq + idle + steal + guest + guestnice)) + + average_idle=$((average_idle + idle)) + average_total=$((average_total + total)) + + # Diff since last sample + diff_idle=$((idle - prev_idle[i])) + diff_total=$((total - prev_total[i])) + + usage[i]=$((100 * (diff_total - diff_idle) / diff_total)) + + prev_idle[i]=${idle} + prev_total[i]=${total} + done + + diff_average_idle=$((average_idle - prev_average_idle)) + diff_average_total=$((average_total - prev_average_total)) + + average_usage=$((100 * (diff_average_total - diff_average_idle) / diff_average_total)) + + prev_average_idle=${average_idle} + prev_average_total=${average_total} + + echo "cpu|range:0-100|${average_usage}" + for i in $(seq 0 $((cpu_count - 1))); do + echo "cpu${i}|range:0-100|${usage[i]}" + done + + echo "" + sleep "${interval}" +done diff --git a/home-manager/config/yambar/scripts/old/dfspace b/home-manager/config/yambar/scripts/old/dfspace new file mode 100755 index 00000000..0b262481 --- /dev/null +++ b/home-manager/config/yambar/scripts/old/dfspace @@ -0,0 +1,23 @@ +#!/bin/sh + +# Sleep seconds +timer="60" + +# Main loop +while true; do + + # vars + used_space=$(btrfs filesystem usage / 2> /dev/null | awk '{if ( /Used:/ ) { print $2 } } ' | head -n1) + all_space=$(btrfs filesystem usage / 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 $timer + +done + diff --git a/home-manager/config/yambar/scripts/old/grades-average b/home-manager/config/yambar/scripts/old/grades-average new file mode 100755 index 00000000..a04b958c --- /dev/null +++ b/home-manager/config/yambar/scripts/old/grades-average @@ -0,0 +1,12 @@ +#!/bin/sh +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +. ~/.local/lib/shell/lib + +grade=$(grades list average | awk '{print $2}'); + +echo "grade|string|$grade"; +echo ""; + + +if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi diff --git a/home-manager/config/yambar/scripts/old/meminfo b/home-manager/config/yambar/scripts/old/meminfo new file mode 100755 index 00000000..0156e94c --- /dev/null +++ b/home-manager/config/yambar/scripts/old/meminfo @@ -0,0 +1,37 @@ +#!/bin/sh +# Checks memory usage + +# Number of seconds to retest +timer=5 + +# Main loop +while true; do + + mem_total=$(LANG=C free -b|awk '/^Mem:/{print $2}') + mem_used=$(LANG=C free -b|awk '/^Mem:/{print $3}') + swap_total=$(LANG=C free -b|awk '/^Swap:/{print $2}') + swap_used=$(LANG=C free -b|awk '/^Swap:/{print $3}') + + + memperc=$(echo "$mem_used" "$mem_total" | awk '{ div = 100 * ($1 / $2)} { printf "%.0f ", div }' | tr -d ' ' ) + swapperc=$(echo "$swap_used" "$swap_total" | awk '{ + if ( $1 == 0 || $2 == 0 ) { + print "%" + } else { + div = 100 * ($1 / $2); + printf "%.0f ", div +} +}' | tr -d ' ' ) + + +echo "memperc|string|$memperc" +if [ "$swapperc" = "%" ];then + echo "swapstate|bool|false" +else + echo "swapperc|string|$swapperc" + echo "swapstate|bool|true" +fi +echo "" +sleep "$timer" + +done diff --git a/home-manager/config/yambar/scripts/old/nmclitest b/home-manager/config/yambar/scripts/old/nmclitest new file mode 100755 index 00000000..3e8bc73a --- /dev/null +++ b/home-manager/config/yambar/scripts/old/nmclitest @@ -0,0 +1,23 @@ +#!/bin/sh +# Test for connectivity with nmcli + +Timer=${1:-120} # Number of seconds to retest +Timer2=${2:-10} # Number of seconds to retest if connection fails + +# Main loop +while true; do + + CONN=$(nmcli networking connectivity) + + if [[ "$CONN" == "full" ]]; then + echo "internet|string|Connected" + echo "" + sleep $Timer + else + echo "internet|string|Disconnected" + echo "" + sleep $Timer2 + fi + +done + diff --git a/home-manager/config/yambar/scripts/old/pingtest b/home-manager/config/yambar/scripts/old/pingtest new file mode 100755 index 00000000..2b5f9998 --- /dev/null +++ b/home-manager/config/yambar/scripts/old/pingtest @@ -0,0 +1,28 @@ +#!/bin/sh +# Test for connectivity with ping + +Timer=${1:-120} # Number of seconds to retest +Timer2=${2:-10} # Number of seconds to retest if connection fails +IP=${3:-'8.8.8.8'} # IP address to test, defaults to Google +PCount=${4:-3} # Number of pings to send + +# Main loop +while true; do + + # Pings the IP address for five times + PINGSTR=$(ping $IP -c $PCount -q) + # Use text formatting to get min/max ms delays + MED=$(echo $PINGSTR | sed 's/min\/avg\/max\/mdev = /\n/g' | tail -n 1 | sed 's/\//\t/g' | cut -f2) + + if [[ "$MED" == "" ]]; then + echo "med|string|No connection" + echo "" + sleep $Timer2 + else + echo "med|string|$MED ms" + echo "" + sleep $Timer + fi + +done + diff --git a/home-manager/config/yambar/scripts/old/yambar-tray b/home-manager/config/yambar/scripts/old/yambar-tray new file mode 100755 index 00000000..1704c6dd --- /dev/null +++ b/home-manager/config/yambar/scripts/old/yambar-tray @@ -0,0 +1,27 @@ +#!/bin/sh + + +pkill stalonetray +pkill trayer + +# launch a tray. +echo + +sleep 0.1 # make sure yambar starts first so we can draw on tpo of it + +# trayer-srg fork! +trayer \ + --edge top \ + --tint 0x24242400 \ + --align right \ + --height 20 \ + --expand false \ + --transparent true \ + --alpha 0 \ + --width 20 \ + --monitor primary \ + --widthtype request + # &>/dev/null + + + diff --git a/home-manager/config/yambar/scripts/old/yambar-tray-width b/home-manager/config/yambar/scripts/old/yambar-tray-width new file mode 100755 index 00000000..00544e70 --- /dev/null +++ b/home-manager/config/yambar/scripts/old/yambar-tray-width @@ -0,0 +1,28 @@ +#!/bin/sh +# shellcheck disable=SC2086 +# shellcheck source=/dev/null +. ~/.local/lib/shell/lib + + +CHARWIDTH=8 # i guess? + +tray_width_px() { + xwininfo -name panel | # trayer names its window "panel" + grep -i width: | + awk '{print $2}' +} + +px_to_spaces() { + spaces="$((1 + ${1:-0} / $CHARWIDTH))" + printf "% *s\n" $spaces +} + +sleep 0.2 # be sure trayer is already up + +output="$(px_to_spaces `tray_width_px`)" +echo "padding|string|$output" +echo "" + + + +if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi diff --git a/home-manager/config/yambar/scripts/pingtest b/home-manager/config/yambar/scripts/pingtest deleted file mode 100755 index 2b5f9998..00000000 --- a/home-manager/config/yambar/scripts/pingtest +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Test for connectivity with ping - -Timer=${1:-120} # Number of seconds to retest -Timer2=${2:-10} # Number of seconds to retest if connection fails -IP=${3:-'8.8.8.8'} # IP address to test, defaults to Google -PCount=${4:-3} # Number of pings to send - -# Main loop -while true; do - - # Pings the IP address for five times - PINGSTR=$(ping $IP -c $PCount -q) - # Use text formatting to get min/max ms delays - MED=$(echo $PINGSTR | sed 's/min\/avg\/max\/mdev = /\n/g' | tail -n 1 | sed 's/\//\t/g' | cut -f2) - - if [[ "$MED" == "" ]]; then - echo "med|string|No connection" - echo "" - sleep $Timer2 - else - echo "med|string|$MED ms" - echo "" - sleep $Timer - fi - -done - diff --git a/home-manager/config/yambar/scripts/sound-volume.sh b/home-manager/config/yambar/scripts/sound-volume.sh new file mode 100644 index 00000000..8fc0107f --- /dev/null +++ b/home-manager/config/yambar/scripts/sound-volume.sh @@ -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 + + +# vim: ft=sh diff --git a/home-manager/config/yambar/scripts/yambar-tray b/home-manager/config/yambar/scripts/yambar-tray deleted file mode 100755 index 1704c6dd..00000000 --- a/home-manager/config/yambar/scripts/yambar-tray +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - - -pkill stalonetray -pkill trayer - -# launch a tray. -echo - -sleep 0.1 # make sure yambar starts first so we can draw on tpo of it - -# trayer-srg fork! -trayer \ - --edge top \ - --tint 0x24242400 \ - --align right \ - --height 20 \ - --expand false \ - --transparent true \ - --alpha 0 \ - --width 20 \ - --monitor primary \ - --widthtype request - # &>/dev/null - - - diff --git a/home-manager/config/yambar/scripts/yambar-tray-width b/home-manager/config/yambar/scripts/yambar-tray-width deleted file mode 100755 index 00544e70..00000000 --- a/home-manager/config/yambar/scripts/yambar-tray-width +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# shellcheck disable=SC2086 -# shellcheck source=/dev/null -. ~/.local/lib/shell/lib - - -CHARWIDTH=8 # i guess? - -tray_width_px() { - xwininfo -name panel | # trayer names its window "panel" - grep -i width: | - awk '{print $2}' -} - -px_to_spaces() { - spaces="$((1 + ${1:-0} / $CHARWIDTH))" - printf "% *s\n" $spaces -} - -sleep 0.2 # be sure trayer is already up - -output="$(px_to_spaces `tray_width_px`)" -echo "padding|string|$output" -echo "" - - - -if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi -- cgit 1.4.1