Mr. Kennedy Mr. Kennedy - 3 months ago 8
PowerShell Question

How to use "ri" in PowerShell for Ruby Index instead of Remove-Item

When I enter "ri" PowerShells default set-up thinks it is an alias for "Remove-Item" - how do I use the ri command to invoke the "R"uby "I"ndex?

I tried cd'ing to the C:\Ruby22 and entering:

rdoc --all --ri


This successfully installed gems and such, but ri remained 'remove item'. I searched the web and the Ruby docs. Having found this: http://samuelmullen.com/2012/01/up-and-running-with-ruby-interactive-ri/ I entered these into the powershell command line:

gem install rdoc rdoc-data
rdoc-data --install


but when I enter "ri" the powershell still thinks it is "Remove-Item"

As a temp measure, I duplicated these files:

C:\Ruby22\bin\ri

C:\Ruby22\bin\ri.bat

And renamed them to:

C:\Ruby22\bin\rr

C:\Ruby22\bin\rr.bat

Now I can enter "rr" in Powershell and get the functionality of the Ruby "r"uby "i"ndex. Also, as noted in the comments, ri works for Ruby Index from the DOS prompt.

How would I change the existing "ri" command in Powershell?

Answer

If your PowerShell has script execution disabled, there's a couple steps involved in getting PShell set-up to launch with "ri" as the command to start the Ruby Index instead of as an alias for Remove-Item.

1) Skip this step if you already have a PowerShell profile:

New-Item $profile -force -itemtype file

...if you don't, this file will get generated in your docs directory: C:\Users\User_Name\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

2) Then open your profile to edit it:

notepad $profile

...if it's new, it should be blank.

3) Add the following line to it:

del alias:ri -force

4) Save the file, close notepad and load up the new profile settings with the command below:

. $profile

... or simply close and open Powershell to apply the profile.

NOTE: This, of course, is insufficient if Powershell has script execution disabled... and only members of the Administrators group on the computer can change the execution policy, so:

1) Launch PowerShell with the "Run as Administrator" option (I only know how to do this from the PowerShell icon sub-menu in the Start Menu...)

2) Enable running unsigned scripts by entering:

set-executionpolicy remotesigned

This will allow running unsigned scripts that you write on your local computer and signed scripts from Internet. NOTE: from what little I understand of PowerShell, setting the execution policy to "unrestricted" is strongly advised against. Njoy!

Comments