Skip to content

Instantly share code, notes, and snippets.

@dontangg
Last active October 3, 2015 08:08
Show Gist options
  • Save dontangg/2422329 to your computer and use it in GitHub Desktop.
Save dontangg/2422329 to your computer and use it in GitHub Desktop.
My powershell setup
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
# Load posh-git module from current directory
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
function Write-Git-Branch {
$st = git status | tail -n 1
if($st -ne $null) {
Write-Host(" on ") -nonewline
$branch = (git symbolic-ref -q HEAD) -replace 'refs/heads/',''
if($branch -eq "") { $branch = "detached HEAD" }
if($st -eq "nothing to commit (working directory clean)") {
Write-Host($branch) -nonewline -ForegroundColor Green
}
else {
Write-Host($branch) -nonewline -ForegroundColor Red
}
Write-Git-NeedsPush
}
}
function Write-Git-NeedsPush {
$unpushed = git cherry -v
if ($unpushed -ne $null) {
Write-Host(" with ") -nonewline
Write-Host("unpushed") -nonewline -ForegroundColor Magenta
}
}
# Set up a simple prompt, adding the git prompt parts inside git repos
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
Write-Host("`nin ") -nonewline
Write-Host($pwd) -nonewline -ForegroundColor Cyan
# Git Prompt
Write-Git-Branch
Write-Host('')
$LASTEXITCODE = $realLASTEXITCODE
return "> "
}
if(Test-Path Function:\TabExpansion) {
$teBackup = 'posh-git_DefaultTabExpansion'
if(!(Test-Path Function:\$teBackup)) {
Rename-Item Function:\TabExpansion $teBackup
}
# Set up tab expansion and include git expansion
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
switch -regex ($lastBlock) {
# Execute git tab completion for all git-related commands
"^$(Get-AliasPattern git) (.*)" { GitTabExpansion $lastBlock }
"^$(Get-AliasPattern tgit) (.*)" { GitTabExpansion $lastBlock }
# Fall back on existing tab expansion
default { & $teBackup $line $lastWord }
}
}
}
Enable-GitColors
Pop-Location
Start-SshAgent -Quiet
$env:path += ";c:\users\rdwilson\bin;c:\Program Files (x86)\Git\bin;c:\Program Files\SlikSvn\bin;c:\Scripts"
# Load posh-git profile (https://github.com/dahlbyk/posh-git)
. 'C:\Users\rdwilson\Documents\WindowsPowerShell\Modules\posh-git\profile.ps1'
# To get git to not ask for you password
# * cd ~/.ssh
# * ssh-add id_rsa
function gl { git pull --prune $args }
function glog { git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative }
function gp { git push origin HEAD $args }
function gd { git diff $args }
function gs($o) { git status -sb $args }
function np($package) { NuGet push $package -source http://packages -apikey 95B3CF54-1B3E-4C00-A7E2-F1AF772E9262 }
function test() {
"The number of parameters passed in p is $($p.Count)"
$i = 0
foreach ($arg in $args) { echo "The $i parameter in p is $arg"; $i++ }
git status -sb $args
}
function which {
($Env:Path).Split(";") | where {Test-Path $_} | Get-ChildItem -filter ("{0}.*" -f $args[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment