Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
Last active June 13, 2022 07:12
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cloudRoutine/87c17655405cd8b1eac7 to your computer and use it in GitHub Desktop.
Save cloudRoutine/87c17655405cd8b1eac7 to your computer and use it in GitHub Desktop.
Powershell Profile for use with Cmder
# If this script is throwing an error near a Unicode symbol try resaving the file as UTF-8 with BOM
$psmodules = ";~\Documents\WindowsPowerShell\Modules"
# sometimes the module paths has been fucked before posh loads, but that won't stop us
$env:PSModulePath = $env:PSModulePath + $psmodules
# Set the OutputEncoding to Unicode so that the λ renders properly
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# The Host check is necessary if you don't want these to load in `Windows PowerShell ISE Host`
if ($host.Name -eq 'ConsoleHost')
{
Import-Module psget
Import-Module PSReadline
Import-Module posh-ssh
Import-Module posh-git
Import-Module powerls
Import-Module PSColor
Import-Module TabExpansion++
# Load all of the scripts in the script repository
select "${psmodules}\script-repo\*.ps1" | %{.$_}
Set-PSReadlineKeyHandler -Key Ctrl+Delete -Function KillWord
Set-PSReadlineKeyHandler -Key Ctrl+Backspace -Function BackwardKillWord
Set-PSReadlineKeyHandler -Key Shift+Backspace -Function BackwardKillWord
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Key Tab -Function Complete
$Host.PrivateData.ErrorBackgroundColor = $Host.UI.RawUI.BackgroundColor
$Host.PrivateData.WarningBackgroundColor = $Host.UI.RawUI.BackgroundColor
$Host.PrivateData.VerboseBackgroundColor = $Host.UI.RawUI.BackgroundColor
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
function prompt
{
$g = [ConsoleColor]::Green
$h = [ConsoleColor]::DarkGray
$realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
$loc = $(Get-Location)
Write-Host `r
Write-Host $loc -n -f $g
Write-VcsStatus
Write-Host `r
Write-Host "λ»" -n -f $h
$global:LASTEXITCODE = $realLASTEXITCODE
Return ' '
}
Pop-Location
Start-SshAgent -Quiet
}
# ┌ ┐
# posh management
# └ ┘
function poshver { $PSVersionTable.PSVersion | write-host }
# Call with `. rlp` to reload profile
function rprof { write-host " `n Δ Reloading Profile... " -foregroundcolor darkgreen
. $profile
}
function rpath { write-host " `n Δ Reloading Environment Variables from PATH... " -foregroundcolor darkgreen
$env:Path = ""
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
[System.Environment]::GetEnvironmentVariable("Path","User")
}
function delfr { Param($target)
del $target -force -recurse
}
function dir { Param($dirName)
ni $dirName -type directory
}
Set-Alias github "~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc\GitHub.appref-ms"
function repos {cd "~\Github" }
# . subl loads the current directory in sublime
Set-Alias subl "~\Portable Software\Sublime Text\sublime_text.exe"
function Edit-Profile { subl $Profile }
Set-Alias ep Edit-Profile
Set-Alias open Invoke-Item
function pics { open '~\Pictures' }
function books { open '~\Ebooks' }
function progproj { cd '~\Programming Projects' }
function progwrite { cd '~\Programming Writing' }
function portsoft { open '~\Portable Software' }
# ┌ ┐
# F# DEV
# └ ┘
Set-Alias msbuild4 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
Set-Alias msbuild12 "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
Set-Alias vs14 "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"
function load-templates { write-host " `Δ loading visual studio 2015 templates from - C:\Users\Jared\Documents\Visual Studio 2015\Templates " -foregroundcolor darkgreen
vs14 /installvstemplates }
function scaffoldfs { Param($projectName)
git clone "https://github.com/fsprojects/ProjectScaffold.git"
cd ProjectScaffold
echo "`nRemoving original .git folder..."
Remove-Item ".git" -force -recurse
echo " done.`n"
cd ..
if ($projectName -eq "") {$projectName = "fsharp_oss_project"}
echo "`nRenaming project $projectName `n"
Rename-Item ProjectScaffold $projectName
cd $projectName
git init
& ".\build.cmd"
}
function scaffold-into { ($directory)
mkdir "temp_scaffold" | cd "temp_scaffold"
echo "`n Cloning Project Scaffold"
git clone "https://github.com/fsprojects/ProjectScaffold.git"
cd ProjectScaffold | Remove-Item ".git" -force -recurse
cd .. | echo "`n Copying Scaffold files into " + $directory
Copy-Item ProjectScaffold\* $directory
cd ..
echo "`n Cleaning up temporary scaffold files " + $directory
Remove-Item "temp_scaffold" -Force -Recurse
echo "`n COMPLETE! You can run the Scaffold setup with '.\build.cmd' "
}
# ┌ ┐
# GIT HELPERS
# └ ┘
function glog { git $args --no-pager log --oneline --all --graph --decorate `
--pretty=format:"%C(yellow)%h%Creset | %C(magenta)%ad%Creset | %Cred%d%Creset %Creset%s %C(green dim) < %cn > %Creset " `
--date=short }
function update { git pull --rebase --prune $@
git submodule update --init --recursive
}
function save { git add -A
git commit -m 'SAVEPOINT'
}
function wipe { git add -u
git commit -m "WIPE"
}
function amend { git commit -a --amend --no-edit }
function amend-with
{ Param($commitMessage)
git commit -a --amend -m $commitMessage }
function undo { reset HEAD~1 --mixed }
function softreset { git reset --soft HEAD~1 }
function wash { git add -A
git commit -qm 'WIPE SAVEPOINT'
git reset HEAD~1 --hard }
function pop-commit { git reset HEAD^ }
function git-remotes
{ git remote -v }
function set-remote ($remote, $url)
{ git remote set-url $remote $url }
function co { Param($branch)
git checkout $branch }
function ec { git config --global -e }
function cm { Param($commitMessage)
git add -A | git commit -m $commitMessage }
function gitdrop { git checkout -- . }
function tracking { Param($branch)
git ls-tree -r $branch --name-only
}
function untrack { Param($file)
git rm --cached -f $file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment