d
iscardd
irectoriesf
ast
Important
mv
s directories and files to $TMPDIR
for quick cleanup
I wanted to try out OCaml 5 and with the new stable eio
library. Also, clearing out node_modules
and other build artifacts with rm -rf
takes too long.
The main form of input is a list of directories and/or files as a space separated list of arguments.
For best results, compose with fd
or find
to ensure correctly matching items on your file system.
Cleanup node_modules
across a monorepo
ddf $(fd -t d -d 3 -a --no-ignore --prune node_modules)
Cleanup local opam/dune deps
ddf _opam _build
Get help.
ddf --help
Output example:
DDF(1) Ddf Manual DDF(1)
NAME
ddf - `mv`s directories and files to `$TMPDIR` for quick cleanup
SYNOPSIS
ddf [-i] [--yolo] [OPTION]… FILE/DIR…
DESCRIPTION
ddf discards each specified FILE/DIR by moving it to a directory in
`$TMPDIR`, listed below.
Discarded FILE/DIRs are moved to this directory:
/var/ddf
To discard a FILE/DIR whose name starts with a -, for example -foo, use
one of these commands:
ddf -- -foo
ddf ./-foo
OPTIONS
-i Prompt before every operation.
-y, --yolo
Ignore nonexistent files and never prompt.
COMMON OPTIONS
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto,
pager, groff or plain. With auto, the format is pager or plain
whenever the TERM env var is dumb or undefined.
--version
Show version information.
EXIT STATUS
ddf exits with:
0 on success.
123 on indiscriminate errors reported on standard error.
-
Opam will be used to install dependencies. One such dependency is
dune
, the build tool.You may have
dune
locally on your own system, but for consistency, we will useopam exec
to run dune within the context of the local switch. -
Create a local switch with
opam
opam switch create . --deps-only --with-test
This command will read all the
*.opam
files and download all dependencies.You will be prompted along the process.
-
Build CLI with
dune
from the local switchopam exec -- dune build bin
-
Verify
ddf.exe
eza --tree ./_build/default
./_build/default ├── bin │ ├── ddf.exe # 👈 │ ├── ddf.ml │ └── ddf.mli ├── ddf.dune-package ├── ddf.install ├── ddf.opam ├── lib │ ├── lib.a │ ├── lib.cma │ ├── lib.cmxa │ ├── lib.cmxs │ └── lib.ml ├── test │ ├── test.exe │ ├── test.ml │ └── test.mli ├── test.dune-package ├── test.install └── test.opam
For production, be sure to include the release flag:
opam exec -- dune build --profile release bin
Run dune
in watch mode to get a fast development feedback loop.
opam exec -- dune exec bin/ddf.exe --watch -- --help
Tests are organied into their own dune project.
Currently, unit tests with Alcoltest are used.
opam exec -- dune runtest
Once the built with dune
, you can invoke the executable directly:
./_build/default/bin/ddf.exe --help
or with dune
opam exec -- dune exec/bin/ddf.exe -- --help
If you are consuming the binary from the build artifacts, ensure you allow the ddf.exe
to be executable:
chmod +x ddf.exe
Install from release page for your environment. Be mindful of the platform architecture.
Important
If you have an M-series Mac, you must download the *-macos-latest-arm64
build.
On MacOS, extract the binary to a location you prefer, like usr/bin
.
Rename the file to drop the .exe
mv ./ddf.exe ddf
Allow the application to be executable
chmod +x ddf
Attempt to run the help page and acknowledge the OS prompt
./ddf --help
Press Cancel
Open System Preferences
Scroll down to Security section, allow ddf
Attempt to run ddf
again
Acknowledge, AGAIN that we want to run this program
Return to see the output of the help page shown in your terminal.
From now on you can invoke the binary without all the interruptions.
Link ddf
on your system $PATH.
Note that this assumes you have the ddf
binary in the /usr/bin/
directory as such:
eza --tree /usr/bin/
.
├── ddf
You may choose a directory of your own choosing.
Add the following to your .bashrc
equivalent.
export DDF_HOME="/usr/bin/ddf"
export PATH="$DDF_HOME:$PATH"
Reload or source and you should now be able to execute ddf
anywhere in your shell.
The tmp directory is defined via the OCaml Filename module in the standard library:
The name of the temporary directory: Under Unix, the value of the
TMPDIR
environment variable, or "/tmp" if the variable is not set. Under Windows, the value of theTEMP
environment variable, or "." if the variable is not set. ..
ddf
creates a child directory (called "ddf") to use as the destination for all discarded items.