esc
esc copied to clipboard
fix: env run interactive should exec
This behavior is closer to what I would expect the command to do, and doesn't leave pulumi or the esc CLI running after starting the interactive process. Reduces memory usage and allows this to replace the current shell with one that has credentials:
exec env run [environment] -i $SHELL
That shell command may be executed an arbitrary number of times without memory usage increasing, as each shell replaces the previous in place.
This provides for a nice way to automatically refresh credentials in a shell, e.g., in a ~/.bashrc:
export PULUMI_ENVIRONMENT_LAST_OPEN_AT=${PULUMI_ENVIRONMENT_LAST_OPEN_AT:-"0"}
refresh_credentials() {
if [[ -z "${PULUMI_ENVIRONMENT:-""}" ]]; then
return
fi
local now
now=$(date +%s)
local elapsed=$((now - PULUMI_ENVIRONMENT_LAST_OPEN_AT))
if [[ $elapsed -gt 3600 ]]; then
echo "Refreshing credentials..."
PULUMI_ENVIRONMENT_LAST_OPEN_AT=$(date +%s)
exec pulumi env run "$PULUMI_ENVIRONMENT" -i "$SHELL"
fi
}
refresh_credentials
PROMPT_COMMAND+="refresh_credentials;"
