Created
April 22, 2012 20:31
-
-
Save dragan/2466702 to your computer and use it in GitHub Desktop.
Set environment for shell command
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e | |
[ -n "$MOPE_DEBUG" ] && set -x | |
# Provide mope completions | |
if [ "$1" = "--complete" ]; then | |
echo --unset | |
echo system | |
exec mope-versions --bare | |
fi | |
version="$1" | |
if [ -z "$version" ]; then | |
if [ -z "$MOPE_VERSION" ]; then | |
echo "mope: no shell-specific version configured" >&2 | |
exit 1 | |
else | |
echo "echo \"\$MOPE_VERSION\"" | |
exit | |
fi | |
fi | |
if [ "$version" = "--unset" ]; then | |
# set environment back | |
echo "unset MOPE_VERSION" | |
if [ -n "$DYLD_FALLBACK_LIBRARY_PATH" ]; then | |
echo "unset DYLD_FALLBACK_LIBRARY_PATH" | |
fi | |
if [ -n "$C_INCLUDE_PATH" ]; then | |
echo "unset C_INCLUDE_PATH" | |
fi | |
if [ -n "$ACLOCAL_PATH" ]; then | |
echo "unset ACLOCAL_PATH" | |
fi | |
if [ -n "$PKG_CONFIG_PATH" ]; then | |
echo "unset PKG_CONFIG_PATH" | |
fi | |
MOPE_VERSION_FILE="$(mope-version-file)" | |
MOPE_VERSION="$(mope-version-file-read "$MOPE_VERSION_FILE" || true)" | |
if [ -n "$MOPE_VERSION" ] && [ ! "$MOPE_VERSION" = "system" ]; then | |
MONO_PREFIX="${MOPE_ROOT}/versions/${MOPE_VERSION}" | |
echo "export DYLD_FALLBACK_LIBRARY_PATH=\"${MONO_PREFIX}/lib\"" | |
echo "export C_INCLUDE_PATH=\"${MONO_PREFIX}/include\"" | |
echo "export ACLOCAL_PATH=\"${MONO_PREFIX}/share/aclocal\"" | |
echo "export PKG_CONFIG_PATH=\"${MONO_PREFIX}/lib/pkgconfig\"" | |
exit | |
fi | |
exit 1 | |
fi | |
# Make sure the specified version is installed. | |
mope-prefix "$version" >/dev/null | |
MONO_PREFIX="${MOPE_ROOT}/versions/${version}" | |
# Export environment variables | |
echo "export MOPE_VERSION=\"${version}\"" | |
echo "export DYLD_FALLBACK_LIBRARY_PATH=\"${MONO_PREFIX}/lib\"" | |
echo "export C_INCLUDE_PATH=\"${MONO_PREFIX}/include\"" | |
echo "export ACLOCAL_PATH=\"${MONO_PREFIX}/share/aclocal\"" | |
echo "export PKG_CONFIG_PATH=\"${MONO_PREFIX}/lib/pkgconfig\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment