forked from farhoodlabs/skills
fix(agent-setup): source existing .env and update GH_CONFIG_DIR in place
Preserves other variables already in $AGENT_HOME/.env when updating the GH_CONFIG_DIR export rather than overwriting the file.
This commit is contained in:
@@ -9,10 +9,24 @@ die() { echo "ERROR: $*" >&2; exit 1; }
|
|||||||
# so we mirror that structure under AGENT_HOME
|
# so we mirror that structure under AGENT_HOME
|
||||||
export GH_CONFIG_DIR="$AGENT_HOME/.github"
|
export GH_CONFIG_DIR="$AGENT_HOME/.github"
|
||||||
|
|
||||||
# Write to a session dotfile so child processes inherit the variables
|
|
||||||
mkdir -p "$AGENT_HOME"
|
mkdir -p "$AGENT_HOME"
|
||||||
cat > "$AGENT_HOME/.env" <<EOF
|
_ENV_FILE="$AGENT_HOME/.env"
|
||||||
export GH_CONFIG_DIR="$GH_CONFIG_DIR"
|
|
||||||
EOF
|
# If .env exists, source it first so we preserve existing variables
|
||||||
|
if [[ -f "$_ENV_FILE" ]]; then
|
||||||
|
set -a
|
||||||
|
source "$_ENV_FILE"
|
||||||
|
set +a
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update or add GH_CONFIG_DIR export
|
||||||
|
if grep -q '^export GH_CONFIG_DIR=' "$_ENV_FILE" 2>/dev/null; then
|
||||||
|
# Replace existing value in place
|
||||||
|
sed -i.bak "s|^export GH_CONFIG_DIR=.*|export GH_CONFIG_DIR=\"$GH_CONFIG_DIR\"|" "$_ENV_FILE"
|
||||||
|
rm -f "$_ENV_FILE.bak"
|
||||||
|
else
|
||||||
|
# Append new export
|
||||||
|
printf 'export GH_CONFIG_DIR="%s"\n' "$GH_CONFIG_DIR" >> "$_ENV_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "GH_CONFIG_DIR set to $GH_CONFIG_DIR"
|
echo "GH_CONFIG_DIR set to $GH_CONFIG_DIR"
|
||||||
|
|||||||
Reference in New Issue
Block a user