bin: simplify scripts through expr and improve formatting

This commit is contained in:
xeruf 2021-07-04 23:22:53 +02:00
parent 51da712040
commit 81f4e66774
7 changed files with 31 additions and 30 deletions

View File

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh
suffix="${2:-bak}" suffix="${2:-bak}"
orig="${1%%.$suffix}" orig="${1%%.$suffix}"
echo $orig
if test -e "$orig.$suffix" if test -e "$orig.$suffix"
then then
test -e "$orig" && mv -v "$orig" /tmp test -e "$orig" && mv -v "$orig" /tmp

View File

@ -3,10 +3,10 @@
# Useful when the history has been manipulated # Useful when the history has been manipulated
loc="$(git lo --color=always "$@")" loc="$(git lo --color=always "$@")"
upstream="$(git lo --color=always @{push} "$@")" upstream="$(git lo --color=always @{push} "$@")"
a=$(echo $loc | wc -l) countLoc=$(echo $loc | wc -l)
b=$(echo $upstream | wc -l) countUp=$(echo $upstream | wc -l)
halfcols="$(expr $(tput cols) / 2)" halfcols="$(expr $(tput cols) / 2)"
for i in $(seq 1 $(test $a -le $b && echo "$a" || echo "$b")); do for i in $(seq 1 $(expr $countLoc \& $countLoc \< $countUp \| $countUp)); do
printf "%-${halfcols}s $(test $halfcols -lt 100 && echo '\\n')%s\n" "$(echo $loc | head -n $i | tail -1)" "$(echo $upstream | head -n $i | tail -1)" printf "%-${halfcols}s $(test $halfcols -lt 100 && echo '\\n')%s\n" "$(echo $loc | head -n $i | tail -1)" "$(echo $upstream | head -n $i | tail -1)"
# use columns instead? - need to interleave! # use columns instead? - need to interleave!
done | ${PAGER:-less} done | ${PAGER:-less}

View File

@ -5,6 +5,9 @@ case "$1" in ([0-9]*) code=$1; shift;; esac
task="${1:-test}" task="${1:-test}"
test $# -gt 1 && prefix=":$2:" test $# -gt 1 && prefix=":$2:"
gradle=$(test -x "./gradlew" && echo "./gradlew" || echo "gradle") gradle=$(test -x "./gradlew"; expr gradle \& $? \| ./gradlew)
( exit $code ); while test $? -eq $code; do $gradle ${prefix}clean$(echo $task | sed -e 's/^./\U&/') ${prefix}$task "${@:3}"; done ( exit $code )
while test $? -eq $code
do $gradle ${prefix}clean$(echo $task | sed -e 's/^./\U&/') ${prefix}$task "${@:3}"
done

View File

@ -5,15 +5,15 @@ if test -f "$subscript"
then shift && $subscript "$@" then shift && $subscript "$@"
else else
apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1) apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1)
parseargs() {
echo hi
}
case "$1" in case "$1" in
(browse|completion|file|ignores|need|status) (browse|completion|file|ignores|need|status)
for arg in "${@:2}" for arg in "${@:2}"
do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac
done done
query="db/$1?folder=$(test -n "$path" && echo "${path%%/*}" || echo "data")&levels=${depth:-1}$(case "$path" in (*/*) echo "&prefix=${path#*/}";; esac)";; query=$(echo "db/$1?folder=$(expr "${path%%/*}" \& "$path" \| data)
$(expr levels \& "$1" = "browse" \| page)=${depth:-1}
$(case "$path" in (*/*) echo "$(expr "prefix" \& "$1" = "browse" \| "$1")=${path#*/}";; esac)" |
tr -d ' ' | paste -s -d'&');;
(*) query="$1";; (*) query="$1";;
esac esac
shift shift

View File

