简体   繁体   English

如何在PowerShell中为Ruby Index使用“ ri”而不是Remove-Item

[英]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? 当我输入“ ri”时,PowerShells的默认设置认为它是“删除项”的别名-如何使用ri命令调用“ R” uby“ I” ndex?

I tried cd'ing to the C:\\Ruby22 and entering: 我尝试cd到C:\\ Ruby22并输入:

rdoc --all --ri

This successfully installed gems and such, but ri remained 'remove item'. 这样就成功安装了gems等,但是ri仍然是“ remove item”。 I searched the web and the Ruby docs. 我搜索了网络和Ruby文档。 Having found this: http://samuelmullen.com/2012/01/up-and-running-with-ruby-interactive-ri/ I entered these into the powershell command line: 找到了这个: http : //samuelmullen.com/2012/01/up-and-running-with-ruby-interactive-ri/我将这些输入到powershell命令行中:

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

but when I enter "ri" the powershell still thinks it is "Remove-Item" 但是当我输入“ ri”时,powershell仍然认为它是“ Remove-Item”

As a temp measure, I duplicated these files: 作为临时措施,我复制了以下文件:

C:\\Ruby22\\bin\\ri C:\\ Ruby22 \\ BIN \\里

C:\\Ruby22\\bin\\ri.bat C:\\ Ruby22 \\ BIN \\ ri.bat

And renamed them to: 并将其重命名为:

C:\\Ruby22\\bin\\rr C:\\ Ruby22 \\ BIN \\ RR

C:\\Ruby22\\bin\\rr.bat C:\\ Ruby22 \\ BIN \\ rr.bat

Now I can enter "rr" in Powershell and get the functionality of the Ruby "r"uby "i"ndex. 现在,我可以在Powershell中输入“ rr”并获得Ruby“ r” uby“ i” ndex的功能。 Also, as noted in the comments, ri works for Ruby Index from the DOS prompt. 另外,如注释中所述,ri在DOS提示符下适用于Ruby Index。

How would I change the existing "ri" command in Powershell? 我将如何更改Powershell中现有的“ ri”命令?

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. 如果您的PowerShell禁用了脚本执行,那么要使PShell设置以“ ri”作为启动Ruby Index的命令而不是Remove-Item的别名的启动步骤,涉及到几个步骤。

1) Skip this step if you already have a PowerShell profile: 1)如果您已经拥有PowerShell配置文件,请跳过此步骤:

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 ...如果不这样做,该文件将在docs目录中生成:C:\\ Users \\ User_Name \\ Documents \\ WindowsPowerShell \\ Microsoft.PowerShell_profile.ps1

2) Then open your profile to edit it: 2)然后打开您的个人资料进行编辑:

notepad $profile

...if it's new, it should be blank. ...如果是新的,应该为空白。

3) Add the following line to it: 3)在其中添加以下行:

del alias:ri -force

4) Save the file, close notepad and load up the new profile settings with the command below: 4)保存文件,关闭记事本,并使用以下命令加载新的配置文件设置:

. $profile

... or simply close and open Powershell to apply the profile. ...或者只是关闭并打开Powershell以应用配置文件。

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: 注意:如果Powershell禁用了脚本执行,那么这当然是不够的...并且只有计算机上Administrators组的成员才能更改执行策略,因此:

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...) 1)使用“以管理员身份运行”选项启动PowerShell(我仅从“开始”菜单中的PowerShell图标子菜单中知道如何执行此操作)

2) Enable running unsigned scripts by entering: 2)通过输入以下命令启用运行中的未签名脚本:

set-executionpolicy remotesigned

This will allow running unsigned scripts that you write on your local computer and signed scripts from Internet. 这将允许您运行在本地计算机上编写的未签名脚本以及来自Internet的已签名脚本。 NOTE: from what little I understand of PowerS hell , setting the execution policy to "unrestricted" is strongly advised against. 注意:我对PowerS hell的了解很少,强烈建议将执行策略设置为“ unrestricted”。 Njoy! 恩乔伊!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM