From e9be3522f2622b0bfc0f2e20dd284dc3bd3de584 Mon Sep 17 00:00:00 2001 From: hogelog Date: Sat, 27 Dec 2025 19:32:55 +0900 Subject: [PATCH 1/3] 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 From d97375e96d70ee909609324767d23d001e06af1e Mon Sep 17 00:00:00 2001 From: hogelog Date: Tue, 30 Dec 2025 01:01:56 +0900 Subject: [PATCH 2/3] Don't use Gem.win_platform? --- lib/irb/command/copy.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/irb/command/copy.rb b/lib/irb/command/copy.rb index ef2c33c66..c02d45256 100644 --- a/lib/irb/command/copy.rb +++ b/lib/irb/command/copy.rb @@ -39,7 +39,7 @@ def execute(arg) private def copy_to_clipboard(text) - if Gem.win_platform? + if windows? Kernel.system("powershell.exe", "-NoProfile", "-Command", "Set-Clipboard", "-Value", text) else IO.popen(clipboard_program, 'w') do |io| @@ -72,7 +72,11 @@ def executable?(command) end def clipboard_available? - Gem.win_platform? || !!clipboard_program + windows? || !!clipboard_program + end + + def windows? + /mingw|mswin/.match?(RUBY_PLATFORM) end end end From e90574a4e233e8bbd9e89bf9e1f05d555d81677c Mon Sep 17 00:00:00 2001 From: hogelog Date: Tue, 30 Dec 2025 01:03:35 +0900 Subject: [PATCH 3/3] Stop the workaround for windows environment --- lib/irb/command/copy.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/irb/command/copy.rb b/lib/irb/command/copy.rb index c02d45256..6b3bcc651 100644 --- a/lib/irb/command/copy.rb +++ b/lib/irb/command/copy.rb @@ -39,12 +39,8 @@ def execute(arg) private def copy_to_clipboard(text) - if windows? - Kernel.system("powershell.exe", "-NoProfile", "-Command", "Set-Clipboard", "-Value", text) - else - IO.popen(clipboard_program, 'w') do |io| - io.write(text) - end + IO.popen(clipboard_program, 'w') do |io| + io.write(text) end raise IOError.new("Copying to clipboard failed") unless $? == 0 @@ -68,7 +64,11 @@ def clipboard_program end def executable?(command) - system("which #{command} > /dev/null 2>&1") + if windows? + system("where #{command} > NUL 2>&1") + else + system("which #{command} > /dev/null 2>&1") + end end def clipboard_available?