What is Nostr?
menherahair /
npub1n78…87ev
2024-01-26 12:32:36
in reply to nevent1q…t5ht

menherahair on Nostr: Yukkuri It was late and I thought shell would mess up this math at least for some ...

Yukkuri (npub1j05…w8rl) It was late and I thought shell would mess up this math at least for some resolutions, but I guess that doesn't happen if you fit it all in one statement.
That awk fails to match xrandr's annoying output, I'd use 'x| +' for the field separator. So the simplified code comes down to:
set -- $(xrandr --current | awk -F 'x| +' '/\*/ {print $2, $3}'); PAD=$((($1-$2*4/3)/2));
or with sed:
set -- $(xrandr --current | sed -En '/\*/ { s/ *([0-9]+)x([0-9]+).*/\1 \2/; p }'); PAD=$((($1-$2*4/3)/2));
but extended sed is not POSIX.
they run comparably (awk is mawk):
menherahair@kishu:~$ time { for i in {1..10000}; do set -- $(xrandr --current | sed -En '/\*/ { s/ *([0-9]+)x([0-9]+).*/\1 \2/; p }'); PAD=$((($1-$2*4/3)/2)); done ; }

real 1m5.756s
user 0m40.500s
sys 1m4.938s
menherahair@kishu:~$ time { for i in {1..10000}; do set -- $(xrandr --current | awk -F 'x| +' '/\*/ {print $2, $3}'); PAD=$((($1-$2*4/3)/2)); done ; }

real 1m5.121s
user 0m41.808s
sys 0m59.352s
So the awk is better; at this point may as well have it do the math:
menherahair@kishu:~$ time { for i in {1..10000}; do PAD=$(xrandr --current | awk -F 'x| +' '/\*/ {print ($2-$3*4/3)/2}'); done ; }

real 1m4.841s
user 0m40.287s
sys 1m0.287s
I'll swap this in.
Author Public Key
npub1n783957maa2g7rpdyd5knx0whfggllws33clq9qg4dme3wauxrvq6q87ev