diff --git a/plugins/perl/completions/_prep b/plugins/perl/completions/_prep new file mode 100644 index 0000000..c1c939e --- /dev/null +++ b/plugins/perl/completions/_prep @@ -0,0 +1,11 @@ +#compdef prep +#autoload + +_arguments \ + '-i[ignore case]' \ + '-m[^ and $ match the start and the end of a line]' \ + '-s[. matches newline]' \ + '-x[ignore whitespace and comments]' \ + '1::pattern:' \ + '2::files:_files' && return 0 + diff --git a/plugins/perl/completions/_psub b/plugins/perl/completions/_psub new file mode 100644 index 0000000..3fa7ef8 --- /dev/null +++ b/plugins/perl/completions/_psub @@ -0,0 +1,13 @@ +#compdef psub +#autoload + +_arguments \ + '-g[match globally]' \ + '-i[ignore case]' \ + '-m[^ and $ match the start and the end of a line]' \ + '-s[. matches newline]' \ + '-x[ignore whitespace and comments]' \ + '1::pattern:' \ + '2::replacement:' \ + '3::files:_files' && return 0 + diff --git a/plugins/perl/functions/pgs b/plugins/perl/functions/pgs deleted file mode 100644 index bff559e..0000000 --- a/plugins/perl/functions/pgs +++ /dev/null @@ -1,12 +0,0 @@ -# Perl Global Substitution -if (( $# < 2 )); then - print "usage: $0 find replace [file ...]" >&2 - return 1 -fi - -local find="$1" -local replace="$2" -repeat 2 shift - -perl -i.orig -pe 's/'"$find"'/'"$replace"'/g' "$@" - diff --git a/plugins/perl/functions/prep b/plugins/perl/functions/prep index 4832629..3bc8b5a 100644 --- a/plugins/perl/functions/prep +++ b/plugins/perl/functions/prep @@ -1,11 +1,46 @@ # Perl grep since 'grep -P' is terrible. -if (( $# < 1 )) ; then - print "usage: $0 pattern [file ...]" >&2 + +local usage pattern modifiers + +usage="$( +cat <&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 return 1 fi -local pattern="$1" +pattern="$1" shift -perl -nle 'print if /'"$pattern"'/;' "$@" +perl -n -l -e "print if m/${pattern//\//\\/}/${modifiers}" "$@" diff --git a/plugins/perl/functions/psub b/plugins/perl/functions/psub new file mode 100644 index 0000000..e88d4bd --- /dev/null +++ b/plugins/perl/functions/psub @@ -0,0 +1,48 @@ +# Perl Substitution + +local usage pattern replacement modifiers + +usage="$( +cat <&2 + print "$usage" >&2 + return 1 + ;; + ([?]) + print "$0: unknown option: $OPTARG" >&2 + print "$usage" >&2 + return 1 + ;; + esac +done +shift $(( $OPTIND - 1 )) + +if (( $# < 2 )); then + print "$usage" >&2 + return 1 +fi + +pattern="$1" +replacement="$2" +repeat 2 shift + +perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@"