@ -21,6 +21,6 @@ if test "$#" -gt 0
esac esac
fi fi
else else
find "$DATA/2-standards/notes/journal" -name "intentions.sync-conflict*" -exec jrnl intentions --import --file {} \; -delete find "$DATA/2-standards/notes/journal" -name "intentions*sync-conflict*" -exec sh -c 'basename {} | cut -d. -f1 | xargs -i% jrnl % --import --file {}' \; -delete
find -name '*sync-conflict*' -exec st-diff $quick '{}' \; find -name '*sync-conflict*' -exec st-diff $quick '{}' \;
fi fi

View File

@ -1,40 +1,39 @@
#!/bin/sh #!/bin/sh
# Set Workrave mode to quiet and wait the given amount of minutes (default: 10)
# Sets Workrave mode to quiet and waits the given amount of minutes (default: 10)
# If no amount is given or the -f flag is provided, it checks whether a fullscreen application is running and if no, exits # If no amount is given or the -f flag is provided, it checks whether a fullscreen application is running and if no, exits
# On exit or Ctrl-C (SIGINT) it sets the Workrave mode back to normal # On exit or Ctrl-C (SIGINT) set Workrave mode back to normal
while true; do while true; do
case $1 in case $1 in
(-q) quiet=1; shift 1;; (-q) quiet=1; shift 1;;
(-f) fullscreen=1; shift 1;; (-f) fullscreen=1; shift 1;;
(*) break;; (*) break;;
esac esac
done done
getFullscreen() { getFullscreen() {
# See https://askubuntu.com/a/1265587 # See https://askubuntu.com/a/1265587
# Get screen size # Get screen size
root_geo=$(xwininfo -root | awk -F'[ +x]' '$3 ~ /-geometry/ {printf "%dx%d",$4/'"$(xrandr | grep ' connected ' | wc -l)"',$5}') root_geo=$(xwininfo -root | awk -F'[ +x]' '$3 ~ /-geometry/ {printf "%dx%d",$4/'"$(xrandr | grep ' connected ' | wc -l)"',$5}')
# Check if any window fills the screen # Check if any window fills the screen
xwininfo -root -tree | grep $root_geo | grep -qv "\(Desktop\|has no name\)" xwininfo -root -tree | grep $root_geo | grep -qv "\(Desktop\|has no name\)"
} }
setWorkraveOperationMode() { setWorkraveOperationMode() {
dbus-send --session --dest=org.workrave.Workrave --type=method_call \ dbus-send --session --dest=org.workrave.Workrave --type=method_call \
/org/workrave/Workrave/Core org.workrave.CoreInterface.SetOperationMode \ /org/workrave/Workrave/Core org.workrave.CoreInterface.SetOperationMode \
string:"$1" string:"$1"
} }
resetWorkraveMode() { resetWorkraveMode() {
test "$quiet" || echo "Setting Workrave operation mode to normal" test "$quiet" || echo "Setting Workrave operation mode to normal"
setWorkraveOperationMode "normal" setWorkraveOperationMode "normal"
} }
trap resetWorkraveMode EXIT INT trap resetWorkraveMode EXIT INT
test "$quiet" || echo "Silencing workrave" test "$quiet" || echo "Silencing workrave"
setWorkraveOperationMode "quiet" setWorkraveOperationMode "quiet"
while true; do while true; do
sleep ${1:-10}m sleep ${1:-10}m
test "$fullscreen" && getFullscreen || break test "$fullscreen" && getFullscreen || break
done done

View File

@ -4,7 +4,7 @@ umask 0
case $ACTION in case $ACTION in
(add) id=1;; (add) id=1;;
(remove) id=0;; (remove) id=0;;
(*) id=$(test -c /dev/ttyACM0 && echo 1 || echo 0);; (*) id=$(! test -c /dev/ttyACM0; echo $?);;
esac esac
echo "Keyboard layout update to $id($ACTION) at $(date)" echo "Keyboard layout update to $id($ACTION) at $(date)"
export XAUTHORITY="/run/user/1000/Xauthority" DISPLAY=:0 export XAUTHORITY="/run/user/1000/Xauthority" DISPLAY=:0