]>
git.rmz.io Git - dotfiles.git/blob - zsh/plugins/perl/perl.plugin.zsh
1 # https://github.com/dbbolton
3 # Below are some useful Perl-related aliases/functions that I use with zsh.
6 # Aliases ###################################################################
9 alias pbi
='perlbrew install'
10 alias pbl
='perlbrew list'
11 alias pbo
='perlbrew off'
12 alias pbs
='perlbrew switch'
13 alias pbu
='perlbrew use'
20 # use perl like awk/sed
21 alias ple
='perl -wlne'
23 # show the latest stable release of Perl
24 alias latest
-perl='curl -s http://www.perl.org/get.html | perl -wlne '\''if (/perl\-([\d\.]+)\.tar\.gz/) { print $1; exit;}'\'
28 # Functions #################################################################
30 # newpl - creates a basic Perl script file and opens it with $EDITOR
32 # set $EDITOR to 'vim' if it is undefined
33 [[ -z $EDITOR ]] && EDITOR
=vim
35 # if the file exists, just open it
36 [[ -e $1 ]] && print
"$1 exists; not modifying.\n" && $EDITOR $1
38 # if it doesn't, make it, and open it
39 [[ ! -e $1 ]] && print
'#!/usr/bin/perl'"\n"'use strict;'"\n"'use warnings;'\
40 "\n\n" > $1 && $EDITOR $1
44 # pgs - Perl Global Substitution
45 # find pattern = 1st arg
46 # replace pattern = 2nd arg
48 pgs
() { # [find] [replace] [filename]
49 perl
-i.orig
-pe 's/'"$1"'/'"$2"'/g' "$3"
53 # Perl grep, because 'grep -P' is terrible. Lets you work with pipes or files.
54 prep
() { # [pattern] [filename unless STDOUT]
55 perl
-nle 'print if /'"$1"'/;' $2
58 # say - append a newline to 'print'