A bash function to easily switch between different Cloudflare environments by loading environment-specific configuration files.
- Interactive environment selection using
fzf(if available) - Direct environment specification via command line argument
- Displays loaded Cloudflare credentials (with masked API token for security)
- Lists available environments when selection fails
-
Source the script in your shell profile (
.bashrc,.zshrc, etc.):source <absolute-path>/cfenv.sh
-
Create environment files in the
env-files/directory with the naming patternenv.{environment_name}:env-files/ ├── env.dev ├── env.staging └── env.prod -
Each environment file should contain your Cloudflare credentials:
export CLOUDFLARE_ACCOUNT_ID="your-account-id" export CLOUDFLARE_API_TOKEN="your-api-token"
cfenvcfenv dev
cfenv staging
cfenv prodfzf(optional, for interactive selection)- Environment files in
env-files/directory
- Environment files are ignored by git (see
.gitignore) - API tokens are displayed with only first and last 4 characters visible