diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/aotrix/plugins/build.lua | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/lua/aotrix/plugins/build.lua b/lua/aotrix/plugins/build.lua index e447414..f40e6b9 100644 --- a/lua/aotrix/plugins/build.lua +++ b/lua/aotrix/plugins/build.lua @@ -1,12 +1,46 @@ +local toBase64Url = function(text) + local binaryToBase64 = function(binary) + local alphabet = { + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", + "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", + "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_" + }; + return alphabet[binary + 1] + end + local output = "" + local size = (string.len(text) - (string.len(text) % 3)) / 3 + for i = 1, size do + local first_byte = string.byte(text, 3 * (i - 1) + 1) + local second_byte = string.byte(text, 3 * (i - 1) + 2); + local third_byte = string.byte(text, 3 * (i - 1) + 3); + + local first_base64 = first_byte >> 2 + local second_base64 = ((first_byte & 3) << 4) | (second_byte >> 4) + local third_base64 = ((second_byte & 15) << 2) | + ((third_byte & 192) >> 6) + local fourth_base64 = third_byte & 63 + + output = output .. binaryToBase64(first_base64) .. + binaryToBase64(second_base64) .. + binaryToBase64(third_base64) .. + binaryToBase64(fourth_base64) + + end + return output +end + +local data_path = vim.fn.stdpath("data") +local PERSONAL_COMMAND_JSON_PATH = data_path .. "/" .. + toBase64Url(vim.fn.getcwd()) .. ".json" + return { "MunifTanjim/nui.nvim", config = function() local COMMANDS = {} local CURRENT_COMMAND = nil - local data_path = vim.fn.stdpath("data") - local PERSONAL_COMMAND_JSON_PATH = data_path .. - "/personal_commands.json" - + --- ---@param command string|nil ---@return nil local executeCommandInTerminal = function(command) @@ -25,13 +59,11 @@ return { end local readJsonFromFile = function(filePath) - local file, error = io.open(filePath, 'r') + local file, _ = io.open(filePath, 'r') if file ~= nil then local content = file:read("*a") local decoded_json = vim.json.decode(content) return decoded_json - else - print("Error in readJsonFromFile: " .. error) end return nil end |
