From 05f3c5aa0f6bd0f8a7cd2250ae0449951f0c878d Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 25 Jul 2020 17:38:45 +0200 Subject: [PATCH] scripts: make all POSIX compliant --- scripts/beep-charlie | 17 +++++++------ scripts/beep-wigfrid | 15 +++++++----- scripts/brightness | 6 ++--- scripts/color-mode | 17 +++++++------ scripts/redshift-acpi | 2 +- scripts/redshift-i2c | 12 ++++----- scripts/wa | 57 ++++++++++++++++++++----------------------- 7 files changed, 65 insertions(+), 61 deletions(-) diff --git a/scripts/beep-charlie b/scripts/beep-charlie index 29030a3..bc83443 100755 --- a/scripts/beep-charlie +++ b/scripts/beep-charlie @@ -1,12 +1,15 @@ #!/bin/sh lock=/tmp/.beep-lock -test -f $lock && exit 1 || touch $lock -head -c 8 /dev/urandom | \ - hexdump -v -e '/1 "%u\n"' | \ - awk '{ split("0,3,5,6,7,10,12",a,","); \ - for (i = 0; i < 1; i+= 0.00012) \ - printf("%08X\n", 60*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' | \ - xxd -r -p | \ +test -f $lock && exit 1 +touch $lock + +head -c 8 /dev/urandom | + hexdump -v -e '/1 "%u\n"' | + awk '{ split("0,3,5,6,7,10,12",a,","); + for (i = 0; i < 1; i+= 0.00012) + printf("%08X\n", 60*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' | + xxd -r -p | aplay -c 1 -f S32_LE -r 48000 -D plug:default + rm -f $lock diff --git a/scripts/beep-wigfrid b/scripts/beep-wigfrid index 5198ab2..ecff83c 100755 --- a/scripts/beep-wigfrid +++ b/scripts/beep-wigfrid @@ -1,12 +1,15 @@ #!/bin/sh lock=/tmp/.beep-lock -test -f $lock && exit 1 || touch $lock +test -f $lock && exit 1 +touch $lock + head -c 4 /dev/urandom | \ - hexdump -v -e '/1 "%u\n"' | \ - awk '{ split("0,3,5,6,7,10,12",a,","); \ - for (i = 0; i < 1; i+= 0.00011) \ - printf("%08X\n", 40*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' | \ - xxd -r -p | \ + hexdump -v -e '/1 "%u\n"' | + awk '{ split("0,3,5,6,7,10,12",a,","); + for (i = 0; i < 1; i+= 0.00011) + printf("%08X\n", 40*sin(450*exp((a[$1 % 8]/12)*log(2))*i)) }' | + xxd -r -p | aplay -c 2 -f S16_LE -r 48000 -Dplug:hdmi1 + rm -f $lock diff --git a/scripts/brightness b/scripts/brightness index c51f8fa..3cce143 100755 --- a/scripts/brightness +++ b/scripts/brightness @@ -5,7 +5,7 @@ current=$(cat /sys/class/backlight/intel_backlight/brightness) if test -z "$1"; then - echo $current + echo "$current" exit 0 fi @@ -15,7 +15,7 @@ case "$1" in echo "missing increment" exit 1 fi - new=$(("$current" "$1" "$2")) + new="$((current $1 $2))" ;; *) echo "invalid argument '$1'" @@ -24,4 +24,4 @@ case "$1" in esac echo "current: $new" -echo $new > /sys/class/backlight/intel_backlight/brightness +echo "$new" > /sys/class/backlight/intel_backlight/brightness diff --git a/scripts/color-mode b/scripts/color-mode index 950a88f..fbe436f 100755 --- a/scripts/color-mode +++ b/scripts/color-mode @@ -2,19 +2,20 @@ xcolor() { xrdb -query | grep -Po "color$1:\s+\K#\w+"; } -xrdb -override $XDG_CONFIG_HOME/x/$1 +xrdb -override "$XDG_CONFIG_HOME/x/$1" pkill -USR1 'qutebrowser|urxvt' -$XDG_CONFIG_HOME/bspwm/bspwmrc +"$XDG_CONFIG_HOME/bspwm/bspwmrc" -if test "$1" == light; then - xsetroot -fg $(xcolor 14) -bg $(xcolor 11) -bitmap ~/img/tiles/tile.xbm - bspc config focused_border_color $(xcolor 3) - bspc config normal_border_color $(xcolor 8) - bspc config presel_feedback_color $(xcolor 3) +if test "$1" = light; then + xsetroot -fg "$(xcolor 14)" -bg "$(xcolor 11)" \ + -bitmap ~/img/tiles/tile.xbm + bspc config focused_border_color "$(xcolor 3)" + bspc config normal_border_color "$(xcolor 8)" + bspc config presel_feedback_color "$(xcolor 3)" fi -if test "$1" == dark; then +if test "$1" = dark; then xsetroot -fg \#4F5B66 -bg \#343D46 -bitmap ~/img/tiles/tile.xbm fi diff --git a/scripts/redshift-acpi b/scripts/redshift-acpi index 8da6097..c410eed 100755 --- a/scripts/redshift-acpi +++ b/scripts/redshift-acpi @@ -15,7 +15,7 @@ deref() { fade_to() { current=$(brightness) - echo $current $1 + echo "$current $1" step=10 [ "$current" -gt "$1" ] && sign=- || sign=+ for i in $(seq "$current" "${sign}$step" "$1"); do diff --git a/scripts/redshift-i2c b/scripts/redshift-i2c index 63ffee7..bed0eb6 100755 --- a/scripts/redshift-i2c +++ b/scripts/redshift-i2c @@ -18,22 +18,22 @@ deref() { } set_brightness() { - sudo ddccontrol $device -r 0x10 -w > /dev/null $1 2>&1 + sudo ddccontrol $device -r 0x10 -w > /dev/null "$1" 2>&1 } fade_to() { current=$(sudo ddccontrol $device -r 0x10 2> /dev/null | grep -oP '\+/\K[0-9]+') - [ $current -gt $1 ] && step=-1 || step=1 - for i in $(seq $current $step $1); do - set_brightness $i + [ "$current" -gt "$1" ] && step=-1 || step=1 + for i in $(seq "$current" "$step" "$1"); do + set_brightness "$i" sleep 1 done } -if [ $1 = "period-changed" ]; then +if [ "$1" = "period-changed" ]; then if ! (lsmod | grep -q "^i2c_dev"); then sudo modprobe i2c-dev fi - fade_to $(deref $3) + fade_to "$(deref "$3")" fi diff --git a/scripts/wa b/scripts/wa index 06640ea..d98b54d 100755 --- a/scripts/wa +++ b/scripts/wa @@ -1,44 +1,41 @@ -#!/usr/bin/sh +#!/bin/sh ## WolframAlpha CLI # load api key -token="${XDG_CONFIG_HOME:-$HOME}/wolfram" -source $token +token="$XDG_CONFIG_HOME/wolfram" +. "$token" # properly encode query -q=$(echo ${*} | sed 's/+/%2B/g' | tr '\ ' '\+') +q=$(echo "$*" | sed 's/+/%2B/g' | tr '\ ' '\+') # fetch and parse result -result=$(curl -s "http://api.wolframalpha.com/v2/query?input=${q}&appid=${API_KEY}&format=plaintext") +result="$(curl -s "http://api.wolframalpha.com/v2/query?input=$q&appid=$API_KEY&format=plaintext")" -if [ -n "$(echo ${result} | grep 'Invalid appid')" ] ; then +if echo "$result" | grep -q 'Invalid appid'; then echo "Invalid API key!" echo "Get one at https://developer.wolframalpha.com/portal/apisignup.html" - echo -n 'Enter your WolframAlpha API key:' - read api_key - echo "API_KEY=${api_key}" >> $token + printf 'Enter your WolframAlpha API key:' + read -r api_key + echo "API_KEY=${api_key}" >> "$token" exit 1 fi -result=`echo "${result}" \ - | tr '\n' '\t' \ - | sed -e 's//\'$'\n<plaintext>/g' \ - | grep -oE "<plaintext>.*</plaintext>|<pod title=.[^\']*" \ - | sed -e 's!<plaintext>!!g; \ - s!</plaintext>!!g; \ - s!<pod title=.*!\\\x1b[1;36m&\\\x1b[0m!g; \ - s!^! !g; \ - s!<pod title=.!\n!g; \ - s!\&amp;!\&!g; \ - s!\&lt;!<!g; \ - s!\&gt;!>!g; \ - s!\&quot;!"!g' \ - -e "s/\&apos;/'/g" \ - | tr '\t' '\n' \ - | sed '/^$/d; \ - s/\ \ */\ /g; \ - s/\\\:/\\\u/g'` - -# print result -echo -e "${result}" +echo "$result" | + tr '\n' '\t' | + sed -e 's/<plaintext>/\n<plaintext>/g' | + grep -oE "<plaintext>.*</plaintext>|<pod title=.[^\']*" | + sed -e 's!<plaintext>!!g' \ + -e 's!</plaintext>!!g' \ + -e 's!<pod title=.*!\x1b[1;36m&\x1b[0m!g' \ + -e 's!^! !g' \ + -e 's!<pod title=.!\n!g' \ + -e 's!\&amp;!\&!g' \ + -e 's!\&lt;!<!g' \ + -e 's!\&gt;!>!g' \ + -e 's!\&quot;!"!g' \ + -e "s/\&apos;/'/g" | + tr '\t' '\n' | + sed -e '/^$/d;' \ + -e 's/\ \ */\ /g;' \ + -e 's/\\\:/\\\u/g'