Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leading-zero-util

A CLI utility to add or remove leading zeros from the numbers at the end of filenames in a directory.

Usage

leading-zero-util [OPTIONS] [PATH]

If no path is provided, it operates on the current directory.

Options

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

Examples

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

How it works

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-1problem-01
  • problem-11problem-11 (already at target width)

With --basic-add, zeros are added naively without normalization:

  • problem-1problem-01
  • problem-11problem-011

When removing zeros (-d), at least one digit is always kept — it will never reduce a number to an empty string.

Install

Via homebrew (recommended)

If you have Homebrew installed:

brew tap KaonQuantum/leading-zero-util
brew install leading-zero-util

Via crates.io

If you have Cargo installed:

cargo install leading-zero-util

From source

Clone the repository and install locally:

git clone https://github.com/KaonQuantum/zero-adder-util
cd zero-adder-util
cargo install --path .

Installing Cargo

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.

Setting Up Completions

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.bash

Then source it from your ~/.bashrc

source ~/.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-util

Then make sure that directory is on your fpath before compinit runs, in your ~/.zshrc

fpath=(~/.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.elv

Then use it from your rc.elv

use leading-zero-util
Powershell

Generate the completion script and add it to your $PROFILE

leading-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.nu

Then source it from your config.nu

source ~/.config/nushell/completions/leading-zero-util.nu

License

See LICENSE.

About

Modifies the amount of leading zeros in everything in the directory. eg. problem-01 <-> problem-001 <-> problem-00001

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages