From e9be3522f2622b0bfc0f2e20dd284dc3bd3de584 Mon Sep 17 00:00:00 2001 From: hogelog Date: Sat, 27 Dec 2025 19:32:55 +0900 Subject: [PATCH] Support copy command on windows and wsl --- lib/irb/command/copy.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/irb/command/copy.rb b/lib/irb/command/copy.rb index 93410b878..ef2c33c66 100644 --- a/lib/irb/command/copy.rb +++ b/lib/irb/command/copy.rb @@ -39,8 +39,12 @@ def execute(arg) private def copy_to_clipboard(text) - IO.popen(clipboard_program, 'w') do |io| - io.write(text) + if Gem.win_platform? + Kernel.system("powershell.exe", "-NoProfile", "-Command", "Set-Clipboard", "-Value", text) + else + IO.popen(clipboard_program, 'w') do |io| + io.write(text) + end end raise IOError.new("Copying to clipboard failed") unless $? == 0 @@ -54,6 +58,8 @@ def copy_to_clipboard(text) def clipboard_program @clipboard_program ||= if IRB.conf[:COPY_COMMAND] IRB.conf[:COPY_COMMAND] + elsif executable?("clip.exe") + "clip.exe" elsif executable?("pbcopy") "pbcopy" elsif executable?("xclip") @@ -66,7 +72,7 @@ def executable?(command) end def clipboard_available? - !!clipboard_program + Gem.win_platform? || !!clipboard_program end end end