Geek Noise
Rants, rambles, news and notes by Peter Provost
02

PowerShell Function: go

Wednesday, 2 August 2006 01:51 by Peter Provost

Yesterday I was in a meeting with Fernando Simonazzi when he mentioned how much he has been falling in love with PowerShell. We talked for a bit about how cool the object pipeline is and then he said, you know what I've been thinking about writing is a "go" script that will jump to a set of named locations.

What a great idea. I couldn't leave well enough alone, this morning, so I wrote one and put it into my profile. Here it is:

go.ps1:

	if( $GLOBAL:go_locations -eq $null ) {
	$GLOBAL:go_locations = @{}
	}
	function go( [string] $location ) {
	if( $go_locations.ContainsKey($location) ) {
	set-location $go_locations[$location]
	} else {
	write-output "The following locations are defined:"
	write-output $go_locations
	}
	}
	

To use it, you can simply put this at the bottom of your profile script:

	. ~/scripts/go.ps1
	$go_locations.Add("home", "~")
	$go_locations.Add("dl", "~\Desktop\Downloads")
	$go_locations.Add("dev", "C:\Development")
	$go_locations.Add("scripts", "~\scripts")
	

And now you can do this:

	PS1> go home
	

Eventually, I will merge this into the "cd" script that Brad Wilson and I have been tweaking to really make directory navigation a breeze.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Technology
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed