Skip to content

Commit 4851ee3

Browse files
staticfloatStefanKarpinski
authored andcommitted
Automatically make use of reattach-to-user-namespace on OSX (#31653)
This dodges the namespace issues with clipboards on OSX. Read more about this at https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
1 parent dc8d2ec commit 4851ee3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

stdlib/InteractiveUtils/src/clipboard.jl

+21-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,30 @@
44

55
if Sys.isapple()
66
function clipboard(x)
7-
open(pipeline(`pbcopy`, stderr=stderr), "w") do io
7+
pbcopy_cmd = `pbcopy`
8+
9+
# OSX shells, especially when run within `tmux` or `screen`, can be
10+
# disconnected from the global shell namespace, which causes problems
11+
# with clipboards. Luckily, the `reattach-to-user-namespace` utility
12+
# dodges these issues quite nicely, so we automatically utilize it if
13+
# it is installed.
14+
if Sys.which("reattach-to-user-namespace") != nothing
15+
pbcopy_cmd = `reattach-to-user-namespace pbcopy`
16+
end
17+
18+
open(pipeline(pbcopy_cmd, stderr=stderr), "w") do io
819
print(io, x)
920
end
1021
end
11-
clipboard() = read(`pbpaste`, String)
22+
function clipboard()
23+
pbpaste_cmd = `pbpaste`
24+
25+
# See above comment in `clipboard(x)`
26+
if Sys.which("reattach-to-user-namespace") != nothing
27+
pbcopy_cmd = `reattach-to-user-namespace pbpaste`
28+
end
29+
read(pbpaste_cmd, String)
30+
end
1231

1332
elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
1433
_clipboardcmd = nothing

0 commit comments

Comments
 (0)