#!/bin/bash

# omarchy:summary=Disable the gcr-ssh-agent SSH agent and its environment override.

# The file goes before disable reloads the manager, or the environment generator keeps exporting it.
rm -f "$HOME/.config/environment.d/90-gcr-ssh-agent.conf"
systemctl --user disable --now gcr-ssh-agent.socket 2>/dev/null || true
systemctl --user stop gcr-ssh-agent.service 2>/dev/null || true

# The socket exported SSH_AUTH_SOCK to the user manager, which outlives the agent.
if systemctl --user show-environment | grep -Fqx "SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gcr/ssh"; then
  systemctl --user unset-environment SSH_AUTH_SOCK
fi

echo ""
echo "SSH agent has been disabled. Log out and back in for it to take full effect."
