1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-12-02 14:15:41 -05:00

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
This commit is contained in:
Subhaditya Nath 2021-05-30 23:19:02 +05:30
parent 7ba87598c1
commit 7b4af3aef6

View file

@ -79,7 +79,7 @@ v=
# Workaround: replace '-5' with '~5' so as not to confuse getopts. # Workaround: replace '-5' with '~5' so as not to confuse getopts.
for v in "$@"; do for v in "$@"; do
shift && set -- "$@" "$(echo "$v" | sed 's/^-\([0-9]\+%\?\)$/~\1/')" shift && set -- "$@" "$(echo "$v" | sed -E 's/^-([0-9]+%?)$/~\1/')"
done done
# This takes into account the fact that getopts stops on # This takes into account the fact that getopts stops on
@ -102,7 +102,7 @@ while test $# -gt 0; do
OPTIND=$((OPTIND + 1)) OPTIND=$((OPTIND + 1))
;; ;;
name=* | window=* | opacity=*) name=* | window=* | opacity=*)
v=$(echo "$OPTARG" | sed 's/^[^=]\+=//') v=$(echo "$OPTARG" | sed -E 's/^[^=]+=//')
;; ;;
*) *)
echo "$0: illegal option $OPTARG" >& 2 echo "$0: illegal option $OPTARG" >& 2
@ -137,10 +137,10 @@ while test $# -gt 0; do
done done
# clean up opacity. xargs == a poor man's trim. # 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 # 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." echo "Invalid opacity specified: $opacity."
exit 1 exit 1
fi fi
@ -213,7 +213,7 @@ fi
# Get current opacity. # Get current opacity.
cur=$(xprop -id "$topmost" -notype _NET_WM_WINDOW_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. # Remove the opacity property.
if test x"$action" = x'delete' -o \( x"$action" = x'toggle' -a -n "$cur" \); then if test x"$action" = x'delete' -o \( x"$action" = x'toggle' -a -n "$cur" \); then