Created
May 16, 2026 10:04
-
-
Save smeech/de95f6d6205d0a77942cbfa6fc249de4 to your computer and use it in GitHub Desktop.
[password-gen-win package] A rewrite of https://github.com/espanso/hub/pull/226 to play with streamlining the repetitive code. #espanso #powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/dev/schemas/match.schema.json | |
| global_vars: | |
| - name: alpha | |
| type: echo | |
| params: | |
| echo: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
| - name: numbers | |
| type: echo | |
| params: | |
| echo: '0123456789' | |
| - name: symbols | |
| type: echo | |
| params: | |
| echo: '!@#$%^&*()-_=+[]{}|;:,.<>?' | |
| anchors: | |
| script1: &script1 | | |
| $chars = "{{chars}}" | |
| $len = [int]('{{len}}') | |
| $rng = [System.Security.Cryptography.RandomNumberGenerator]::Create() | |
| $bytes = New-Object byte[] $len | |
| $rng.GetBytes($bytes) | |
| $pw = -join ($bytes | ForEach-Object { $chars[$_ % $chars.Length] }) | |
| $rng.Dispose() | |
| Set-Clipboard -Value $pw | |
| Write-Output $pw | |
| matches: | |
| # Standard: Letters + Numbers | |
| - regex: ':pw(?P<len>\d{2})' | |
| replace: "{{output}}" | |
| vars: | |
| - name: chars | |
| type: echo | |
| params: | |
| echo: "{{alpha}}" | |
| - name: output | |
| type: shell | |
| params: | |
| cmd: *script1 | |
| shell: powershell | |
| # Secure: Letters + Numbers + Symbols | |
| - regex: ':pws(?P<len>\d{2})' | |
| replace: "{{output}}" | |
| vars: | |
| - name: chars | |
| type: echo | |
| params: | |
| echo: "{{alpha}}{{numbers}}{{symbols}}" | |
| - name: output | |
| type: shell | |
| params: | |
| cmd: *script1 | |
| shell: powershell | |
| # Numeric: Numbers only | |
| - regex: ':pwn(?P<len>\d{2})' | |
| replace: "{{output}}" | |
| vars: | |
| - name: chars | |
| type: echo | |
| params: | |
| echo: "{{numbers}}" | |
| - name: output | |
| type: shell | |
| params: | |
| cmd: *script1 | |
| shell: powershell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment