Sha256: ebe41d14fdf1fe3a4fd3cf98b6534dd9ed6370b0b60dc5de41991c83d443acf6

Contents?: true

Size: 1.73 KB

Versions: 23

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/env bash

# Usage: $rvm_path/scripts/environment-convertor <shell> <environment>

unset GREP_COLOR
unset GREP_OPTIONS

source "$rvm_path/scripts/base"

convert_path_to_fish()
{
  local parts path_parts

  path_part="$1"
  parts="$(echo "$path_part" | sed -e 's#:\$PATH##' -e "s#:#\" \"#g" -e "s#^export \\([^[:space:]]*\\)=##")"

  printf "\
for path_part in $parts
  if test -d $path_part
    set PATH $path_parth $PATH
  end
end
"
  return 0
}

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_path/environments/$(__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
}

args=($*)
shell_name="${args[0]}"
environment_name="${args[1]:-"$(__rvm_environment_identifier)"}"
args="$(echo ${args[@]:2}) " # Strip trailing / leading / extra spacing.

[[ -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

23 entries across 23 versions & 2 rubygems

Version Path
rvm-1.1.4 scripts/environment-convertor
rvm-1.1.3 scripts/environment-convertor
rvm-1.1.2 scripts/environment-convertor
rvm-1.1.1 scripts/environment-convertor
rvm-1.1.0 scripts/environment-convertor
rvm-1.0.23 scripts/environment-convertor
rvm-1.0.22 scripts/environment-convertor
rvm-1.0.21 scripts/environment-convertor
rvm-1.0.20 scripts/environment-convertor
rvm-1.0.19 scripts/environment-convertor
rvm-1.0.18 scripts/environment-convertor
rvm-1.0.17 scripts/environment-convertor
rvm-1.0.15 scripts/environment-convertor
gemrage-1.0.0 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.4.1 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.4.0 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.3.2 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.3.1 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.3.0 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor
gemrage-0.2.0 vendor/ruby/1.8/gems/rvm-1.0.14/scripts/environment-convertor