From 7b4af3aef6e69d4aea1706af47bbba455e9f9a9b Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Sun, 30 May 2021 23:19:02 +0530 Subject: [PATCH 1/3] picom-trans: Use POSIX-compatible sed, grep \b \? \+ \| are GNU extensions to sed In BRE (Basic Regular Expressions) there is no \? \+ or \| In ERE (Extended Regular Expressions) there is ? + and | To specify sed to use ERE, specify the -E flag. GNU grep does not distinguish between BRE and ERE, but other implementations do. To make grep use ERE instead of BRE, specify the -E flag. The GNU extension \b has no equivalent in either BRE or ERE. So, in line number 216, I used the whole initial expected output. For quick reference (n/a means 'not available') - GNU BRE | POSIX BRE | POSIX ERE ------------------------------- \( | \( | ( \) | \) | ) \? | \{0,1\} | ? or {0,1} \+ | \{1,\} | + or {1,} \| | n/a | | \b | n/a | n/a --- bin/picom-trans | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/picom-trans b/bin/picom-trans index 99031d9b..27ba38e5 100755 --- a/bin/picom-trans +++ b/bin/picom-trans @@ -79,7 +79,7 @@ v= # Workaround: replace '-5' with '~5' so as not to confuse getopts. for v in "$@"; do - shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')" + shift && set -- "$@" "$(echo "$v" | sed -E 's/^-([0-9]+%?)$/~\1/')" done # This takes into account the fact that getopts stops on @@ -102,7 +102,7 @@ while test $# -gt 0; do OPTIND=$((OPTIND + 1)) ;; name=* | window=* | opacity=*) - v=$(echo "$OPTARG" | sed 's/^[^=]\+=//') + v=$(echo "$OPTARG" | sed -E 's/^[^=]+=//') ;; *) echo "$0: illegal option $OPTARG" >& 2 @@ -137,10 +137,10 @@ while test $# -gt 0; do done # clean up opacity. xargs == a poor man's trim. -opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed 's/^~\([0-9]\+\)$/-\1/') +opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed -E 's/^~([0-9]+)$/-\1/') # Validate opacity value -if test -z "$action" && ! echo "$opacity" | grep -q '^[+-]\?[0-9]\+$'; then +if test -z "$action" && ! echo "$opacity" | grep -qE '^[+-]?[0-9]+$'; then echo "Invalid opacity specified: $opacity." exit 1 fi @@ -213,7 +213,7 @@ fi # Get current opacity. cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_OPACITY \ - | sed 's/^.*\b\([0-9]\+\).*$\|^.*$/\1/') + | sed -E 's/^_NET_WM_WINDOW_OPACITY = ([0-9]*)$|^.*$/\1/') # Remove the opacity property. if test x"$action" = x'delete' -o \( x"$action" = x'toggle' -a -n "$cur" \); then From df1c6159fca1a11cab02cd095f7afe4c7642fae2 Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Mon, 31 May 2021 12:27:18 +0530 Subject: [PATCH 2/3] picom-trans: Use POSIX-compatible getopts --- bin/picom-trans | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/picom-trans b/bin/picom-trans index 27ba38e5..d90431ef 100755 --- a/bin/picom-trans +++ b/bin/picom-trans @@ -82,16 +82,15 @@ for v in "$@"; do shift && set -- "$@" "$(echo "$v" | sed -E 's/^-([0-9]+%?)$/~\1/')" done -# This takes into account the fact that getopts stops on -# any argument it doesn't recognize or errors on. This -# allows for things like `picom-trans -5` as well -# as `picom-trans -c +5 -s` (contrived example). +# We make getopts stop on any argument it doesn't recognize +# or errors on. This allows for things like `picom-trans -5` +# as well as `picom-trans -c +5 -s` (contrived example). while test $# -gt 0; do # Reset option index OPTIND=1 # Read options - while getopts 'hscrtdgn:w:o:-:' option "$@"; do + while getopts ':hscrtdgn:w:o:-:' option "$@"; do if test "$option" = '-'; then case "$OPTARG" in help | select | current | reset | toggle | delete | get) @@ -127,7 +126,7 @@ while test $# -gt 0; do n) wprefix='-name'; window=$OPTARG ;; w) wprefix='-id'; window=$OPTARG ;; o) opacity=$OPTARG ;; - \?) exit 1 ;; + \?) break ;; esac done From 5394b2c2bce92856b73046d707e7391cf31cbeab Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Mon, 31 May 2021 12:32:12 +0530 Subject: [PATCH 3/3] picom-trans: remove a no-longer-needed workaround --- bin/picom-trans | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bin/picom-trans b/bin/picom-trans index d90431ef..2c84634f 100755 --- a/bin/picom-trans +++ b/bin/picom-trans @@ -77,11 +77,6 @@ lineno= option= v= -# Workaround: replace '-5' with '~5' so as not to confuse getopts. -for v in "$@"; do - shift && set -- "$@" "$(echo "$v" | sed -E 's/^-([0-9]+%?)$/~\1/')" -done - # We make getopts stop on any argument it doesn't recognize # or errors on. This allows for things like `picom-trans -5` # as well as `picom-trans -c +5 -s` (contrived example). @@ -136,7 +131,7 @@ while test $# -gt 0; do done # clean up opacity. xargs == a poor man's trim. -opacity=$(echo "$opacity" | xargs | sed 's/%//g' | sed -E 's/^~([0-9]+)$/-\1/') +opacity=$(echo "$opacity" | xargs | sed 's/%//g') # Validate opacity value if test -z "$action" && ! echo "$opacity" | grep -qE '^[+-]?[0-9]+$'; then