1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 23:08:00 +00:00
prezto/plugins/perl/functions/prep

47 lines
894 B
Plaintext
Raw Normal View History

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