Created
December 1, 2021 14:28
-
-
Save offlinehacker/b1f0973f3442358ca39532c58485e2fb to your computer and use it in GitHub Desktop.
Devcontainer env probe
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
#!/bin/bash | |
[[ $ENVRC_RUN != yes ]] && source /etc/envrc | |
# whether running via vscode env probe | |
if shopt -q login_shell && [[ "$BASH_EXECUTION_STRING" =~ $HOME/.vscode-server/bin/.*/node ]]; then | |
old_bash_path="$(which bash)" | |
if [ ! -z "${ENV_PRINT_COMMAND}" ]; then | |
cd "${WORKSPACE_DIR}" | |
eval "$(${ENV_PRINT_COMMAND})" | |
cd - | |
elif [ -f "${WORKSPACE_DIR}/.envrc" ]; then | |
eval "$(direnv exec ${WORKSPACE_DIR} direnv dump bash)" | |
elif [ -f "${WORKSPACE_DIR}/flake.nix" ]; then | |
cd "${WORKSPACE_DIR}" | |
eval "$(nix print-dev-env)" | |
cd - | |
elif [ -f "${WORKSPACE_DIR}/shell.nix" ]; then | |
eval "$(nix print-dev-env -f ${WORKSPACE_DIR}/shell.nix)" | |
fi | |
# remove bash from path if nix shell has overriden it, | |
# we don't want dev environment to pullute our shell | |
if [ "$(which bash)" != "${old_bash_path}" ]; then | |
PATH=:$PATH: | |
PATH=${PATH//:$(dirname $(which bash)):/:} | |
PATH=${PATH#:}; PATH=${PATH%:} | |
export PATH | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment