Created
January 29, 2011 06:16
-
-
Save dalinaum/801590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ -f $HOME/.perlbrew/init ]]; then | |
source $HOME/.perlbrew/init | |
fi | |
__perlbrew_reinit () { | |
echo '# DO NOT EDIT THIS FILE' > $HOME/.perlbrew/init | |
command perlbrew env $1 >> $HOME/.perlbrew/init | |
source $HOME/.perlbrew/init | |
__perlbrew_set_path | |
} | |
__perlbrew_set_path () { | |
[[ -z "$PERLBREW_ROOT" ]] && return 1 | |
export PATH_WITHOUT_PERLBREW=$(perl -e 'print join ":", grep { index($_, $ENV{PERLBREW_ROOT}) } split/:/,$ENV{PATH};') | |
export PATH=$PERLBREW_PATH:$PATH_WITHOUT_PERLBREW | |
} | |
__perlbrew_set_path | |
perlbrew () { | |
local exit_status | |
case $1 in | |
(use) | |
if [[ -x "$PERLBREW_ROOT/perls/$2/bin/perl" ]]; then | |
eval $(command perlbrew env $2) | |
__perlbrew_set_path | |
elif [[ "$2" = "system" ]]; then | |
unset PERLBREW_PERL | |
eval $(command perlbrew env) | |
__perlbrew_set_path | |
else | |
echo "$2 is not installed" >&2 | |
exit_status=1 | |
fi | |
;; | |
(switch) | |
if [[ ! -d $HOME/.perlbrew ]]; then | |
mkdir -p $HOME/.perlbrew | |
fi | |
if [[ -x "$PERLBREW_ROOT/perls/$2/bin/perl" ]]; then | |
__perlbrew_reinit $2 | |
elif [[ "$2" = "system" ]]; then | |
perlbrew off | |
return $? | |
else | |
echo "$2 is not installed" >&2 | |
exit_status=1 | |
fi | |
;; | |
(off) | |
if [[ ! -d $HOME/.perlbrew ]]; then | |
mkdir -p $HOME/.perlbrew | |
fi | |
unset PERLBREW_PERL | |
command perlbrew off | |
__perlbrew_reinit | |
;; | |
(*) | |
command perlbrew $* | |
exit_status=$? | |
;; | |
esac | |
hash -r | |
return ${exit_status:-0} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment