How I Normalize Filenames on Windows Using MSYS2 Bash and CLI Tools

💡 TL;DR: Quick Setup

1# 1. Add Windows tools to PATH inside MSYS2 Bash
2export PATH="$PATH:/c/Users/USERNAME/.local/bin:/c/Users/USERNAME/.cargo/bin:/c/Users/USERNAME/scoop/shims"
3
4# 2. Install CLI tools
5cargo install notox
6pipx install date2name
7
8# 3. Clean up filenames
9notox -r . && date2name -r .

✅ Works natively on Windows — no WSL, just MSYS2 Bash inside Alacritty.


If you handle messy filenames every day — photos, invoices, USB dumps — you know the pain:
spaces, accents, duplicate #copy files, and random dates everywhere.

This is my Windows-native workflow for cleaning and normalizing filenames fast:

Alacritty + MSYS2 Bash + cross-platform CLI tools (notox, date2name, pipx)

No WSL. No emulation.
Everything runs natively on Windows, but with the power and convenience of Unix commands.


⚙️ Setup Overview

I already have:

  1. MSYS2 installed (msys2.org) — provides a native Unix-like shell on Windows
  2. Scoop installed (scoop.sh) — a lightweight package manager for Windows
  3. pipx installed via Scoop — manages and runs Python-based CLI tools (requires Python from python.org)
  4. Rust installed via rustup.rs — compiles and installs Rust-based CLI tools
  5. Alacritty (alacritty.org) — a lightweight, GPU-accelerated terminal that works beautifully with MSYS2 Bash

Then I simply:

  1. Set MSYS2 Bash as the default shell in Alacritty via bash.exe
  2. Adjusted my Alacritty configuration so it launches directly into the UCRT64 environment.

Alacritty automatically adds an “Open Alacritty here” option to the Windows right-click menu, so I can open any folder in the same Bash environment instantly.

Here’s the relevant part of my alacritty.toml:

1[terminal.shell]
2program = "C:\\msys64\\usr\\bin\\bash.exe"
3args = ["--login", "-i"]
4
5[env]
6MSYSTEM = "UCRT64"
7CHERE_INVOKING = "1"
8LANG = "en_US.UTF-8"
9LC_ALL = "en_US.UTF-8"

This ensures Alacritty opens MSYS2 Bash directly, keeps the working directory when launched via the right-click menu, and uses UTF-8 everywhere for consistent filenames and Unicode output.


🧩 1. Make MSYS2 See Your Windows Tools

By default, MSYS2 doesn’t automatically detect CLI tools installed on Windows (for example, via pipx, cargo, or scoop).
To bridge them, add their install paths manually to your Bash config.

Open your MSYS2 Bash inside Alacritty, then edit:

1vim ~/.bashrc

Append this at the end:

1# Access Windows-native binaries from MSYS2
2export PATH="$PATH:/c/Users/USERNAME/.local/bin"
3export PATH="$PATH:/c/Users/USERNAME/.cargo/bin"
4export PATH="$PATH:/c/Users/USERNAME/scoop/shims"

Reload your shell:

1source ~/.bashrc

Now MSYS2 can run tools installed by pipx, Rust, and Scoop directly:

1pipx --version
2cargo --version

If those commands respond normally, your environment is ready.


🧽 2. Install notox (Rust)

notox cleans filenames — removes accents, replaces spaces, and strips unsafe characters.

1cargo install notox

🗂 The binary is installed to:

C:\Users\USERNAME\.cargo\bin\notox.exe

You can test it immediately in MSYS2 Bash:

1notox --help

🗓️ 3. Install date2name (Python via pipx)

date2name renames files based on EXIF metadata or last-modified dates.

Since pipx is installed via Scoop, it automatically links its executables under:

C:\Users\USERNAME\.local\bin

So installing is simple:

1pipx install date2name

Verify it’s available:

1date2name --help

🔁 4. The Workflow

Once everything’s in place:

  1. Right-click any folder → “Open Alacritty here
  2. Run:
1notox -r .
2date2name -r .

That’s it — clean, normalized filenames in seconds.


📦 Example

Before:

Ảnh chụp (2) #Copy.JPG
Thử nghiệm 03.2024 - final.docx

After:

2024-03-05_Anh_chup_2_Copy.JPG
2024-03-05_Thu_nghiem_03_2024_final.docx

✔️ Safe
✔️ Sortable
✔️ Cross-platform ready


🧭 Why This Setup Works

System overview:
Windows → Alacritty → MSYS2 Bash → CLI tools (notox, date2name)

Component Role Benefit
Alacritty + MSYS2 Bash Shell Fast startup, GPU-accelerated, right-click integration
notox (Rust tool) Filename normalizer Blazing fast, Unicode-aware
date2name (Python tool) Date-based renamer Smart EXIF/timestamp parsing
PATH bridge Integration Lets MSYS2 see Windows-installed tools

⚠️ Why PowerShell Fails (and MSYS2 Works)

date2name and notox don’t run reliably in PowerShell because it’s not a POSIX shell.
They expect Unix-style path handling and argument behavior that PowerShell doesn’t provide.

If you try a command like:

1PS C:\Users\USERNAME\Temp> date2name.exe .\dada\

you’ll likely see an error such as:

FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

That happens because PowerShell passes .\dada\ as a Windows-style path, while the script’s internal logic expects POSIX-style behavior.

MSYS2 Bash fixes this automatically — it converts /c/... paths to real Windows locations and provides the POSIX environment these tools expect.
So if you hit errors like this in PowerShell, just rerun the same command in Alacritty’s MSYS2 Bash — it’ll work perfectly there.


💡 Pro Tips


🔗 References


In short:
Use Alacritty with MSYS2 Bash as your compatibility layer on Windows.
Install your CLI tools once — notox, date2name, or anything provided by Scoop, pipx, Cargo, or MSYS2.
Open any folder in Bash via Alacritty, run your cleanup commands, and get perfectly normalized filenames in seconds.
If PowerShell throws path errors or nothing happens, switch to MSYS2 Bash — it’s built for Unix-style tools.


And that’s why I don’t use PowerShell.
Alacritty with MSYS2 Bash just works — paths, UTF-8, globs, and all.

#windows   #cli   #msys2   #bash   #automation   #notox   #date2name   #pipx   #alacritty   #scoop