Skip to content

Instantly share code, notes, and snippets.

@alirp88
Created April 8, 2026 15:40
Show Gist options
  • Select an option

  • Save alirp88/c97b63216dff31fb5c42b33e6e4d8f0e to your computer and use it in GitHub Desktop.

Select an option

Save alirp88/c97b63216dff31fb5c42b33e6e4d8f0e to your computer and use it in GitHub Desktop.
#!/bin/zsh
# To load the secret from keychain in macos
load_secret() {
local name=$1
local value=$(security find-generic-password -a "$USER" -s "$name" -w 2>/dev/null)
if [ -n "$value" ]; then
export "$name"="$value"
fi
}
load_secret SECRET_NAME
# To save the secret into keychain in macos
security add-generic-password -a "$USER" -s SECRET_NAME -w "SECRET_VALUE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment