Skip to content

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

@sxyazi sxyazi force-pushed the main branch 5 times, most recently from a9c693e to 86f4659 Compare April 8, 2025 09:06
@sxyazi sxyazi force-pushed the main branch 12 times, most recently from 1cc8e5a to a29dbb9 Compare April 21, 2025 18:46
@sxyazi sxyazi force-pushed the main branch 3 times, most recently from d1efbb8 to a0ab614 Compare June 16, 2025 13:25
@sxyazi sxyazi force-pushed the main branch 4 times, most recently from 35d9907 to 2768fd2 Compare June 27, 2025 09:44
@sxyazi sxyazi force-pushed the main branch 3 times, most recently from 9f077f9 to 60a2382 Compare July 14, 2025 15:08
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