I have tried to get my head around PowerShell for a while, and I’ve read blogs by Scott Hanselman about PsReadline and PoshGit and decided to finally get on with it and use it properly.
This post is just a repository of my current setup.
Install PsGet if you don’t have it:
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
Install PsReadline:
Install-Module PsReadline
Install Git for Windows
http://git-scm.com/download/win
Install posh-git
Install-Module posh-git
Update the profile.ps1 file
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
# Load posh-git module from current directory
Import-Module PSReadLine
Import-Module posh-git
# If module is installed in a default location ($env:PSModulePath),
# use this instead (see about_Modules for more information):
# Import-Module posh-git
# Set up a simple prompt, adding the git prompt parts inside git repos
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
Write-Host($pwd.ProviderPath) -nonewline
Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE
return "> "
}
Enable-GitColors
Pop-Location
Start-SshAgent -Quiet
set-alias -name np -value "C:\Program Files\Sublime Text 2\sublime_text.exe"
function vsh() {
Write-Output "Opening first solution..."
$sln = (dir -in *.sln -r | Select -first 1)
Write-Output "Found $($sln.FullName)"
Invoke-Item $sln.FullName
}
function title($str) {
(get-host).ui.rawui.windowtitle = $str
}
function ga() {
Write-Output "Staging all changes..."
git add -A
git status
}
function gs() {
git status
}
function gsd() {
Write-Output "Pushing changes to subversion..."
git svn dcommit
}
function gsf() {
Write-Output "Checking subversion for recent changes..."
git svn fetch
}
function gco() {
param([switch]$amend, [switch]$a)
$argstr = $args -join ' '
$message = '"', $argstr, '"' -join ''
if ($amend -or $a) {
Write-Output "Amending previous commit with message: $message"
git commit -m $message --amend
} else {
Write-Output "Committing with message: $args"
git commit -m $message
}
}
function gca() {
$argstr = $args -join ' '
$message = '"', $argstr, '"' -join ''
Write-Output "Amending previous commit with message: $message"
git commit -m $message --amend
}
Links
- PsReadline: https://github.com/lzybkr/PSReadLine
- PsGet: http://psget.net/
- posh-git: https://github.com/dahlbyk/posh-git