#!/bin/sh # The MIT License (MIT) # # Copyright © 2025 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # avoid [options...] [regular expressions...] # # Avoid/ignore lines which match any of the extended-mode regular expressions # given. When not given any regex, ignore all empty lines by default. # # The options are, available both in single and double-dash versions # # -h show this help message # -help show this help message # # -i match regexes case-insensitively # -ins match regexes case-insensitively case "$1" in -h|--h|-help|--help) # show help message, using the info-comment from this very script awk '/^# +avoid /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 0 ;; esac insensitive=0 case "$1" in -i|--i|-ins|--ins) insensitive=1 shift ;; esac [ "$1" = '--' ] && shift command='awk' if [ -e /usr/bin/gawk ]; then command='/usr/bin/gawk' fi if [ -p /dev/stdout ] || [ -t 1 ]; then command="stdbuf -oL ${command}" fi ${command} -v ci="${insensitive}" ' BEGIN { if (ci && IGNORECASE == "") { msg = "this variant of AWK lacks case-insensitive regex-matching" print(msg) > "/dev/stderr" exit 125 } if (ci) IGNORECASE = 1 for (i = 1; i < ARGC; i++) { re[i] = ARGV[i] delete ARGV[i] } } { for (i = 1; i < ARGC; i++) if ($0 ~ re[i]) next print got++ } END { exit(got == 0) } ' "${@:-^\r?$}"