keypaste env
Imports, exports and compares an environment’s variables, stage by stage.
Synopsis
Section titled “Synopsis”keypaste env ls [<project>] [-p <stage>] [--profiles] [--json]keypaste env set <project> <KEY[=value]> [-p <stage>] [--entry <item>] [--generate …]keypaste env rm <project> <KEY> [-p <stage>] [--entry <item>] [--yes]keypaste env pull <project> [<file>] [-p <stage>] [--entry <item>] [--yes] [--keep | --delete-source]keypaste env export [<project>] [<file>] [-p <stage>] [--dotenv] [--stdout] [--force] [--yes]keypaste env diff [<project>] [<stage>] [<other>]keypaste env tag <project> <item> [-p <stage>] [--yes]keypaste env untag <project> <item> [-p <stage>] [--yes]Every verb also takes --vault <path> and --keyfile <path> (flags every command takes).
<project> is the environment’s name; the argument keeps its earlier name. An environment’s variables are the custom fields of the items tagged env:<project>, for the dev stage, or env:<project>:<stage>. set and pull write on the stage’s home item, env/<project>/.env or env/<project>/.env.<stage>, created and tagged when missing, unless --entry names another. On those home items any name a shell can export is a variable, lower case included, such as api_url; on any other item tagged into the stage, such as a login, only fields named in capitals are, so its ordinary fields never join the stage.
Options
Section titled “Options”| Option | Verbs | Effect |
|---|---|---|
-p, --profile <stage> | all but diff | The stage, dev by default; export in a folder the app saved uses that folder’s stage. |
--profiles | ls | The environment’s stages only. |
--json | ls | Machine-readable output. |
--entry <item> | set, rm, pull | The item to write on, rather than the stage’s home item. |
--generate | set | Generate the value. With --length <N> (20 by default), or --words <N> and --separator <C> (. by default), --no-symbols and --no-lookalikes. |
--keep | pull | Keep the .env without asking. |
--delete-source | pull | Delete the .env afterwards without asking. |
--dotenv | export | Write the values in plain text as a .env, ./.env by default, instead of kp:// references. |
--stdout | export | Print the values rather than write them. |
--force | export | Replace a file that is there. It never overwrites a KeePass vault. |
--yes | rm, pull, export, tag, untag | Go ahead without asking. Needed without a terminal. |
export and diff with no environment use the one the desktop app saved for this folder.
Behaviour
Section titled “Behaviour”setasks for the value unlessKEY=valuegives it, so a value stays out of shell history.pullreads./.envunless you name a file, lists names and never values, and writes nothing if any line is malformed. Without--keepit then offers to delete the file.exportprintskp://references, safe to commit (kp:// references). With--dotenvit writes values in plain text, the one way keypaste puts them on disk unencrypted: on Linux and macOS only you can read the file; on Windows it takes its folder’s permissions.diffnames a key one stage lacks or cannot release, and a value two stages share. It never prints a value.prod,productionand their-…forms are protected stages.
How keypaste reads a .env
Section titled “How keypaste reads a .env”It differs from motdotla/dotenv in three ways:
- Comments. A
#starts a comment only after a space, soPASSWORD=hunter2#42keeps#42. - Duplicate keys. keypaste refuses them until you resolve them.
- Escapes. Inside double quotes,
\n,\r,\t,\\and\"expand. For a literal Windows path, write'C:\temp'in single quotes.
Avoid docker run --env-file with an exported .env: it keeps quotes as literal text.
What KeePassXC sees
Section titled “What KeePassXC sees”Ordinary items: env/<project>/.env, tagged env:<project>, with a protected field per variable. You can edit them in KeePassXC without keypaste.
Examples
Section titled “Examples”keypaste env pull shop --keepkeypaste env set shop DATABASE_URL -p stagingkeypaste env set shop SESSION_SECRET --generate --length 40keypaste env ls shop --profileskeypaste env diff shop dev stagingkeypaste env export shop -p staging > .env.keypastekeypaste env export shop .env --dotenvExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Usage error |
| 2 | Internal or environment error |
| 3 | Vault, environment or item not found |
| 4 | Wrong master password |