Skip to content

add base64 encode and decode which supports all os (can't do it) edit: Add base64-win package for native Windows support#225

Merged
smeech merged 5 commits into
espanso:mainfrom
kaniamutan14:main
May 16, 2026
Merged

Conversation

@kaniamutan14
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator

@smeech smeech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :b64e and :b64d matches implemented via shell vars 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.

Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Comment thread packages/base64-utils/0.1.0/package.yml Outdated
Comment thread packages/base64-utils/0.1.0/package.yml Outdated
@kaniamutan14 kaniamutan14 changed the title add base64 encode and decode which supports all os add base64 encode and decode which supports all os (can't do it) edit: Add base64-win package for native Windows support May 5, 2026
@kaniamutan14
Copy link
Copy Markdown
Contributor Author

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.
So only way I can think of is using python script, but windows doesn't come with python installed by default. Therefore, I have removed the cross-platform old package and updated to Windows package that uses PowerShell.

@kaniamutan14 kaniamutan14 requested a review from smeech May 5, 2026 09:59
Copy link
Copy Markdown
Collaborator

@smeech smeech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/base64-win/0.1.0/package.yml Outdated
Comment thread packages/base64-win/0.1.0/package.yml Outdated
Comment thread packages/base64-win/0.1.0/package.yml
Comment thread packages/base64-win/0.1.0/_manifest.yml
@kaniamutan14
Copy link
Copy Markdown
Contributor Author

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.

Changing the powershell to pwsh throws error not working, windows is not ignoring pwsh

19:00:07 [worker(14388)] [WARN] extension 'shell' on var: 'output' reported an error: could not execute command: '`$c = $env:ESPANSO_CLIPBOARD; if ($c) { [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($c.TrimEnd())) }`', error: '`program not found`'
19:00:07 [worker(14388)] [ERROR] error during rendering: rendering error

Caused by:
    could not execute command: '`$c = $env:ESPANSO_CLIPBOARD; if ($c) { [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($c.TrimEnd())) }`', error: '`program not found`'

@kaniamutan14 kaniamutan14 requested a review from smeech May 5, 2026 13:49
@smeech
Copy link
Copy Markdown
Collaborator

smeech commented May 6, 2026

Changing the powershell to pwsh throws error not working

Sorry - my mistake. pwsh is a valid option in Windows, so it won't be ignored.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

- 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]" } }'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without it the user cant know what the problem is so i added the line Clipboard does not contain valid Base64

@smeech
Copy link
Copy Markdown
Collaborator

smeech commented May 6, 2026

Copilot raises a few minor issues. Do you want to address those, or shall I go ahead and merge?

@kaniamutan14
Copy link
Copy Markdown
Contributor Author

yes please you can merge i think those are not issues one shows the user what the error is and others trim whitespace

@smeech smeech merged commit 69f1554 into espanso:main May 16, 2026
5 checks passed
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.

3 participants