Created
March 29, 2011 06:07
-
-
Save lurdan/891876 to your computer and use it in GitHub Desktop.
perlbrew init file for dash
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 | |
. $HOME/.perlbrew/init | |
fi | |
short_option="" | |
__perlbrew_reinit () { | |
if [ ! -d $HOME/.perlbrew ]; then | |
mkdir -p $HOME/.perlbrew | |
fi | |
echo '# DO NOT EDIT THIS FILE' >| $HOME/.perlbrew/init | |
command perlbrew $short_option env $1 >> $HOME/.perlbrew/init | |
. $HOME/.perlbrew/init | |
__perlbrew_set_path | |
} | |
__perlbrew_set_path () { | |
[ -z "$PERLBREW_ROOT" ] && return 1 | |
hash -d perl 2>/dev/null | |
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 | |
export SHELL | |
if [ "`echo $1 | awk 'BEGIN{FS=\"\"}{print $1}'`" = '-' ]; then | |
short_option=$1 | |
shift | |
fi | |
case $1 in | |
(use) | |
if [ -z "$2" ] ; then | |
if [ -z "$PERLBREW_PERL" ] ; then | |
echo "No version in use; defaulting to system" | |
else | |
echo "Using $PERLBREW_PERL version" | |
fi | |
elif [ -x "$PERLBREW_ROOT/perls/$2/bin/perl" || "$2" = "system" ]; then | |
unset PERLBREW_PERL | |
eval $(command perlbrew $short_option env $2) | |
__perlbrew_set_path | |
else | |
echo "$2 is not installed" >&2 | |
exit_status=1 | |
fi | |
;; | |
(switch) | |
command perlbrew $short_option $* | |
exit_status=$? | |
if [ -n "$2" ] ; then | |
__perlbrew_reinit | |
fi | |
;; | |
(off) | |
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