Files
2026-09-24 23:54:13 +02:00

29 lines
1.2 KiB
Bash

# CLion toolchain environment file: Settings > Build, Execution, Deployment >
# Toolchains > Add environment > From file. CLion sources it before CMake,
# builds, runs and debugging, so all of them see the nix devShell.
#
# The direnv plugin cannot do this on its own: it only writes variables into
# Run/Debug configurations, and a CMake reload is not one.
#
# direnv searches upward for .envrc, so export from this file's directory
# instead of relying on whatever working directory CLion sources it from.
# CLion sources through the user's login shell ($SHELL -l -i -c), which
# shapes the rest:
# - The file's own path has to be found in zsh as well as bash. The zsh
# spelling sits inside eval so other shells never parse it.
# - No shell `cd`. An interactive zsh carries direnv's chpwd hook, which
# loads the env inside the cd subshell and leaves `direnv export` with
# nothing to print. `env -C` changes directory in the child instead.
if [ -n "${BASH_SOURCE:-}" ]; then
_sd_self=$BASH_SOURCE
elif [ -n "${ZSH_VERSION:-}" ]; then
eval '_sd_self=${(%):-%x}'
fi
if [ -n "${_sd_self:-}" ]; then
eval "$(env -C "$(dirname "$_sd_self")" direnv export bash)"
else
eval "$(direnv export bash)"
fi
unset _sd_self