prezto_config/plugins/perl/functions/prep

47 lines
894 B
Text
Raw Normal View History

2011-10-12 05:13:58 +02: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-12 05:13:58 +02:00
return 1
fi
pattern="$1"
2011-10-12 05:13:58 +02:00
shift
perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@"
2011-10-12 05:13:58 +02:00