Sha256: 4ad7ef8db957720ca55bb1ea857a450caf0c71e9e62c5d608141cc43b8014764

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

#!/usr/bin/env bash

# Usage: $rvm_scripts_path/environment-convertor <shell> <environment>

unset GREP_COLOR
unset GREP_OPTIONS

source "$rvm_scripts_path/base"

convert_path_to_fish() {
  local path_part="$1"
  local parts="$(echo "$path_part" | sed -e 's#:\$PATH##' -e "s#:#\" \"#g" -e "s#^export \\([^[:space:]]*\\)=##")"
  echo "for path_part in $parts"
  echo '  if test -d $path_part'
  echo '    set PATH $path_parth $PATH'
  echo '  end'
  echo 'end'
}

convert_unset_to_fish() {
  sed 's#^unset #set -e #'
}

convert_exports_to_fish() {
  sed -e "s#:#' '#g" -e "s#^\\(export \\)\\{0,1\\}\\([^[:space:]]*\\)=#set -x \\2 #"
}

contents_of_environment_file() {
  cat "$rvm_environments_path/$(__rvm_environment_identifier)"
}

convert_to_shell() {
  convert_path_to_fish "$(contents_of_environment_file | grep '^export PATH=')"
  while read -r shell_line; do
    if echo "$shell_line" | grep -q '^unset '; then
      echo "$shell_line" | convert_unset_to_fish
    else
      echo "$shell_line" | convert_exports_to_fish
    fi
  done < <(contents_of_environment_file | grep -v '^export [^=]*$' | grep -v '^export PATH=')
  unset shell_line
}

ensure_has_shell() {
  for item in "path" "unset" "exports"; do
    command -v "convert_${item}_to_${1}" >/dev/null || return 1
  done; unset item
}

shell_name="$1"
environment_name="${2:-"$(__rvm_environment_identifier)"}"

[[ -n "$shell_name" && -n "$environment_name" ]] || exit 1
ensure_has_shell "$shell_name"                   || exit 1
# Check we're loading a different shell.
if [[ "$(__rvm_environment_identifier)" != "$environment_name" ]]; then
  __rvm_become "$environment_name" || exit 1
fi

convert_to_shell

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rvm-0.1.47 scripts/environment-convertor
rvm-0.1.46 scripts/environment-convertor
rvm-0.1.45 scripts/environment-convertor
rvm-0.1.44 scripts/environment-convertor