Skip to content

Commit

Permalink
fix: use pbpaste for mac
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonHarnes committed Mar 1, 2024
1 parent ddddd2d commit 6e2940f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lua/img-clip/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@ M.get_content = function()
return output:match("^[^\n]+")
end

-- MacOS (pngpaste)
elseif cmd == "pngpaste" then
local output, exit_code = util.execute("pngpaste -")
-- MacOS
elseif cmd == "pngpaste" or cmd == "osascript" then
local output, exit_code = util.execute("pbpaste")
if exit_code == 0 then
return output:match("^[^\n]+")
end

-- MacOS (osascript)
elseif cmd == "osascript" then
local output, exit_code = util.execute([[osascript -e 'get the clipboard as text']])
output, exit_code = util.execute([[osascript -e 'get the clipboard as text']])
if exit_code == 0 then
return output:match("^[^\n]+")
end
Expand Down
8 changes: 4 additions & 4 deletions lua/img-clip/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ local M = {}

M.verbose = true

M.executable = function(command)
return vim.fn.executable(command) == 1
end

---@param input_cmd string
---@return string | nil output
---@return number exit_code
Expand Down Expand Up @@ -50,6 +46,10 @@ M.execute = function(input_cmd)
return output, exit_code
end

M.executable = function(command)
return vim.fn.executable(command) == 1
end

---@param feature string
M.has = function(feature)
return vim.fn.has(feature) == 1
Expand Down

0 comments on commit 6e2940f

Please sign in to comment.