From 9706c8c819338256eef0470d053654f98c5775ef Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 7 Oct 2015 16:33:45 +0200 Subject: [PATCH] Scripts: Fix cpuusage, currency, cxev --- .scripts/cpuusage | 22 +++++++++++----------- .scripts/currency | 2 +- .scripts/cxev | 20 ++++++++++++++++---- .scripts/getip | 2 -- 4 files changed, 28 insertions(+), 18 deletions(-) delete mode 100755 .scripts/getip diff --git a/.scripts/cpuusage b/.scripts/cpuusage index 2fa454e5..8dc7c7ac 100755 --- a/.scripts/cpuusage +++ b/.scripts/cpuusage @@ -35,22 +35,22 @@ fi ## ## Only the first 4 values are interesting here. -cpuarray="$(grep 'cpu ' /proc/stat)" -f1=$(echo $cpuarray | cut -f3 -d' ') -f2=$(echo $cpuarray | cut -f4 -d' ') -f3=$(echo $cpuarray | cut -f5 -d' ') -f4=$(echo $cpuarray | cut -f6 -d' ') +cpuarray="$(grep '^cpu ' /proc/stat)" +## We start at field #3 since there are 2 spaces after 'cpu'. +f1=$(echo "$cpuarray" | cut -f3 -d' ') +f2=$(echo "$cpuarray" | cut -f4 -d' ') +f3=$(echo "$cpuarray" | cut -f5 -d' ') +f4=$(echo "$cpuarray" | cut -f6 -d' ') totalA=$(($f1+$f2+$f3+$f4)) idleA=$f4 - sleep 1 -cpuarray="$(grep 'cpu ' /proc/stat)" -f1=$(echo $cpuarray | cut -f3 -d' ') -f2=$(echo $cpuarray | cut -f4 -d' ') -f3=$(echo $cpuarray | cut -f5 -d' ') -f4=$(echo $cpuarray | cut -f6 -d' ') +cpuarray="$(grep '^cpu ' /proc/stat)" +f1=$(echo "$cpuarray" | cut -f3 -d' ') +f2=$(echo "$cpuarray" | cut -f4 -d' ') +f3=$(echo "$cpuarray" | cut -f5 -d' ') +f4=$(echo "$cpuarray" | cut -f6 -d' ') totalB=$(($f1+$f2+$f3+$f4)) idleB=$f4 diff --git a/.scripts/currency b/.scripts/currency index 8f3d4a63..049b78d3 100755 --- a/.scripts/currency +++ b/.scripts/currency @@ -12,4 +12,4 @@ EOF fi curl -sA "Mozilla/5.0" "http://www.google.com/finance?q=$2$3" | \ - awk -v value=$1 -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}' + awk -v value="$1" -F '<|>' '/^1 / {print value * substr($3, 1, index($3," "))}' diff --git a/.scripts/cxev b/.scripts/cxev index 9b1ae1b2..48be9ab0 100755 --- a/.scripts/cxev +++ b/.scripts/cxev @@ -1,6 +1,11 @@ #!/bin/sh -xev | awk '/KeyPress|KeyRelease/ { +compat="" +if [ $(awk --version | grep -c GNU) -gt 0 ]; then + # This is for hex-to-decimal conversion. + compat="--non-decimal" +fi +xev "$@" | awk $compat '/KeyPress|KeyRelease/ { if ($1 == "KeyPress") event="pressed"; else @@ -11,8 +16,15 @@ xev | awk '/KeyPress|KeyRelease/ { keycode = $4; keysym = substr($7, 1, length($7)-2); - getline; - string=$6; + printf "%-16s code=%-3s state=%s event=%-8s", keysym, keycode, state, event - printf "%-10s: code=%-3s state=%s event=%-8s string=%s\n", keysym, keycode, state, event, string + getline; + gsub(/\(|\)/, "", $5) + code=int(sprintf("%d", "0x" $5)) + if (code > 32 && code != 127) { + /* Ignore non-printable characters" */ + gsub(/"/, "", $NF) + printf " string=%s", $NF + } + print "" }' diff --git a/.scripts/getip b/.scripts/getip deleted file mode 100755 index fa1b755d..00000000 --- a/.scripts/getip +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -zenity --info --text "IP: $(curl -s 192.168.1.1 | awk -F'>: |<' '/Adresse IP/{getline;print $3;exit}')"