PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[PowerRename] Random string values to file names

Open jhirvioja opened this issue 9 months ago • 6 comments

Summary of the Pull Request

This pull request introduces random string replacement to PowerRename. With the random button toggled on, user can use these values in the "Replace with" input to generate random values to file names:

  • ${rstringalnum=9} - Random string with uppercase letters, lowercase letters and 0-9 digits, customized length.

  • ${rstringalpha=13} - Random string with uppercase letters and lowercase letters, customized length.

  • ${rstringdigit=36} - Random string with 0-9 digits, customized length.

  • ${ruuidv4} - Random UUID according to v4 specification.

PR Checklist

  • [x] Closes: #3373
  • [x] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [x] Tests: Added/updated and all pass
  • [x] Localization: All end user facing strings can be localized
  • [ ] Dev docs: Added/updated
  • [N/A] New binaries: Added on the required places
  • [x] Documentation updated: If checked, please file a pull request on our docs repo and link it here: https://github.com/MicrosoftDocs/windows-dev-docs/pull/4995

Detailed Description of the Pull Request / Additional comments

  • I think this covers most use cases, as uppercase/lowercase is controlled by existing functionality, and curly brackets flavor of UUID can be added manually by user in the "Replace with" input if needed (all tested and working)

  • Enumerating and random strings toggle each other on/off, similar to uppercase/lowercase/etc. Unfortunately right now I don't have the time (or the knowledge) to look in to how to make them work together

  • Other UUID versions, like UUIDv5, can be added later. But in a sense UUIDv5 is no longer "random", so it might be better to do it in another issue, even probably in another subheading in the PowerRename tool tip. Just to be super clear to the user that it is not random

  • Tweaked the texts a little in the UI, in my opinion a little more clearer now, let me know if they make sense (my reasoning: when you click on enumerating icon, you are not actually just enumerating items like it used to be [0, 1 ... etc], you are also enabling the enumeration feature)

  • Combined with the date feature (f.e. $YYYY), it only works when added to the middle of values or end of the file name. There is an issue about this already: #28428, enumerator feat works in a similar way, so maybe an unified solution is possible (outside of this scope)

Validation Steps Performed

  • All unit tests pass
  • Tested manually with Windows 11 Pro x64 (W10 upgraded version)
    • renamed in various ways with a bunch of txt-files, subfolders, uppercase, lowercase, etc., works as intended

jhirvioja avatar May 12 '24 11:05 jhirvioja

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.

Unrecognized words (4)

rstring rstringchar rstringnum ruuid

Previously acknowledged words that are now absent COMMANDTITLE FILELOCKSMITHLIB gdnbaselines interactable JArray ksh localport OOBEPT Pathto qwertyuiopasdfghjklzxcvbnm qwrtyuiopsghjklzxvnm redirectedfrom runsettings testhost toggleswitch 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:jhirvioja/PowerToys.git repository on the powerrename-randomizer branch (:information_source: how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/9050963582/attempts/1'
Available :books: dictionaries could cover words (expected and unrecognized) not in the :blue_book: dictionary

This includes both expected items (1876) from .github/actions/spell-check/expect.txt and unrecognized words (4)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
If the flagged items are :exploding_head: false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar May 12 '24 11:05 github-actions[bot]

@microsoft-github-policy-service agree

jhirvioja avatar May 12 '24 11:05 jhirvioja

I think "rstringchar" should be "rstringalpha".

Jay-o-Way avatar May 13 '24 14:05 Jay-o-Way

I think "rstringchar" should be "rstringalpha".

Hmm, right. In POSIX that implies uppercase letters as well, and the solution does not do that. But a character can indeed be numbers as well by definition.

Now that I think about it, should rstring (the basic one) actually be called rstringalnum, and add uppercase letters to there and to rstringalpha? And call rstringnum rstringdigit. That would be in line with POSIX altogether.

Before:

  • ${rstring=9} - abcdefghijklmnopqrstuvwxyz0123456789

  • ${rstringchar=13} - abcdefghijklmnopqrstuvwxyz

  • ${rstringnum=36} - 0123456789

After:

  • ${rstringalnum=9} - abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

  • ${rstringalpha=13} - abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

  • ${rstringdigit=36} - 0123456789

e: updated, looks a lot cleaner and opens up one more use case (upper- and lowercase letters mixed)

jhirvioja avatar May 13 '24 15:05 jhirvioja

e: updated, looks a lot cleaner and opens up one more use case (upper- and lowercase letters mixed)

I can imagine that users need to decide if upper, lower or mixed case. Does a simple drop down setting in the ux makes sense?

htcfreek avatar May 13 '24 16:05 htcfreek

e: updated, looks a lot cleaner and opens up one more use case (upper- and lowercase letters mixed)

I can imagine that users need to decide if upper, lower or mixed case. Does a simple drop down setting in the ux makes sense?

I would probably keep it like it has been established, user can decide between mixed (default), lower case (toggle lower case button), upper case (toggle upper case button): mixed-lower-upper

jhirvioja avatar May 13 '24 17:05 jhirvioja

Thanks for opening the PR. Assigning this to me, since I'm currently reviewing. I'm trying to figure out if we can make this feature coexist with Enumerate.

jaimecbernardo avatar Jun 17 '24 21:06 jaimecbernardo

@jhirvioja , I've enabled the use of this feature with Enumerate at the same time. I'll now have to ask for a different reviewer, though, since my hands are all up in this code 😅

jaimecbernardo avatar Jun 19 '24 11:06 jaimecbernardo

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.

Unrecognized words (1)

randomizers

Previously acknowledged words that are now absent COMMANDTITLE FILELOCKSMITHLIB gdnbaselines GPT interactable JArray ksh localport OOBEPT Pathto qwertyuiopasdfghjklzxcvbnm qwrtyuiopsghjklzxvnm redirectedfrom runsettings runspace testhost toggleswitch 🫥
Some files were automatically ignored :see_no_evil:

These sample patterns would exclude them:

^src/modules/launcher/Plugins/Microsoft\.PowerToys\.Run\.Plugin\.TimeDate/Properties/

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands

... in a clone of the [email protected]:jhirvioja/PowerToys.git repository on the powerrename-randomizer branch (:information_source: how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/9581458263/attempts/1'
Available :books: dictionaries could cover words (expected and unrecognized) not in the :blue_book: dictionary

This includes both expected items (1881) from .github/actions/spell-check/expect.txt and unrecognized words (1)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Warnings (1)

See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.

:information_source: Warnings Count
:information_source: binary-file 2

See :information_source: Event descriptions for more information.

If the flagged items are :exploding_head: false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar Jun 19 '24 11:06 github-actions[bot]