From 53ce3026359dc0e881cef8aadfdfdae86e910b51 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 13 Dec 2022 00:40:34 +0100 Subject: [PATCH] bin/nb-php-grep-unique.sh --- bin/nb-php-grep-unique.sh | 94 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/bin/nb-php-grep-unique.sh b/bin/nb-php-grep-unique.sh index aef65707..7c322115 100755 --- a/bin/nb-php-grep-unique.sh +++ b/bin/nb-php-grep-unique.sh @@ -8,7 +8,97 @@ set -o errexit declare -r NAME="$(basename "${0}")" -#declare -r DIR_NAME="$(cd "$(dirname "${0}")"; echo $(pwd))" +################################################################################ +# +# Default value options +# +################################################################################# +VERBOSE=0 +DEBUG=0 + +################################################################################ +# +# Functions +# +################################################################################# +usage() { +echo " +=head1 NAME + +${NAME} + +=head1 SYNOPSIS + +Example shell script with embedded POD documentation + + -v, --verbose Print verbose mode + -d, --debug Print debug messages + -h, --help Print this help (alternatives: --man, --help2man) + +=head1 DESCRIPTION + +Long description + +=head1 SEE ALSO + +http://blog.nbdom.net/ + +=head1 LICENSE + +Copyright (C) 2022 Nicolas Boisselier + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +See . + +=head1 AUTHOR + +Nicolas Boisselier +" +} + +################################################################################# +# +# Args +# +################################################################################# +ARGS="" +ALL=0 +UNIQ=0 +while [ $# -gt 0 ]; do + + case "$1" in + + --all) ALL=1 ;; + --uniq) UNIQ=1 ;; + + -*help|-h) usage | pod2text --width 250; exit 0 ;; + --man) usage | pod2man | man -l -; exit 0 ;; + --help2man) usage | pod2man; exit 0 ;; + + --verbose|-v) VERBOSE=$(($VERBOSE+1)) ;; + + --debug|-d) DEBUG=$(($DEBUG+1)) ;; + + *) ARGS="$ARGS " + + esac + shift + +done + +################################################################################# +# +# Main +# +################################################################################# cd "$(dirname "$0")"/.. -pcregrep ${@:-'-h'} -o1 '(?:[:>]p(?:def)?\(.([\w-]+))' $(git ls-files | grep '\.php$') | sort | uniq -c +[ "$ALL" = 1 ] && ARGS="$ARGS $(git ls-files | grep '\.php$')" + +EXP='(?:[:>]p(?:def)?\(["'"'"']([\w-]+))' +if [ "$UNIQ" = 1 ]; then + pcregrep -h -o1 "$EXP" $ARGS | sort | uniq -c +else + pcregrep -n -H -o1 "$EXP" $ARGS +fi -- 2.47.3