cargo-temp

A CLI tool that allows you to create a new rust project in a temporary directory with already installed dependencies.

Cargo-temp demo

Install

Requires Rust 1.51.

cargo install cargo-temp

Usage

Create a new temporary project:

Using the cargo's comparison requirements:

Repositories

You can add repositories to your Cargo.toml.

Examples:

If you have some problems to add a dependency over SSH, please refer to this: Support SSH Git URLs. If it doesn't help, please fill an issue.

To choose a branch or a revision:

Without a branch or a revision, cargo will use the default branch of the repository.

Dependencies features

You can add features to a dependency with +.

Examples:

If you want to add multiple features you can do it with +, like this:

cargo-temp serde=1.0+derive+alloc

Features

The TO_DELETE file

If you change your mind and decide to keep the project you can just delete the TO_DELETE file and the directory will not be deleted when the shell or the editor exits.

Git Working Tree

You can create a git worktree from the current repository using:

cargo-temp --worktree

This will create a new working tree at the current HEAD. You can specify a branch like this:

cargo-temp --worktree <branch>

When exiting the shell (or your editor) the working tree will be cleaned up. Equivalent to git worktree prune.

Temporary Git Clone

If you want to create a temporary project from a Git repository, you can use the --git option with the repository's URL:

cargo-temp --git <url>

Cargo-temp truncates the history to the last commit by default. You can change this behavior in the config file:

git_repo_depth = true is the same as the default behavior.

Settings

The config file is located at {CONFIG_DIR}/cargo-temp/config.toml. When you run cargo-temp for the first time it will be created automatically. We use the XDG system for both Linux and OSX and the Known Folder system on Windows.

Temporary project directory

The path where the temporary projects are created. Set on the cache directory by default.

toml temporary_project_dir = "/home/name/.cache/cargo-temp/"

Cargo target directory

Cargo's target directory override. This setting is unset by default and will be ignored if the CARGO_TARGET_DIR environment variable is already set.

toml cargo_target_dir = "/home/name/repos/tmp"

Editor

You can use editor to start an IDE instead of a shell and editor_args to provide its arguments. These settings are unset by default.

Use a VCS

By default, cargo-temp will use the default cargo VCS for your projects (which is normally git), you can change that in the config file with the vcs option.

toml vcs = "pijul"

The possible values are

The --vcs value will be passed as is to cargo.

Subprocesses

You can spawn subprocess along your temporary shell like this:

toml [[subprocess]] command = "alacritty -e cargo watch -x run" foreground = false

The command field is a shell command like echo Hello. The foreground field allows to run the program in foreground instead of background.

Additional settings

Platform specific

Unix: * stdout and stderr settings allows enabling or disabling outputs. With a background process, the default will be false, with a foreground process, the default will be true. The stdin setting doesn't exist since it's always disabled.

Windows: * inherit_handles allows handles inheritance - If this parameter is true, each inheritable handle in the calling process is inherited by the new process. If the parameter is false, the handles are not inherited (see CreateProcessW).

Examples