scripts: make all POSIX compliant

This commit is contained in:
Michele Guerini Rocco 2020-07-25 17:38:45 +02:00
parent 15deaadc5f
commit 05f3c5aa0f
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
7 changed files with 65 additions and 61 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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/<plaintext>/\'$'\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'