Autocompleting ssh, rake, cap command parameters using PowerShell

I have mentioned in my previous posts that PowerShell has excellent and customizabme autocompletion support.
And some awesome plugins like powertab exist to take this functionality to another level.
Here is one easy way you can customize autocompletion easily by writing a couple of lines of code.

Open your PowerShell profile file (for help see here) and create a function with name "global:TabExpansion" in it.
This function basically overrides default autocompletion and sends your values to the prompt. For example for it to read your ssh files and display hosts in it the function would look something like this:

# customized tab expansion
function global:TabExpansion {
  param($line, $lastWord)
  
  if ($line -match 'ssh'){
    return cat C:\Users\Gaurav\.ssh\config | Select-String '^Host ' | % { if($_.Line -match "^Host ($lastword\S*)" ){ $matches[1] }}
  }
}

› Continue reading

Sunday, November 23rd, 2008 powerpoint, rails, ssh No Comments

Using RubyAmf for creating a CRUD application in Rails

CRUD applications can be easily created using Ruby on Rails as the backend and Flex as the frontend app using the XML format as demonstrated here.

Another way to create such applications is using the AMF protocol which is optimized for network communications and stores objects in binary format so consumes less bandwidth. Another compelling reason for using this library is that it doesn’t feel like a hack as it integrates very nicely with Rails :)

The Ruby port of this protocol known as RubyAmf can be downloaded from from here. More information about this protocol can be found here.

Lets start making the application.

 

Create a Rails Application:

   1: > rails amf_demo

This will create a rails application. Please note that I am using Rails 2.1.2 for this example and it is not tested on any other Rails version.

Generate a scaffold:

   1: > ruby script/generate scaffold blog_post title:string body:text

Create Tables and run Migrations:

   1: > rake db:migrate

   1: > rake db:create

› Continue reading

Wednesday, November 12th, 2008 adobe, crud, flex, open source, ruby on rails, user interface 8 Comments

Multiple ways to open PowerShell in the current Explorer window

These techniques are generic and can be used for other items like command prompt as well. A word of caution, everything given below involves fiddling with the registry so please backup your system’s registry or create a restore point before trying this out.

1) Adding it to Vista Explorer’s toolbar:

image

This is the most convenient one in my opinion, but requires most work to enable it.

Firstly, navigate to the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\FolderTypes\{7d49d726-3c21-4f05-99aa-fdc2c9474656}

› Continue reading

Context sensitive auto-completion using PowerShell, PowerTab and GIT

Powertab is an Awesome PowerShell TabExpansion extension. It extends the default PowerShell autocompletion and shows the results like:

image

The best part is that it is easily customizable.

One way to customize it is by editing it Tab Expansion database file which is located in your powershell profile directory:

TabExpansion.xml

› Continue reading

Monday, October 13th, 2008 GIT, powershell, ruby, vista, windows 5 Comments

Displaying GIT Branch on your PowerShell prompt

PowerShell is a command line shell like the command prompt (cmd.exe) but with a lot more features. It can be downloaded from here.

One of the features is that you can change the default prompt. Prompt can be changed by overriding the function with name “prompt”.

This function can be declared inside the PowerShell profile file which has the path:

C:\Users\Gaurav\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

If the file does not exist then you will need to create this file. Declaring the following function inside the profile file will change the prompt.

   1: function prompt {
   2:   return "prompt> "
   3: }

to:

image

› Continue reading

Sunday, October 12th, 2008 GIT, powershell, vista, windows 6 Comments