add base64 encode and decode which supports all os (can't do it) edit: Add base64-win package for native Windows support#225
Conversation
smeech
left a comment
There was a problem hiding this comment.
A Windows alternative to base64-encoder-decoder which attempts to provide OS-agnostic triggers. There are a number of problems which prevent it working for me, for which I've left comments.
I'll be interested to see what Copilot has to say.
There was a problem hiding this comment.
Pull request overview
Adds a new Espanso package (base64-utils) intended to provide cross-platform Base64 encode/decode triggers, using PowerShell on Windows and common CLI tools on Unix-like systems.
Changes:
- Introduces
:b64eand:b64dmatches implemented viashellvars with a Windows override. - Adds package metadata via
_manifest.yml. - Documents installation, usage, and requirements in
README.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/base64-utils/0.1.0/package.yml | Defines Base64 encode/decode triggers with OS-specific shell commands. |
| packages/base64-utils/0.1.0/_manifest.yml | Adds package metadata (name/title/version/tags). |
| packages/base64-utils/0.1.0/README.md | Documents triggers, installation, and platform requirements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I cannot figure out to create a single, cross-platform package that handled both Windows and macOS/Linux. The Espanso's filter_os directive only works at the global configuration level and cannot be applied directly inside a package.yml match block to swap out shell commands. |
smeech
left a comment
There was a problem hiding this comment.
I cannot figure out to create a single, cross-platform package that handled both Windows and macOS/Linux.
Not having an OS-agnostic scripting option is a real pain. I've also struggled for hours trying to find a way around it!
As you say, Python is probably the closest, but it requires installation in Windows, which most users won't do.
I suggest you change the instances of shell: powershell in your file (which are not needed as it's the default for Windows) to shell: pwsh (which Windows will ignore) and put a note in README.md that the package will only work in macOS and Linux if Powershell is installed. The only problem with this is that in Linux at least, Powershell is massively slower than Python.
Changing the powershell to pwsh throws error not working, windows is not ignoring pwsh |
Sorry - my mistake. |
| - name: output | ||
| type: shell | ||
| params: | ||
| cmd: "$c = $env:ESPANSO_CLIPBOARD; if ($c) { [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($c.TrimEnd())) }" |
| - name: output | ||
| type: shell | ||
| params: | ||
| cmd: '$c = $env:ESPANSO_CLIPBOARD; if ($c) { try { [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($c.TrimEnd())) } catch { Write-Output "[Error: Clipboard does not contain valid Base64]" } }' |
| - name: output | ||
| type: shell | ||
| params: | ||
| cmd: '$c = $env:ESPANSO_CLIPBOARD; if ($c) { try { [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($c.TrimEnd())) } catch { Write-Output "[Error: Clipboard does not contain valid Base64]" } }' |
There was a problem hiding this comment.
without it the user cant know what the problem is so i added the line Clipboard does not contain valid Base64
|
Copilot raises a few minor issues. Do you want to address those, or shall I go ahead and merge? |
|
yes please you can merge i think those are not issues one shows the user what the error is and others trim whitespace |
There is already base64 encoder and decoder, but it didn't support windows so i added mine which supports cross-platform using native OS tools (PowerShell for Windows, OpenSSL/Bash for Unix) and handles cases like empty clipboards or invalid input silently.