Skip to content

keypaste env

Imports, exports and compares an environment’s variables, stage by stage.

Terminal window
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.

OptionVerbsEffect
-p, --profile <stage>all but diffThe stage, dev by default; export in a folder the app saved uses that folder’s stage.
--profileslsThe environment’s stages only.
--jsonlsMachine-readable output.
--entry <item>set, rm, pullThe item to write on, rather than the stage’s home item.
--generatesetGenerate the value. With --length <N> (20 by default), or --words <N> and --separator <C> (. by default), --no-symbols and --no-lookalikes.
--keeppullKeep the .env without asking.
--delete-sourcepullDelete the .env afterwards without asking.
--dotenvexportWrite the values in plain text as a .env, ./.env by default, instead of kp:// references.
--stdoutexportPrint the values rather than write them.
--forceexportReplace a file that is there. It never overwrites a KeePass vault.
--yesrm, pull, export, tag, untagGo ahead without asking. Needed without a terminal.

export and diff with no environment use the one the desktop app saved for this folder.

  • set asks for the value unless KEY=value gives it, so a value stays out of shell history.
  • pull reads ./.env unless you name a file, lists names and never values, and writes nothing if any line is malformed. Without --keep it then offers to delete the file.
  • export prints kp:// references, safe to commit (kp:// references). With --dotenv it 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.
  • diff names a key one stage lacks or cannot release, and a value two stages share. It never prints a value.
  • prod, production and their -… forms are protected stages.

It differs from motdotla/dotenv in three ways:

  • Comments. A # starts a comment only after a space, so PASSWORD=hunter2#42 keeps #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.

Ordinary items: env/<project>/.env, tagged env:<project>, with a protected field per variable. You can edit them in KeePassXC without keypaste.

Terminal window
keypaste env pull shop --keep
keypaste env set shop DATABASE_URL -p staging
keypaste env set shop SESSION_SECRET --generate --length 40
keypaste env ls shop --profiles
keypaste env diff shop dev staging
keypaste env export shop -p staging > .env.keypaste
keypaste env export shop .env --dotenv
CodeMeaning
0Success
1Usage error
2Internal or environment error
3Vault, environment or item not found
4Wrong master password