powershell

Posted on October 06, 2010 tools

configure startup.

c:/users/mkhan/documents/windowspowershell/profile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	# Load posh-git module from current directory
	Import-Module d:\scripts\posh-git

 	# Set up a simple prompt, adding the git prompt parts inside git repos
	function prompt {
		$host.UI.RawUi.WindowTitle = get_current_folder
		return write_prompt(get_unix_style_path);
	}
	function get_current_folder() {
		$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries)
		if($pathbits.length -eq 1) {
		  return   $pathbits[0] + "\";
		} 
		return   $pathbits[$pathbits.length - 1]
	}
	function get_unix_style_path() {
		return '/' + ([string]$pwd).replace('\','/').replace(':','').tolower()
	}
	function write_prompt($path) {
		Write-Host( ($env:username + '@' + [System.Environment]::MachineName + ' ' + $path).tolower() ) -foregroundcolor Green
			
		$Global:GitStatus = Get-GitStatus
		Write-GitStatus $GitStatus
		return "$ " 
	}

	if(-not (Test-Path Function:\DefaultTabExpansion)) {
		Rename-Item Function:\TabExpansion DefaultTabExpansion
	}

 	# Set up tab expansion and include git expansion
	function TabExpansion($line, $lastWord) {
		$lastBlock = [regex]::Split($line, '[|;]')[-1]
		
		switch -regex ($lastBlock) {
			# Execute git tab completion for all git-related commands
			'git (.*)' { GitTabExpansion $lastBlock }
			# Fall back on existing tab expansion
			default { DefaultTabExpansion $line $lastWord }
		}
	}

	Enable-GitColors