Crates.io | withd |
lib.rs | withd |
version | 0.3.1 |
source | src |
created_at | 2024-06-05 10:22:46.178122 |
updated_at | 2024-06-10 11:37:29.185289 |
description | Run a command in another directory. |
homepage | |
repository | https://github.com/allenap/withd |
max_upload_size | |
id | 1262642 |
size | 84,673 |
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.
Many commands – such as git
, npm
, and cargo
– require you to run them from
a specific directory. This can be done by cd
ing 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.
withd --help
$ withd --help
Run a command in another directory.
Usage: withd [OPTIONS] <DIRECTORY> [COMMAND]...
Arguments:
<DIRECTORY>
The directory in which to execute the command.
[COMMAND]...
The command and its arguments.
[env: SHELL=/opt/homebrew/bin/bash]
Options:
-c, --create
Create the directory if it does not exist.
-t, --temporary
Create a temporary directory within DIRECTORY. This temporary
directory will be deleted when the command completes. Note that this
option modifies slightly how the DIRECTORY argument is used. For
example:
- `withd -tc foo/bar.XXXX.baz …` will create the directory `foo` (and
will not remove it later on) and a temporary directory inside it
called `bar.1234.baz` (where the 1234 is random).
- `withd -tc foo …` will create `foo`, as above, and a temporary
directory inside it named `.tmp123456` (again, where 123456 is
random).
- `withd -t foo …` will create a temporary directory named
`.tmp123456` (again, where 123456 is random) in `foo`, but assumes
that `foo` already exists.
- `withd -t foo.XXXX.bar …` will create a temporary directory named
`foo.1234.bar` in the system's temporary directory, e.g. $TMPDIR.
- `withd -t "" …` will create a temporary directory named `.tmp123456`
in the system's temporary directory, e.g. $TMPDIR.
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
The executed command can use the `WHENCE` environment variable to refer back to
the directory from whence `withd` was invoked.
For now, use Cargo:
cargo install withd
withd /path/to/repo git status
To create the directory:
withd -c /some/where echo "Hello, world!"
(-c
is short for --create
.)
cargo completions
.Cargo.toml
.--help
output into README.md
(this file; see
near the top). On macOS the command cargo withd --help | pbcopy
is helpful.
Note that --help
output is not the same as -h
output: it's more
verbose and that's actually what we want here.cargo build && cargo test
cargo build --no-default-features && cargo test --no-default-features
$VERSION
."$VERSION
", e.g. git tag v1.0.10
.git push && git push --tags
.cargo publish
.GNU General Public License 3.0 (or later). See LICENSE.