Skip to content

Instantly share code, notes, and snippets.

@gslin
Created March 8, 2011 04:35
Show Gist options
  • Save gslin/859850 to your computer and use it in GitHub Desktop.
Save gslin/859850 to your computer and use it in GitHub Desktop.
if [[ -f $HOME/.perlbrew/init ]]; then
source $HOME/.perlbrew/init
fi
short_option=""
__perlbrew_reinit () {
echo '# DO NOT EDIT THIS FILE' > $HOME/.perlbrew/init
command perlbrew $short_option 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
if [[ `echo $1 | awk 'BEGIN{FS=""}{print $1}'` = '-' ]]; then
short_option=$1
shift
fi
case $1 in
(use)
if [[ -x "$PERLBREW_ROOT/perls/$2/bin/perl" ]]; then
eval $(command perlbrew $short_option env $2)
__perlbrew_set_path
elif [[ "$2" = "system" ]]; then
unset PERLBREW_PERL
eval $(command perlbrew $short_option 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 $short_option off
__perlbrew_reinit
;;
(*)
command perlbrew $short_option $*
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