On the fly URL Encode/Decode with Espanso
You probably know Espanso, if not go for it because it’s so useful! Espanso is a free and open source software, written in Rust. It detects when you type a keyword and replaces it based on defined rules while you're typing.
Today I added two new rules to my Espanso config to encode and decode URLs from clipboard. You only need to copy a text or a URL, and write :enc:
to perform URL encoding; or write :dec:
for URL decoding. If you use Linux it’s even easier as you only need to select text or URLs to copy them.
It’s so useful for people who work decode/encode lots of URLs during a day; pentester, bug hunters, and web developers. You can add it to your Espanso matches using the following instructions. Note that you need Python to be installed on your OS.
Linux
On Linux add the following to ~/.config/espanso/match/base.yml
.
- trigger: ":enc:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "xclip -o -sel c | python -c 'import urllib.parse as ul; print(ul.quote_plus(open(0).read()))'"
- trigger: ":dec:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "xclip -o -sel c | python -c 'import urllib.parse as ul; print(ul.unquote_plus(open(0).read()))'"
It’s for X, on Wayland you need to use an xclip
alternative (e.g., wl-clipboard).
MacOS
On MacOs add the following to ~/Library/Application Support/espanso/match/base.yml
. Not tested.
- trigger: ":enc:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "pbpaste | python -c 'import urllib.parse as ul; print(ul.quote_plus(open(0).read()))'"
- trigger: ":dec:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "pbpaste | python -c 'import urllib.parse as ul; print(ul.unquote_plus(open(0).read()))'"
Windows
On Windows add the following to %USERPROFILE%\AppData\Roaming\espanso\match\base.yml
. Not tested.
- trigger: ":enc:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "powershell.exe -command \"Get-Clipboard | python -c 'import urllib.parse as ul; print(ul.quote_plus(open(0).read()))'\""
- trigger: ":dec:"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "powershell.exe -command \"Get-Clipboard | python -c 'import urllib.parse as ul; print(ul.unquote_plus(open(0).read()))'\""
And yes, we can add more cool and useful decoders and encoders for Base64 for example, or HTML entities. Espanso is a cool and super useful tool that enhances productivity.