4

I'm using gitbash ver 2.9.0, 64-bit, on Windows 7. It uses mintty version 2.0.3.

The gitbash shell most of the time seems to work fine. You can use the arrow keys, etc, as with any bash shell and they perform as expected, being able to scroll through prior commands, etc.

However, when using irb or rails console (which runs irb) it is very flakey. Rather than scroll through prior commands, the up arrow just moves the cursor up the screen and enters what are probably up arrow control codes into the input buffer. In addition, irb must be exited with ^C rather than ^D. The ^D does nothing except go into the input buffer (if I type ^D then ^C, it exits irb because of the ^C, then exits gitbash because of the ^D).

I can't find much in the way of other reports on this issue and what little I've found is somewhat old. I've tried the solutions shown in this post: Backspace and arrow keys aren't working in IRB (Git Bash console) on windows machine, but they haven't changed the behavior at all.

Has anyone found a legitimate solution to this problem?

Community
  • 1
  • 1
lurker
  • 56,987
  • 9
  • 69
  • 103
  • What about `ruby -S irb`? – VonC Jul 02 '16 at 08:08
  • Also http://gorbikoff.com/tag/ruby-on-windows/ (not git bash though) It includes http://stackoverflow.com/a/10253338/6309 – VonC Jul 02 '16 at 08:10
  • 1
    @VonC I had already stumbled upon `ruby -S irb` and that doesn't work either. It has exactly the same issue. I may, in the long run, have to resort to something much more drastic as in your link, but I don't understand why gitbash can't work. This seems like such a normal use case. I thought about trying to find a version of `rlwrap` that works on gitbash for Windows... – lurker Jul 02 '16 at 10:13
  • 1
    Have the same issues with Git for Windows v2.8.1. When running `$ ruby -v` it recognizes the installed Ruby: `ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]`. When hitting `irb` it sucks: `Switch to inspect mode.` No problem in a standard Windows command prompt (Windows + R + cmd). – belgoros Oct 06 '16 at 13:11

3 Answers3

4

The git bash terminal emulator (mintty) does not really get along with windows console programs. So you might want to look for a wrapper that runs a console program (e.g. irb.cmd, python.exe, etc) then interfaces with the git bash.

Concretely, once you have wintpy.exe and irb in your $PATH of the git bash, you can set an alias as such

$ alias irb='winpty "$(which irb).cmd"'

NOTE that there are two irbs shipped with the default ruby windows installer: a good old bash script irb and a windows batch script irb.cmd. Only the latter works for me with the winpty trick.

krim
  • 138
  • 1
  • 6
0

Many Thanks to krim! After learning the add-.cmd-trick, I tried the same for rails console bin/rails c) and ended with a ~/scripts/rails_ bash script:

#!/usr/bin/bash
winpty rails.bat "$@"

So I can do now rails_ c or rails_ db etc.

0

In addition to krim's answer, you can put

alias irb='winpty "$(which irb).cmd"'
alias rails='winpty "$(which rails).bat"'

in a text file and save it as .bashrc in your home directory %homepath%. Then you won't have to type it in the console every time you start up git bash.

Source: Comment on https://fool-dev.com/switch-to-inspect-mode-on-gitbash-in-windows/

Levvine
  • 1
  • 1