withd 0.1.0

Run a command in another directory.
withd-0.1.0 is not a library.

withd

withd is a simple command-line tool that allows you to run a command with a different working directory without affecting the current shell's working directory.

Why is this useful?

Many commands – such as git, npm, and cargo – require you to run them from a specific directory. This can be done by cding into the directory:

cd /path/to/repo
git status
cd -

or by using a subshell to isolate the change:

( cd /path/to/repo && git status )

The first is cumbersome. The latter can be confusing when also trying to work with shell variables in a script, for example, since the subshell cannot propagate changes to the parent shell. It's also easy to forget.

Then there's CDPATH. If this is set in your shell, cd's behaviour changes and you might end up in a different directory than you expected. I've seen this be a source of confusion – and a disruptive and very difficult to diagnose bug.

withd does not have these problems. It's simple and predictable.

Installation

For now, use Cargo:

cargo install withd

Usage

withd /path/to/repo git status

To create the directory:

withd -c /some/where echo "Hello, world!"

(-c is short for --create.)

License

GNU General Public License 3.0 (or later). See LICENSE.