A CLI utility to add or remove leading zeros from the numbers at the end of filenames in a directory.
leading-zero-util [OPTIONS] [PATH]
If no path is provided, it operates on the current directory.
| Flag | Short | Description |
|---|---|---|
--number <N> |
-n |
Number of zeros to add or remove (default: 1) |
--decrease |
-d |
Remove leading zeros instead of adding them |
--basic-add |
-b |
Add zeros naively without normalizing across files |
--help |
-h |
Print help |
--version |
-V |
Print version |
Add one leading zero to all files in the current directory:
leading-zero-util
Add two leading zeros to files in ~/my-folder:
leading-zero-util ~/my-folder -n 2
Remove one leading zero from files in the current directory:
leading-zero-util -d
Remove two leading zeros:
leading-zero-util -d -n 2
Add one zero naively (without normalizing):
leading-zero-util -b
Only files whose names (excluding file extensions (.txt, .rs, .html, etc.)) end in digits are renamed. The prefix (everything before the trailing number) is preserved.
By default, adding zeros normalizes across all files — it finds the shortest numeric suffix and pads everything to the same width plus the requested count. For example, with -n 1 on problem-1 and problem-11:
problem-1→problem-01problem-11→problem-11(already at target width)
With --basic-add, zeros are added naively without normalization:
problem-1→problem-01problem-11→problem-011
When removing zeros (-d), at least one digit is always kept — it will never reduce a number to an empty string.
If you have Homebrew installed:
brew tap KaonQuantum/leading-zero-util
brew install leading-zero-utilIf you have Cargo installed:
cargo install leading-zero-utilClone the repository and install locally:
git clone https://github.com/KaonQuantum/zero-adder-util
cd zero-adder-util
cargo install --path .If you don't have Cargo, install Rust (which includes Cargo) by following the instructions at https://www.rust-lang.org/tools/install.
Then re-run the install command above.
If you didn't install with Homebrew, or you aren't on Bash, Zsh, or Fish, for completions to work, you must follow the instructions for your shell.
Bash
Generate the completion script and place it in your completions directory (usually ~/.bash_completion.d/ or wherever your ~/.bashrc sources completions from)
mkdir -p ~/.bash_completion.d/ leading-zero-util --generate-completions bash > ~/.bash_completion.d/leading-zero-util.bashThen source it from your
~/.bashrcsource ~/.bash_completion.d/leading-zero-util.bash
Zsh
Generate the completion script into a directory on your
$fpath(usually ~/.zsh/completions/)mkdir -p ~/.zsh/completions/ leading-zero-util --generate-completions zsh > ~/.zsh/completions/_leading-zero-utilThen make sure that directory is on your
fpathbeforecompinitruns, in your~/.zshrcfpath=(~/.zsh/completions $fpath) autoload -Uz compinit && compinit
Fish
Generate the completion script directly into your completions directory (usually ~/.config/fish/completions/)
mkdir -p ~/.config/fish/completions/ leading-zero-util --generate-completions fish > ~/.config/fish/completions/leading-zero-util.fish
Elvish
Generate the completion script and place it in your rc directory (usually ~/.config/elvish/lib/)
mkdir -p ~/.config/elvish/lib/ leading-zero-util --generate-completions elvish > ~/.config/elvish/lib/leading-zero-util.elvThen use it from your
rc.elvuse leading-zero-util
Powershell
Generate the completion script and add it to your
$PROFILEleading-zero-util --generate-completions powershell >> $PROFILE
Nushell
Generate the completion file and place it in your completions directory (usually ~/.config/nushell/completions/)
mkdir -p ~/.config/nushell/completions/ leading-zero-util --generate-nu-completions o> ~/.config/nushell/completions/leading-zero-util.nuThen source it from your
config.nusource ~/.config/nushell/completions/leading-zero-util.nu
See LICENSE.