From 0d374a5f82b88177d2fdaf35d9c28080a8f35494 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 4 Nov 2025 16:37:44 +0000 Subject: awk refactor of my scripts awk is OP man - so easy to use and does a bunch of stuff all at once without having to rely on multiple pipes. It comes with essentially every distribution so you'll always have access to it. --- Scripts/.local/scripts/qscope | 2 +- Scripts/.local/scripts/status/bluetooth-status | 22 ++++++++++++---------- Scripts/.local/scripts/status/connection | 4 ++-- Scripts/.local/scripts/status/temperature | 3 ++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Scripts/.local/scripts/qscope b/Scripts/.local/scripts/qscope index 0ae22cb..bd62e3a 100755 --- a/Scripts/.local/scripts/qscope +++ b/Scripts/.local/scripts/qscope @@ -1,3 +1,3 @@ #!/usr/bin/env sh -pgrep ".*" -l | dmenu -p "Choose process: " | sed "s/\\([0-9]*\\).*/\1/g" | xargs kill -9 $1 +pgrep ".*" -l | dmenu -p "Choose process: " | awk '{ print $1 }' | xargs kill -9 $1 diff --git a/Scripts/.local/scripts/status/bluetooth-status b/Scripts/.local/scripts/status/bluetooth-status index a84ede3..0eadb4e 100755 --- a/Scripts/.local/scripts/status/bluetooth-status +++ b/Scripts/.local/scripts/status/bluetooth-status @@ -1,23 +1,25 @@ #!/usr/bin/env sh -devices=$(bluetoothctl devices Connected | grep -oE '([0-9A-Fa-f:]{17})') +devices=$(bluetoothctl devices Connected | awk '{print $2}') if [ -z "$devices" ] then - echo "" + echo '' else - acc="" - + sep='' + printf ' ' for mac in $devices do - name=$(bluetoothctl info $mac | grep "Alias" | sed 's/.*Alias: //') - battery=$(bluetoothctl info $mac | grep "Battery Percentage" | sed 's/.*(//;s/)//') - acc="$acc $name" + name=$(bluetoothctl info $mac | awk -F ': ' '/Alias/ { print $2 }') + battery=$(bluetoothctl info $mac | awk -F '[()]' '/Battery Percentage/ { print $2 }') + + printf "$sep<$name" if [ "$battery" ] then - acc="$acc ($battery%)" + printf " $battery%%" fi + printf ">" + sep=" " done - - echo "$acc" + printf "\n" fi diff --git a/Scripts/.local/scripts/status/connection b/Scripts/.local/scripts/status/connection index 84f84dc..5c566fb 100755 --- a/Scripts/.local/scripts/status/connection +++ b/Scripts/.local/scripts/status/connection @@ -1,9 +1,9 @@ #!/usr/bin/env bash -internet=$(nmcli g | sed -n 2p | awk '{print $1}') +internet=$(nmcli g | awk 'NR == 2 {print $1}') if [[ $internet == "connected" ]] then - con=$(nmcli | grep "connected to" | sed "s/.*: connected to \(.*\)/\1/g") + con=$(nmcli | awk -F "to " '/connected to/ { print $2 }') echo "" $con else echo "" diff --git a/Scripts/.local/scripts/status/temperature b/Scripts/.local/scripts/status/temperature index 1a6f5dd..b81fe9e 100755 --- a/Scripts/.local/scripts/status/temperature +++ b/Scripts/.local/scripts/status/temperature @@ -1,3 +1,4 @@ #!/usr/bin/env sh -echo "㊋ $(sensors | grep "Tctl" | sed 's/Tctl:.*+\(.*\)C.*/\1/')C" +data=$(sensors | awk -F'+' '/Tctl/ { gsub(/[ \t]+$/, "", $2); print $2 }') +echo "㊋ $data" -- cgit v1.2.3-13-gbd6f