This is a post for those poor souls who are like me stuck for whatever reasons developing in Ruby on a Windows system. I don’t know about other people, but I spend a big chunk of my development time in console, particularly in irb or rails console: trying things out & debugging. Do you want your console to look like this? I’m not referring to the bright clown-like colors – this is for illustration purposes: but you can have colored irb console, transparency, auto completion, history and bunch of other goodies.
I’ve been trying these and combination of other tools for a while, but it finally came together when I found a pure ruby implementation of readline, called rb-readline developed by Luis Lavena . While it is not as fast readline library – the advatange is that is actually works on windows. For those who haven’t encountered there are some nasty bugs in readline lib on ruby 1.8.6 that prevent it from working properly in command line in conjunction with other libs. I.E. – text gets scrambled all over the screen, if the line is a little too long then you get problems with not being able to edit the line, the cursor keeps jumping, etc.
I’ve been getting by with default ruby config for a while, until I came across a gem called RawLine, which is intended to replace readline and gives you a bunch of other tools. For the life of me I can’t get it to work on my windows machine – it get’s my command line even worse. It looks like a lot of people thou have it working ok on their systems, so I’m guessing it has to do with me messing around with my system – I have too much different software and gems installed – so I would attribute it to problems on my machine. I just wanted to mention RawLine – as an alternative to my setup that works for some people. Without further ado here is my setup:
Optional: If you haven’t done so download Windows powershell. This is not required for this setup per se, but is an improvement on cmd.exe . Note that this will not replace default windows shell but will actually install this as a separate program. ( You already get it on Windows 2008 by default I believe) . It does things like *nix style pipelines for one and better file transfer.
Recommended: Get Console2! This is a nice wrapper for windows shell. It’s not a replacement for shell, all it does it lets you specify which shell you want to use and gives you a bunch of customization options: TABBED windows, transparency, you can pin windows to a top z-level on your screen or to a desktop, etc. You can point it to use either powershell or cmd, i.e. in the screenshot bellow I setup 3 most commonly used environments – 1st one is default Desktop – which opens up powershell in “c:\documents and settings\ngorbikoff\Desktop”Then you can just setup a regular windows shortcut (or 2 or 3) pointing to your console2 installation and specifying tab that you want to open, like so;
C:\Console2\Console.exe -t "Desktop"
I have a bunch of shortcuts in my QuickLaunch bar that point to my current projects.
Highly Recommended: In order to get this to work I had to replace default readline lib with the rb-readline as I mentioned above. You may try the following setup without doing this step if default C readline lib works fine on your machine – but I otherwise I would recommend installing rb-readline. It’s on rubyforge yet – which means you need to get it from github. Just download it. Unzip on desktop and run setup.rb . It will setup a separate rb-readline gem and replace default readline.bat .
Required: Installed these 2 gems or make sure they are installed
gem install wirble win32console
Required: Define “HOME” envirnoment. Go to System Properties > Advanced > Environment Variables. Click on new, enter HOME for the name and point it to the folder you want to be considered your home folder such as C:\Documents and Settings\ngorbikoff\ or whatever else you want. This is analogousto “~\” on *nix systems. Doesn’t matter where you point it as long as you know where. You can set it up as a system variable if you want to but not recommended. This step is needed so that shell can store your irb history or irb will keep failing.
Required: you need to tell irb to load all the libs required for the magic. I saw people recommending to put your settings into .irbrc file in your home folder (if you want this make sure that you create this file from some text editor as by default Windows will not allow you to create a file with a . as the first character in the filename. ). You can also combine this steop with step #5 and create ENV VAR call IRBRC and point it to the irbrc file somewhere. Unfortunately these approcahes interfere with MSYS – if you don’t use it don’t worry, but I gave you a fair warning. So what I did I just modified irb.bat in my ruby folder ( c:\ruby\bin\):
#!/usr/bin/env ruby
#
# irb.rb - intaractive ruby
# $Release Version: 0.9.5 $
# $Revision: 11708 $
# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
# by Keiju ISHITSUKA(kei...@ruby-lang.org)
#
require "irb"
require "win32console"
require 'wirble'
colors = Wirble::Colorize.colors.merge({
:comm => :white,
:refers => :yellow,
:class => :dark_gray,
:symbol => :light_red,
:symbol_prefix => :light_blue,
})
#you can configure this according to your taste - this is just to show you how easy it is.
# start wirble (with color)
# set the colors used by Wirble
Wirble::Colorize.colors = colors
Wirble.init
Wirble.colorize
#I picked this up on stackoverflow.com - by user: webmat
class Object
# Return only the methods not present on basic objects
def interesting_methods
(self.methods - Object.new.methods).sort
end
end
##make sure any pre you add goes before this line.
if __FILE__ == $0
IRB.start(__FILE__)
else
# check -e option
if /^-e$/ =~ $0
IRB.start(__FILE__)
else
IRB.setup(__FILE__)
end
end
Now you have autocompletion, colors, history and bunch of other goodies that will ease up life for you. As an added bonus this will work in your rails console. Also I’ve seen some pople define their color scheme using ANSI colors – you can if you want to but wirble does the job for me.
ABSOLUTELY REQUIRED: Enjoy! Enjoy I tell you!! muhahaha
Sane Ruby console on Windows or how to patch IRB to behave like *nix.
This is a post for those poor souls who are like me stuck for whatever reasons developing in Ruby on a Windows system. I don’t know about other people, but I spend a big chunk of my development time in console, particularly in irb or rails console: trying things out & debugging. Do you want your console to look like this? I’m not referring to the bright clown-like colors – this is for illustration purposes: but you can have colored irb console, transparency, auto completion, history and bunch of other goodies.
I’ve been trying these and combination of other tools for a while, but it finally came together when I found a pure ruby implementation of readline, called rb-readline developed by Luis Lavena . While it is not as fast readline library – the advatange is that is actually works on windows. For those who haven’t encountered there are some nasty bugs in readline lib on ruby 1.8.6 that prevent it from working properly in command line in conjunction with other libs. I.E. – text gets scrambled all over the screen, if the line is a little too long then you get problems with not being able to edit the line, the cursor keeps jumping, etc.
I’ve been getting by with default ruby config for a while, until I came across a gem called RawLine, which is intended to replace readline and gives you a bunch of other tools. For the life of me I can’t get it to work on my windows machine – it get’s my command line even worse. It looks like a lot of people thou have it working ok on their systems, so I’m guessing it has to do with me messing around with my system – I have too much different software and gems installed – so I would attribute it to problems on my machine. I just wanted to mention RawLine – as an alternative to my setup that works for some people. Without further ado here is my setup:
I have a bunch of shortcuts in my QuickLaunch bar that point to my current projects.
#!/usr/bin/env ruby # # irb.rb - intaractive ruby # $Release Version: 0.9.5 $ # $Revision: 11708 $ # $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $ # by Keiju ISHITSUKA(kei...@ruby-lang.org) # require "irb" require "win32console" require 'wirble' colors = Wirble::Colorize.colors.merge({ :comm => :white, :refers => :yellow, :class => :dark_gray, :symbol => :light_red, :symbol_prefix => :light_blue, }) #you can configure this according to your taste - this is just to show you how easy it is. # start wirble (with color) # set the colors used by Wirble Wirble::Colorize.colors = colors Wirble.init Wirble.colorize #I picked this up on stackoverflow.com - by user: webmat class Object # Return only the methods not present on basic objects def interesting_methods (self.methods - Object.new.methods).sort end end ##make sure any pre you add goes before this line. if __FILE__ == $0 IRB.start(__FILE__) else # check -e option if /^-e$/ =~ $0 IRB.start(__FILE__) else IRB.setup(__FILE__) end end