From 65040fc1421fb671dbfea110fcb437ae3078946a Mon Sep 17 00:00:00 2001 From: Paul Seelman Date: Thu, 11 Feb 2021 13:36:31 -0700 Subject: [PATCH] Add Fish PATH Hex Converter --- Boop/Boop/scripts/FishHexPathConverter.js | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Boop/Boop/scripts/FishHexPathConverter.js diff --git a/Boop/Boop/scripts/FishHexPathConverter.js b/Boop/Boop/scripts/FishHexPathConverter.js new file mode 100644 index 00000000..7ce9c567 --- /dev/null +++ b/Boop/Boop/scripts/FishHexPathConverter.js @@ -0,0 +1,41 @@ +/** +{ + "api": 1, + "name": "Fish PATH Hex Converter", + "description": "Takes a regular PATH and converts it to use hex ascii characters ex. -L/usr/local/opt/openssl@1.1/lib -> \x2dL/usr/local/opt/openssl\x401\x2e1/lib"", + "author": "Paul Seelman", + "icon": "broom", + "tags": "fish_user_paths, fish, hex, ascii, path, var" +} +**/ +function convert(string) { + var chars = string.split(""); + var dict = { + " ": ":", + "%": "25", + "&": "26", + "+": "2b", + "-": "2d", + ".": "2e", + "*": "2a", + ":": "3a", + "@": "40", + ";": "3b" + }; + + for (var i = chars.length - 1; i >= 0; i--) { + var char = chars[i]; + var hex = dict[char]; + + if (hex !== undefined) { + var slash_x = '\\x'; + chars[i] = slash_x.concat(hex); + } + } + + return chars.join(""); +} + +function main(input) { + input.text = convert(input.text); +}