fix: Fixes typo in readme, strip quotes from output for all commands for consistency.

This commit is contained in:
2025-11-21 13:41:29 -05:00
parent 47f5a32ce8
commit 6e3d774366
2 changed files with 13 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ dotfiles repo.
```lua ```lua
vim.pack.add({ vim.pack.add({
{ src = "https://git.housh.dev/michael/shortenurl.nvm" }, { src = "https://git.housh.dev/michael/shortenurl.nvim" },
}) })
``` ```

View File

@@ -49,16 +49,24 @@ shortenurl.prompt = function(s)
return cmd return cmd
end end
-- Run the command and return the short url as a string.
local function runCmd(cmd)
local output = trimNewline(vim.fn.system(cmd))
if not output or output == "" then
return
end
return trimQuotes(output)
end
-- Convert url on the current line. -- Convert url on the current line.
shortenurl.convertUrl = function() shortenurl.convertUrl = function()
local url = get_url() local url = get_url()
local cmd = shortenurl.prompt(url) local cmd = shortenurl.prompt(url)
local output = trimNewline(vim.fn.system(cmd)) local output = runCmd(cmd)
if output == "" then if not output or output == "" then
print("Got empty output") print("Got empty output")
return return
end end
output = trimQuotes(output)
-- Replace occurence of the url with the shortened url. -- Replace occurence of the url with the shortened url.
vim.cmd(":%s/" .. vim.fn.escape(url, "/") .. "/" .. vim.fn.escape(output, "/")) vim.cmd(":%s/" .. vim.fn.escape(url, "/") .. "/" .. vim.fn.escape(output, "/"))
end end
@@ -67,7 +75,7 @@ end
shortenurl.convertFromClipboard = function() shortenurl.convertFromClipboard = function()
local url = trimNewline(vim.fn.system("wl-paste")) local url = trimNewline(vim.fn.system("wl-paste"))
local cmd = shortenurl.prompt(url) local cmd = shortenurl.prompt(url)
local output = trimNewline(vim.fn.system(cmd)) local output = runCmd(cmd)
if not output or output == "" then if not output or output == "" then
print("Got empty output") print("Got empty output")
return return