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
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
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.
shortenurl.convertUrl = function()
local url = get_url()
local cmd = shortenurl.prompt(url)
local output = trimNewline(vim.fn.system(cmd))
if output == "" then
local output = runCmd(cmd)
if not output or output == "" then
print("Got empty output")
return
end
output = trimQuotes(output)
-- Replace occurence of the url with the shortened url.
vim.cmd(":%s/" .. vim.fn.escape(url, "/") .. "/" .. vim.fn.escape(output, "/"))
end
@@ -67,7 +75,7 @@ end
shortenurl.convertFromClipboard = function()
local url = trimNewline(vim.fn.system("wl-paste"))
local cmd = shortenurl.prompt(url)
local output = trimNewline(vim.fn.system(cmd))
local output = runCmd(cmd)
if not output or output == "" then
print("Got empty output")
return