]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/perl/perl.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / perl / perl.plugin.zsh
1 # https://github.com/dbbolton
2 #
3 # Below are some useful Perl-related aliases/functions that I use with zsh.
4
5
6 # Aliases ###################################################################
7
8 # perlbrew ########
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'
14
15 # Perl ############
16
17 # perldoc`
18 alias pd='perldoc'
19
20 # use perl like awk/sed
21 alias ple='perl -wlne'
22
23 # show the latest stable release of Perl
24 alias latest-perl='curl -s https://www.perl.org/get.html | perl -wlne '\''if (/perl\-([\d\.]+)\.tar\.gz/) { print $1; exit;}'\'
25
26
27
28 # Functions #################################################################
29
30 # newpl - creates a basic Perl script file and opens it with $EDITOR
31 newpl () {
32         # set $EDITOR to 'vim' if it is undefined
33         [[ -z $EDITOR ]] && EDITOR=vim
34
35         # if the file exists, just open it
36         [[ -e $1 ]] && print "$1 exists; not modifying.\n" && $EDITOR $1
37
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
41 }
42
43
44 # pgs - Perl Global Substitution
45 # find pattern          = 1st arg
46 # replace pattern       = 2nd arg
47 # filename                      = 3rd arg
48 pgs() { # [find] [replace] [filename]
49     perl -i.orig -pe 's/'"$1"'/'"$2"'/g' "$3"
50 }
51
52
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
56 }