Skip to content

docs / save

cwm save

Store a command, a piece of history or a multi-line script under a short name.

$ cwm save [name] [command] [flags]

How it works

  • Saving to a name that exists is an error. Use -e to replace it or -r to rename it.
  • Names may contain letters, digits, ., _ and -, up to 64 characters. Names with / or spaces are refused.
  • Your quotes and JSON are stored exactly as typed. Wrap the command in quotes so your shell passes it as one value.
  • Use %name% inside a command to make a placeholder. cwm get asks for a value when it runs.
  • Script mode (-s) opens your editor and keeps the file in ~/.cwm/scripts/. Set the editor with cwm config --editor.

Flags

-d, --desc <text>
Attach a description.
-t, --tag <tags>
Attach tags. One value, comma separated, for example -t git,util.
-e, --edit
Replace an existing command, or edit an existing script.
-r, --rename
Rename an alias. Usage: cwm save -r old new.
-l, --last
Save the last command from your shell history.
-s, --script
Write a multi-line script in your editor. The file lives in ~/.cwm/scripts/.

Examples

Save a command with a tag and description

cwm save
$ cwm save hello "echo Hello World" -t util -d "Greets user"
Saved [util] hello = echo Hello World (Greets user)

Save a command with placeholders

cwm save
$ cwm save deploy "kubectl rollout restart deploy/%name% -n %ns%" -t k8s -d "Restart a deployment"
Saved [k8s] deploy = kubectl rollout restart deploy/%name%... (Restart a deployment)

Refuse to overwrite

cwm save
$ cwm save hello "echo again"
Error: Variable 'hello' already exists. (Use -e to edit)