Skip to content

Commit 84d95c4

Browse files
committed
feat: replace pngpaste with pbctl
1 parent 08a02e1 commit 84d95c4

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ https://github.com/HakonHarnes/img-clip.nvim/assets/89907156/ab4edc10-d296-4532-
2020
## 🔧 Requirements
2121

2222
- **Linux:** [xclip](https://github.com/astrand/xclip) (x11) or [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (wayland)
23-
- **MacOS:** [pngpaste](https://github.com/jcsalterego/pngpaste)
23+
- **MacOS:** [pbctl](https://github.com/hakonharnes/pbctl)
2424
- **Windows:** No additional requirements
2525

2626
> [!IMPORTANT]

doc/img-clip.nvim.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ FEATURES *img-clip.nvim-img-clip.nvim-features*
4040
REQUIREMENTS *img-clip.nvim-img-clip.nvim-requirements*
4141

4242
- **Linux:** xclip <https://github.com/astrand/xclip> (x11) or wl-clipboard <https://github.com/bugaevc/wl-clipboard> (wayland)
43-
- **MacOS:** pngpaste <https://github.com/jcsalterego/pngpaste>
43+
- **MacOS:** pbctl <https://github.com/hakonharnes/pbctl>
4444
- **Windows:** No additional requirements
4545

4646

lua/img-clip/clipboard.lua

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ M.get_clip_cmd = function()
1616

1717
-- MacOS
1818
elseif util.has("mac") then
19-
if util.executable("pngpaste") then
19+
if util.executable("pbctl") then
20+
M.clip_cmd = "pbctl"
21+
elseif util.executable("pngpaste") then
2022
M.clip_cmd = "pngpaste"
2123
end
2224

@@ -48,8 +50,15 @@ M.content_is_image = function()
4850
local output = util.execute("wl-paste --list-types")
4951
return output ~= nil and output:find("image/png") ~= nil
5052

53+
-- MacOS (pbctl)
54+
elseif cmd == "pbctl" then
55+
local output, exit_code = util.execute("pbctl types")
56+
-- print()
57+
return output ~= nil and output:find("image/") ~= nil
58+
5159
-- MacOS (pngpaste)
5260
elseif cmd == "pngpaste" then
61+
util.warn("`pngpaste` is deprecated. Install `pbctl` instead")
5362
local _, exit_code = util.execute("pngpaste -")
5463
return exit_code == 0
5564

@@ -83,6 +92,12 @@ M.save_image = function(file_path)
8392
local _, exit_code = util.execute(command)
8493
return exit_code == 0
8594

95+
-- MacOS (pbctl)
96+
elseif cmd == "pbctl" then
97+
local command = string.format('pbctl paste %s> "%s"', process_cmd:gsub("%%", "%%%%"), file_path)
98+
local _, exit_code = util.execute(command)
99+
return exit_code == 0
100+
86101
-- MacOS (pngpaste)
87102
elseif cmd == "pngpaste" then
88103
local command = string.format('pngpaste - %s> "%s"', process_cmd:gsub("%%", "%%%%"), file_path)
@@ -123,7 +138,14 @@ M.get_content = function()
123138
return output:match("^[^\n]+")
124139
end
125140

126-
-- MacOS
141+
-- MacOS (pbctl)
142+
elseif cmd == "pbctl" then
143+
local output, exit_code = util.execute("pbctl paste")
144+
if exit_code == 0 then
145+
return output:match("^[^\n]+")
146+
end
147+
148+
-- MacOS (pngpaste)
127149
elseif cmd == "pngpaste" then
128150
local output, exit_code = util.execute("pbpaste")
129151
if exit_code == 0 then
@@ -163,6 +185,13 @@ M.get_base64_encoded_image = function()
163185
return output
164186
end
165187

188+
-- MacOS (pbctl)
189+
elseif cmd == "pbctl" then
190+
local output, exit_code = util.execute("pbctl paste " .. process_cmd .. "| base64 | tr -d '\n'")
191+
if exit_code == 0 then
192+
return output
193+
end
194+
166195
-- MacOS (pngpaste)
167196
elseif cmd == "pngpaste" then
168197
local output, exit_code = util.execute("pngpaste - " .. process_cmd .. "| base64 | tr -d '\n'")

lua/img-clip/health.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local M = {}
55
local ok = vim.health.ok or vim.health.report_ok
66
local start = vim.health.start or vim.health.report_start
77
local error = vim.health.error or vim.health.report_error
8+
local warn = vim.health.warn or vim.health.report_warn
89

910
M.check = function()
1011
start("img-clip.nvim")
@@ -27,10 +28,12 @@ M.check = function()
2728

2829
-- MacOS
2930
elseif util.has("mac") then
30-
if util.executable("pngpaste") then
31-
ok("`pngpaste` is installed")
31+
if util.executable("pbctl") then
32+
ok("`pbctl` is installed")
33+
elseif util.executable("pngpaste") then
34+
warn("`pngpaste` is deprecated. Install `pbctl` instead")
3235
else
33-
error("`pngpaste` is not installed")
36+
error("`pbctl` is not installed")
3437
end
3538

3639
-- Windows

vimdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ https://github.com/HakonHarnes/img-clip.nvim/assets/89907156/ab4edc10-d296-4532-
2020
## 🔧 Requirements
2121

2222
- **Linux:** [xclip](https://github.com/astrand/xclip) (x11) or [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (wayland)
23-
- **MacOS:** [pngpaste](https://github.com/jcsalterego/pngpaste)
23+
- **MacOS:** [pbctl](https://github.com/hakonharnes/pbctl)
2424
- **Windows:** No additional requirements
2525

2626
> [!IMPORTANT]

0 commit comments

Comments
 (0)