Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add counters to bulk rename function #2525

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JustForFun88
Copy link

@JustForFun88 JustForFun88 commented Mar 24, 2025

This Pull Request introduces counter-based bulk renaming to Yazi, enabling users to specify incrementing placeholders across multiple lines. Each line can include zero or more placeholders of the form:

%{<COUNT_TYPE>,<START_VALUE>,<STEP>,<WIDTH>}

where:

  • <COUNT_TYPE>: A single character indicating the counter type:
    • N, n, D, d → Numeric digits.
    • A → Uppercase ANSI letters.
    • a → Lowercase ANSI letters.
    • R → Uppercase Roman numerals.
    • r → Lowercase Roman numerals.
    • C → Uppercase Cyrillic letters.
    • c → Lowercase Cyrillic letters.
  • <START_VALUE> (optional): Initial value, either as a number (e.g., 1, 2, etc.) or a value corresponding to the counter type:
    • A, B, AA (ANSI uppercase)
    • a, b, aa (ANSI lowercase)
    • I, II, III (Roman uppercase)
    • i, ii, iii (Roman lowercase)
    • А, Б, АБ (Cyrillic uppercase)
    • а, б, аб (Cyrillic lowercase)
    • _ for unspecified.
  • <COUNT_STEP> (optional): Step size, integer (e.g., 2) or _ for unspecified.
  • <COUNT_WIDTH> (optional): Minimum width with zero-padding. Integer (e.g., 3) or _ for unspecified.

Optional parameters (<START_VALUE>, <STEP>, <WIDTH>) can be set or left as _ to take defaults. For instance, %{n,_,2,3} starts at the default value 1, increments by 2, and has a minimum width of 3. They also can be omitted, i.e. not written at all. For example, you can write %{N}, %{N, 1}

Optional parameters must be specified sequentially: <START_VALUE> is required if <COUNT_STEP> or <COUNT_WIDTH> are used, either explicitly (e.g., 1) or with _. Omitting earlier parameters with commas (e.g., %{N,,2} or %{N,,,4}) is invalid. User should write %{N,_,2} or %{N,_,_,4} instead.

Escaping: To insert a literal %{ in filenames (in linux for example), user could escape it by writing %%{. For example, file_%%{name}.txt will become file_%{name}.txt.

Constraints & Error Handling:

  • If any line contains counters, all lines must have the same number of placeholders; mismatches result in a comprehensive error report showing all problematic lines simultaneously.
  • All errors are collected and reported together.

To avoid adding extra dependencies, the parser is custom-written. While parsing performance could theoretically be improved using Rayon parallelization, I think that typical usage scenarios likely won’t require such optimization.

default.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant