This repository has been archived on 2022-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
prezto/plugins/perl/functions/prep

47 lines
894 B
Plaintext
Raw Normal View History

2011-10-11 23:13:58 -04:00
# Perl grep since 'grep -P' is terrible.
local usage pattern modifiers
usage="$(
cat <<EOF
usage: $0 [-option ...] [--] pattern [file ...]
options:
-i ignore case
-m ^ and $ match the start and the end of a line
-s . matches newline
-x ignore whitespace and comments
EOF
)"
while getopts ':igmxe::' opt; do
case "$opt" in
(i) modifiers="${modifiers}i" ;;
(m) modifiers="${modifiers}m" ;;
(x) modifiers="${modifiers}x" ;;
(e) modifiers="${modifiers}e" ;;
(:)
print "$0: option requires an argument: $OPTARG" >&2
print "$usage" >&2
return 1
;;
([?])
print "$0: unknown option: $OPTARG" >&2
print "$usage" >&2
return 1
;;
esac
done
shift $(( $OPTIND - 1 ))
if (( $# < 1 )); then
print "$usage" >&2
2011-10-11 23:13:58 -04:00
return 1
fi
pattern="$1"
2011-10-11 23:13:58 -04:00
shift
perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@"
2011-10-11 23:13:58 -04:00