aspnet / dnvm

OBSOLETE - see readme
Other
174 stars 61 forks source link

dnvm is polluting environment variables? #508

Closed mikebz closed 6 years ago

mikebz commented 8 years ago

I found this by issuing my set command. Somehow I am getting a whole bunch of functions outputting after the SET? (this is a portion of the output).

How do I clean it up?

_DNVM_VERSION_MANAGER_NAME='.NET Version Manager'
__CF_USER_TEXT_ENCODING=0x4FD6E7:0x0:0x0
__dnvm_file=/Users/mike.borozdin/.dnx/alias/default.alias
f=dnx-mono.1.0.0-beta6
__dnvm_current_os () 
{ 
    local uname=$(uname);
    if [[ $uname == "Darwin" ]]; then
        echo "darwin";
    else
        echo "linux";
    fi
}
__dnvm_description () 
{ 
    __echo_art;
    echo "";
    echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER";
    [[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS";
    echo "";
    echo "DNVM can be used to download versions of the $_DNVM_RUNTIME_FRIENDLY_NAME and manage which version you are using.";
    echo "You can control the URL of the stable and unstable channel by setting the DNX_FEED and DNX_UNSTABLE_FEED variables.";
    echo "";
    printf "%b\n" "${Yel}Current feed settings:${RCol}";
    printf "%b\n" "${Cya}Default Stable:${Yel} $_DNVM_DEFAULT_FEED";
    printf "%b\n" "${Cya}Default Unstable:${Yel} $_DNVM_DEFAULT_UNSTABLE_FEED";
    local dnxStableOverride="<none>";
    [[ -n $DNX_FEED ]] && dnxStableOverride="$DNX_FEED";
    printf "%b\n" "${Cya}Current Stable Override:${Yel} $dnxStableOverride";
    local dnxUnstableOverride="<none>";
    [[ -n $DNX_UNSTABLE_FEED ]] && dnxUnstableOverride="$DNX_UNSTABLE_FEED";
    printf "%b\n" "${Cya}Current Unstable Override:${Yel} $dnxUnstableOverride${RCol}";
    echo ""
}
__dnvm_download () 
{ 
    local runtimeFullName="$1";
    local downloadUrl="$2";
    local runtimeFolder="$3";
    local force="$4";
    local pkgName=$(__dnvm_package_name "$runtimeFullName");
    local pkgVersion=$(__dnvm_package_version "$runtimeFullName");
    local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg";
    if [ -n "$force" ]; then
        printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}";
        rm -rf "$runtimeFolder";
    fi;
    if [ -e "$runtimeFolder" ]; then
        printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}";
        return 0;
    fi;
    if ! __dnvm_has "curl"; then
        printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" 1>&2;
        return 1;
    fi;
    mkdir -p "$runtimeFolder" > /dev/null 2>&1;
    echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED";
    echo "Download: $downloadUrl";
    local httpResult=$(curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/");
    if [[ $httpResult == "404" ]]; then
        printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}";
        printf "%b\n" "${Cya}This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $_DNVM_RUNTIME_SHORT_NAME of the right name format or some other error caused a 404 on the server.${RCol}";
        return 1;
    fi;
    [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1;
    __dnvm_unpack $runtimeFile $runtimeFolder;
    return $?
}
__dnvm_find_latest () 
{ 
    local platform=$1;
    local arch=$2;
    local os=$3;
    if ! __dnvm_has "curl"; then
        printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" 1>&2;
        return 1;
    fi;
    if [[ $platform == "mono" ]]; then
        local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform";
    else
        local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch";
    fi;
    local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false";
    __dnvm_query_feed $url;
    return $?
}
__dnvm_find_package () 
{ 
    local platform=$1;
    local arch=$2;
    local os=$3;
    local version=$4;
    if [[ $platform == "mono" ]]; then
        local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform";
    else
        local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch";
    fi;
    local url="$DNX_ACTIVE_FEED/Packages()?\$filter=Id%20eq%27$packageId%27%20and%20Version%20eq%20%27$version%27";
    __dnvm_query_feed $url;
    return $?
}
__dnvm_has () 
{ 
    type "$1" > /dev/null 2>&1;
    return $?
}
__dnvm_help () 
{ 
    __dnvm_description;
    printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME <command> [options] ${RCol}";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] ${RCol}";
    echo "  install latest $_DNVM_RUNTIME_SHORT_NAME from feed";
    echo "  adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line";
    echo "  set installed version as default";
    echo "  -f|forces         force upgrade. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed";
    echo "  -u|unstable       use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable unstable feed";
    echo "  -r|runtime        The runtime flavor to install [clr or coreclr] (default: clr)";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-r <runtime>] [-OS <OS>] [-a|-alias <alias>] [-p|-persistent] [-f|-force] [-u|-unstable] ${RCol}";
    echo "  <semver>|<alias>  install requested $_DNVM_RUNTIME_SHORT_NAME from feed";
    echo "  <nupkg>           install requested $_DNVM_RUNTIME_SHORT_NAME from local package on filesystem";
    echo "  latest            install latest version of $_DNVM_RUNTIME_SHORT_NAME from feed";
    echo "  -OS               the operating system that the runtime targets (default:$(__dnvm_current_os)";
    echo "  -a|-alias <alias> set alias <alias> for requested $_DNVM_RUNTIME_SHORT_NAME on install";
    echo "  -p|-persistent    set installed version as default";
    echo "  -f|force          force install. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed";
    echo "  -u|unstable       use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable unstable feed";
    echo "  -r|runtime        The runtime flavor to install [mono or coreclr] (default: mono)";
    echo "";
    echo "  adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p|-persistent] [-r|-runtime <runtime>] [-a|-arch <architecture>] ${RCol}";
    echo "  <semver>|<alias>|<package>  add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line   ";
    echo "  none                        remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line";
    echo "  -p|-persistent              set selected version as default";
    echo "  -r|-runtime                 runtime to use (mono, coreclr)";
    echo "  -a|-arch                    architecture to use (x64)";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME run <semver>|<alias> <args...> ${RCol}";
    echo "  <semver>|<alias>            the version or alias to run";
    echo "  <args...>                   arguments to be passed to $_DNVM_RUNTIME_SHORT_NAME";
    echo "";
    echo "  runs the $_DNVM_RUNTIME_SHORT_NAME command from the specified version of the runtime without affecting the current PATH";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME exec <semver>|<alias> <command> <args...> ${RCol}";
    echo "  <semver>|<alias>            the version or alias to execute in";
    echo "  <command>                   the command to run";
    echo "  <args...>                   arguments to be passed to the command";
    echo "";
    echo "  runs the specified command in the context of the specified version of the runtime without affecting the current PATH";
    echo "  example: $_DNVM_COMMAND_NAME exec 1.0.0-beta4 $_DNVM_PACKAGE_MANAGER_NAME build";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list [-detailed]${RCol}";
    echo "  -detailed                   display more detailed information on each runtime";
    echo "";
    echo "  list $_DNVM_RUNTIME_SHORT_NAME versions installed ";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}";
    echo "  list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> ${RCol}";
    echo "  display value of the specified alias";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> <semver>|<alias>|<package> ${RCol}";
    echo "  <alias>                      the name of the alias to set";
    echo "  <semver>|<alias>|<package>   the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME unalias <alias> ${RCol}";
    echo "  remove the specified alias";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol}";
    echo "  displays this help text.";
    echo "";
    printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}";
    echo "  updates dnvm itself."
}
__dnvm_locate_runtime_bin_from_full_name () 
{ 
    local runtimeFullName=$1;
    [ -e "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" && return
}
__dnvm_os_runtime_defaults () 
{ 
    local os=$1;
    if [[ $os == "win" ]]; then
        echo "clr";
    else
        if [[ $os == "linux" ]]; then
            echo "mono";
        else
            if [[ $os == "darwin" ]]; then
                echo "mono";
            else
                echo "unknown os";
            fi;
        fi;
    fi
}
__dnvm_package_arch () 
{ 
    local runtimeFullName="$1";
    if [[ "$runtimeFullName" =~ $_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-[^-.]*-[^-.]*\..* ]]; then
        echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-[^-.]*-\([^-.]*\)\..*/\1/";
    fi
}
__dnvm_package_name () 
{ 
    local runtimeFullName="$1";
    echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/"
}
__dnvm_package_os () 
{ 
    local runtimeFullName="$1";
    if [[ "$runtimeFullName" =~ "mono" ]]; then
        echo "linux/darwin";
    else
        echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-\([^.-]*\).*/\1/";
    fi
}
__dnvm_package_runtime () 
{ 
    local runtimeFullName="$1";
    echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/"
}
__dnvm_package_version () 
{ 
    local runtimeFullName="$1";
    echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/"
}
__dnvm_prepend_path () 
{ 
    if [ -z "$1" ]; then
        echo "$2";
    else
        echo "$2:$1";
    fi
}
__dnvm_query_feed () 
{ 
    local url=$1;
    xml="$(curl $url 2>/dev/null)";
    echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1;
    version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')";
    downloadUrl="$(echo $xml | sed 's/.*<content.*src="\([^"]*\).*/\1/')";
    echo $version $downloadUrl
}
__dnvm_requested_version_or_alias () 
{ 
    local versionOrAlias="$1";
    local runtime="$2";
    local arch="$3";
    local os="$4";
    local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias");
    if [ -n "$runtimeBin" ]; then
        echo "$versionOrAlias";
    else
        if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
            local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias");
            echo "$runtimeFullName";
        else
            local pkgVersion=$versionOrAlias;
            local pkgArchitecture="x64";
            local pkgSystem=$os;
            if [[ -z $runtime || "$runtime" == "mono" ]]; then
                echo "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$pkgVersion";
            else
                if [ "$arch" != "" ]; then
                    local pkgArchitecture="$arch";
                fi;
                echo "$_DNVM_RUNTIME_PACKAGE_NAME-$runtime-$pkgSystem-$pkgArchitecture.$pkgVersion";
            fi;
        fi;
    fi
}
__dnvm_runtime_bitness_defaults () 
{ 
    local runtime=$1;
    if [[ $runtime == "clr" ]]; then
        echo "x86";
    else
        if [[ $runtime == "coreclr" ]]; then
            echo "x64";
        else
            echo "unknown runtime";
        fi;
    fi
}
__dnvm_strip_path () 
{ 
    echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g"
}
__dnvm_unpack () 
{ 
    local runtimeFile="$1";
    local runtimeFolder="$2";
    echo "Installing to $runtimeFolder";
    if ! __dnvm_has "unzip"; then
        echo "$_DNVM_COMMAND_NAME needs unzip to proceed." 1>&2;
        return 1;
    fi;
    unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1;
    [ -e "$runtimeFolder/[Content_Types].xml" ] && rm "$runtimeFolder/[Content_Types].xml";
    [ -e "$runtimeFolder/_rels/" ] && rm -rf "$runtimeFolder/_rels/";
    [ -e "$runtimeFolder/package/" ] && rm -rf "$runtimeFolder/_package/";
    [ -e "$runtimeFile" ] && rm -f "$runtimeFile";
    if [[ -s "$runtimeFolder/bin/dnx" ]]; then
        chmod 775 "$runtimeFolder/bin/dnx";
    fi;
    if [[ -s "$runtimeFolder/bin/dnu" ]]; then
        chmod 775 "$runtimeFolder/bin/dnu";
    fi
}
__dnvm_update_self () 
{ 
    local dnvmFileLocation="$_DNVM_DNVM_DIR/dnvm.sh";
    if [ ! -e $dnvmFileLocation ]; then
        local formattedDnvmFileLocation=`(echo $dnvmFileLocation | sed s=$HOME=~=g)`;
        local formattedDnvmHome=`(echo $_DNVM_DNVM_DIR | sed s=$HOME=~=g)`;
        printf "%b\n" "${Red}$formattedDnvmFileLocation doesn't exist. This command assumes you have installed dnvm in the usual location and are trying to update it. If you want to use update-self then dnvm.sh should be sourced from $formattedDnvmHome ${RCol}";
        return 1;
    fi;
    printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}";
    local httpResult=$(curl -L -D - "$_DNVM_UPDATE_LOCATION" -o "$dnvmFileLocation" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/");
    [[ $httpResult == "404" ]] && printf "%b\n" "${Red}404. Unable to download DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1;
    [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1;
    source "$dnvmFileLocation"
}
__echo_art () 
{ 
    printf "%b" "${Cya}";
    echo "    ___  _  ___   ____  ___";
    echo "   / _ \/ |/ / | / /  |/  /";
    echo "  / // /    /| |/ / /|_/ / ";
    echo " /____/_/|_/ |___/_/  /_/  ";
    printf "%b" "${RCol}"
}
code () 
{ 
    VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
dnvm () 
{ 
    if [ $# -lt 1 ]; then
        __dnvm_description;
        printf "%b\n" "Use ${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol} to display help text.";
        echo "";
        return;
    fi;
    case $1 in 
        "help" | "-h" | "-help" | "--help")
            __dnvm_help
        ;;
        "update-self")
            __dnvm_update_self
        ;;
        "upgrade")
            shift;
            $_DNVM_COMMAND_NAME install latest -p $@
        ;;
        "install")
            [ $# -lt 2 ] && __dnvm_help && return;
            shift;
            local persistent=;
            local versionOrAlias=;
            local alias=;
            local force=;
            local unstable=;
            local os=;
            local runtime=;
            local arch=;
            while [ $# -ne 0 ]; do
                if [[ $1 == "-p" || $1 == "-persistent" ]]; then
                    local persistent="-p";
                else
                    if [[ $1 == "-a" || $1 == "-alias" ]]; then
                        local alias=$2;
                        shift;
                    else
                        if [[ $1 == "-f" || $1 == "-force" ]]; then
                            local force="-f";
                        else
                            if [[ $1 == "-u" || $1 == "-unstable" ]]; then
                                local unstable="-u";
                            else
                                if [[ $1 == "-r" || $1 == "-runtime" ]]; then
                                    local runtime=$2;
                                    shift;
                                else
                                    if [[ $1 == "-OS" ]]; then
                                        local os=$2;
                                        shift;
                                    else
                                        if [[ $1 == "-arch" ]]; then
                                            local arch=$2;
                                            shift;
                                            if [[ $arch != "x86" && $arch != "x64" ]]; then
                                                printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}";
                                                return 1;
                                            fi;
                                        else
                                            if [[ -n $1 ]]; then
                                                [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1;
                                                local versionOrAlias=$1;
                                            fi;
                                        fi;
                                    fi;
                                fi;
                            fi;
                        fi;
                    fi;
                fi;
                shift;
            done;
            if [[ $arch == "x86" && $runtime == "coreclr" && $os != "win" ]]; then
                printf "%b\n" "${Red}Core CLR doesn't currently have a 32 bit build. You must use x64.${RCol}";
                return 1;
            fi;
            if [ -z $unstable ]; then
                DNX_ACTIVE_FEED="$DNX_FEED";
                if [ -z "$DNX_ACTIVE_FEED" ]; then
                    DNX_ACTIVE_FEED="$_DNVM_DEFAULT_FEED";
                else
                    printf "%b\n" "${Yel}Default stable feed ($_DNVM_DEFAULT_FEED) is being overridden by the value of the DNX_FEED variable ($DNX_FEED). ${RCol}";
                fi;
            else
                DNX_ACTIVE_FEED="$DNX_UNSTABLE_FEED";
                if [ -z "$DNX_ACTIVE_FEED" ]; then
                    DNX_ACTIVE_FEED="$_DNVM_DEFAULT_UNSTABLE_FEED";
                else
                    printf "%b\n" "${Yel}Default unstable feed ($_DNVM_DEFAULT_UNSTABLE_FEED) is being overridden by the value of the DNX_UNSTABLE_FEED variable ($DNX_UNSTABLE_FEED). ${RCol}";
                fi;
            fi;
            if [[ -z $os ]]; then
                os=$(__dnvm_current_os);
            fi;
            if [[ $os == "osx" ]]; then
                os="darwin";
            fi;
            if [[ -z $runtime ]]; then
                runtime=$(__dnvm_os_runtime_defaults "$os");
            fi;
            if [[ -z $arch ]]; then
                arch=$(__dnvm_runtime_bitness_defaults "$runtime");
            fi;
            if [[ $runtime == "mono" ]] && ! __dnvm_has "mono"; then
                printf "%b\n" "${Yel}It appears you don't have Mono available. Remember to get Mono before trying to run $DNVM_RUNTIME_SHORT_NAME application. ${RCol}" 1>&2;
            fi;
            if [[ "$versionOrAlias" != *.nupkg ]]; then
                if [[ "$versionOrAlias" == "latest" ]]; then
                    echo "Determining latest version";
                    read versionOrAlias downloadUrl < <(__dnvm_find_latest "$runtime" "$arch" "$os");
                    [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1;
                    printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}";
                else
                    local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os");
                    local runtimeVersion=$(__dnvm_package_version "$runtimeFullName");
                    read versionOrAlias downloadUrl < <(__dnvm_find_package "$runtime" "$arch" "$os" "$runtimeVersion");
                    [[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1;
                fi;
                local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os");
                local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName";
                __dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$force";
                [[ $? == 1 ]] && return 1;
                if [[ "$os" == $(__dnvm_current_os) ]]; then
                    $_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch";
                    [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias";
                fi;
            else
                local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/");
                local runtimeVersion=$(__dnvm_package_version "$runtimeFullName");
                local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName";
                local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg";
                local runtimeClr=$(__dnvm_package_runtime "$runtimeFullName");
                if [ -n "$force" ]; then
                    printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}";
                    rm -rf "$runtimeFolder";
                fi;
                if [ -e "$runtimeFolder" ]; then
                    echo "$runtimeFullName already installed";
                else
                    mkdir -p "$runtimeFolder" > /dev/null 2>&1;
                    cp -a "$versionOrAlias" "$runtimeFile";
                    __dnvm_unpack "$runtimeFile" "$runtimeFolder";
                    [[ $? == 1 ]] && return 1;
                fi;
                $_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr";
                [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion";
            fi
        ;;
        "use" | "run" | "exec")
            [[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return;
            local cmd=$1;
            local persistent=;
            local arch=;
            local runtime=;
            shift;
            if [ $cmd == "use" ]; then
                local versionOrAlias=;
                while [ $# -ne 0 ]; do
                    if [[ $1 == "-p" || $1 == "-persistent" ]]; then
                        local persistent="true";
                    else
                        if [[ $1 == "-a" || $1 == "-arch" ]]; then
                            local arch=$2;
                            shift;
                        else
                            if [[ $1 == "-r" || $1 == "-runtime" ]]; then
                                local runtime=$2;
                                shift;
                            else
                                if [[ $1 == -* ]]; then
                                    echo "Invalid option $1" && __dnvm_help && return 1;
                                else
                                    if [[ -n $1 ]]; then
                                        [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1;
                                        local versionOrAlias=$1;
                                    fi;
                                fi;
                            fi;
                        fi;
                    fi;
                    shift;
                done;
            else
                local versionOrAlias=$1;
                shift;
            fi;
            if [[ $cmd == "use" && $versionOrAlias == "none" ]]; then
                echo "Removing $_DNVM_RUNTIME_SHORT_NAME from process PATH";
                PATH=$(__dnvm_strip_path "$PATH" "/bin");
                if [[ -n $persistent && -e "$_DNVM_ALIAS_DIR/default.alias" ]]; then
                    echo "Setting default $_DNVM_RUNTIME_SHORT_NAME to none";
                    rm "$_DNVM_ALIAS_DIR/default.alias";
                fi;
                return 0;
            fi;
            local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$(__dnvm_current_os)");
            local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName");
            if [[ -z $runtimeBin ]]; then
                echo "Cannot find $runtimeFullName, do you need to run '$_DNVM_COMMAND_NAME install $versionOrAlias'?";
                return 1;
            fi;
            case $cmd in 
                "run")
                    local hostpath="$runtimeBin/dnx";
                    if [[ -e $hostpath ]]; then
                        $hostpath $@;
                    else
                        echo "Cannot find $_DNVM_RUNTIME_SHORT_NAME in $runtimeBin. It may have been corrupted. Use '$_DNVM_COMMAND_NAME install $versionOrAlias -f' to attempt to reinstall it";
                    fi
                ;;
                "exec")
                    ( PATH=$(__dnvm_strip_path "$PATH" "/bin");
                    PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin");
                    $@ )
                ;;
                "use")
                    echo "Adding" $runtimeBin "to process PATH";
                    PATH=$(__dnvm_strip_path "$PATH" "/bin");
                    PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin");
                    if [[ -n $persistent ]]; then
                        local runtimeVersion=$(__dnvm_package_version "$runtimeFullName");
                        $_DNVM_COMMAND_NAME alias default "$runtimeVersion";
                    fi
                ;;
            esac
        ;;
        "alias")
            [[ $# -gt 7 ]] && __dnvm_help && return;
            [[ ! -e "$_DNVM_ALIAS_DIR/" ]] && mkdir "$_DNVM_ALIAS_DIR/" > /dev/null;
            if [[ $# == 1 ]]; then
                echo "";
                local format="%-25s %s\n";
                printf "$format" "Alias" "Name";
                printf "$format" "-----" "----";
                if [ -d "$_DNVM_ALIAS_DIR" ]; then
                    for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias);
                    do
                        local alias="$(basename $__dnvm_file | sed 's/\.alias//')";
                        local name="$(cat $__dnvm_file)";
                        printf "$format" "$alias" "$name";
                    done;
                fi;
                echo "";
                return;
            fi;
            shift;
            local name="$1";
            if [[ $# == 1 ]]; then
                [[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return;
                cat "$_DNVM_ALIAS_DIR/$name.alias";
                echo "";
                return;
            fi;
            shift;
            local versionOrAlias="$1";
            shift;
            while [ $# -ne 0 ]; do
                if [[ $1 == "-a" || $1 == "-arch" ]]; then
                    local arch=$2;
                    shift;
                else
                    if [[ $1 == "-r" || $1 == "-runtime" ]]; then
                        local runtime=$2;
                        shift;
                    else
                        if [[ $1 == "-OS" ]]; then
                            local os=$2;
                            shift;
                        fi;
                    fi;
                fi;
                shift;
            done;
            local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os");
            [[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1;
            local action="Setting";
            [[ -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && action="Updating";
            echo "$action alias '$name' to '$runtimeFullName'";
            echo "$runtimeFullName" > "$_DNVM_ALIAS_DIR/$name.alias"
        ;;
        "unalias")
            [[ $# -ne 2 ]] && __dnvm_help && return;
            local name=$2;
            local aliasPath="$_DNVM_ALIAS_DIR/$name.alias";
            [[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1;
            echo "Removing alias $name";
            rm "$aliasPath" >> /dev/null 2>&1
        ;;
        "list")
            [[ $# -gt 2 ]] && __dnvm_help && return;
            [[ ! -d $_DNVM_USER_PACKAGES ]] && echo "$_DNVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1;
            local searchGlob="$_DNVM_RUNTIME_PACKAGE_NAME-*";
            echo "";
            local arr;
            arr=();
            local i=1;
            local format="%-20s %s\n";
            if [ -d "$_DNVM_ALIAS_DIR" ]; then
                for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias);
                do
                    arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)";
                    let i+=1;
                done;
            fi;
            if [[ $2 == "-detailed" ]]; then
                local formatString="%-6s %-20s %-7s %-4s %-15s %-20s %s\n";
                printf "$formatString" "Active" "Version" "Runtime" "Arch" "OperatingSystem" "Location" "Alias";
                printf "$formatString" "------" "-------" "-------" "----" "---------------" "--------" "-----";
            else
                local formatString="%-6s %-20s %-7s %-4s %-15s %s\n";
                printf "$formatString" "Active" "Version" "Runtime" "Arch" "OperatingSystem" "Alias";
                printf "$formatString" "------" "-------" "-------" "----" "---------------" "-----";
            fi;
            local formattedHome=`(echo $_DNVM_USER_PACKAGES | sed s=$HOME=~=g)`;
            for f in $(find $_DNVM_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;);
            do
                local active="";
                [[ $PATH == *"$_DNVM_USER_PACKAGES/$f/bin"* ]] && local active="  *";
                local pkgRuntime=$(__dnvm_package_runtime "$f");
                local pkgName=$(__dnvm_package_name "$f");
                local pkgVersion=$(__dnvm_package_version "$f");
                local pkgArch=$(__dnvm_package_arch "$f");
                local pkgOs=$(__dnvm_package_os "$f");
                local alias="";
                local delim="";
                for i in "${arr[@]}";
                do
                    if [[ ${i#*/} == "$pkgName.$pkgVersion" ]]; then
                        alias+="$delim${i%/*}";
                        delim=", ";
                    fi;
                done;
                if [[ $2 == "-detailed" ]]; then
                    printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$formattedHome" "$alias";
                else
                    printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$alias";
                fi;
            done;
            echo ""
        ;;
        *)
            echo "Unknown command $1";
            return 1
        ;;
    esac;
    return 0
}
update_terminal_cwd () 
{ 
    local SEARCH=' ';
    local REPLACE='%20';
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}";
    printf '\e]7;%s\a' "$PWD_URL"
}
muratg commented 8 years ago

DNVM/DNX/DNU are being retired in RC2, so no more work is planned.

mikebz commented 8 years ago

that's cool, except that I can't figure out how to remove all the stuff that was injected into my environment :) I ran dnvm uninstall 1.0.0-beta6 and the set stuff is still there.

muratg commented 8 years ago

Find where dnvm is sourced :) probably in your .bashrc or .zshrc, there's a line that sources dnvm. Remove that line. :)

murats-mbp% cat .zshrc | grep source
source ~/.dnx/dnvm/dnvm.sh