discarddirectoriesfast
Important
mvs 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 _buildGet help.
ddf --helpOutput 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
dunelocally on your own system, but for consistency, we will useopam execto run dune within the context of the local switch. -
Create a local switch with
opamopam switch create . --deps-only --with-testThis command will read all the
*.opamfiles and download all dependencies.You will be prompted along the process.
-
Build CLI with
dunefrom the local switchopam exec -- dune build bin -
Verify
ddf.exeeza --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 binRun dune in watch mode to get a fast development feedback loop.
opam exec -- dune exec bin/ddf.exe --watch -- --helpTests are organied into their own dune project.
Currently, unit tests with Alcoltest are used.
opam exec -- dune runtestOnce the built with dune, you can invoke the executable directly:
./_build/default/bin/ddf.exe --helpor with dune
opam exec -- dune exec/bin/ddf.exe -- --helpIf you are consuming the binary from the build artifacts, ensure you allow the ddf.exe to be executable:
chmod +x ddf.exeInstall 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 ddfAllow the application to be executable
chmod +x ddfAttempt to run the help page and acknowledge the OS prompt
./ddf --helpPress 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/
.
├── ddfYou 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
TMPDIRenvironment variable, or "/tmp" if the variable is not set. Under Windows, the value of theTEMPenvironment variable, or "." if the variable is not set. ..
ddf creates a child directory (called "ddf") to use as the destination for all discarded items.


