Skip to content

Instantly share code, notes, and snippets.

@brettmillerb brettmillerb/profile.ps1
Last active Feb 28, 2019

Embed
What would you like to do?
Powershell Profile
# function declarations
function Open-Here { explorer $pwd }
function Set-SupportPath { Set-Location C:\support }
function Set-DocsPath { Set-Location $env:OneDrive\documents }
function Set-HomePath { Set-Location $home }
function Set-GitPath { Set-Location C:\support\git }
New-Alias -Name op -value Open-Here
New-Alias -Name support -Value Set-SupportPath
New-Alias -Name docs -value Set-DocsPath
New-Alias -Name home -Value Set-HomePath
New-Alias -Name GitPath -Value Set-GitPath
function Syntax {
[CmdletBinding()]
param (
$Command,
[switch]
$PrettySyntax
)
$check = Get-Command -Name $Command
$params = @{
Name = if ($check.CommandType -eq 'Alias') {
Get-Command -Name $check.Definition
}
else {
$Command
}
Syntax = $true
}
if ($PrettySyntax) {
(Get-Command @params) -replace '(\s(?=\[)|\s(?=-))', "`r`n "
}
else {
Get-Command @params
}
}
function Git-Whoami {
$author = git config user.name
$email = git config user.email
[pscustomobject]@{
Author = $author
Email = $email
}
}
function Backup-Profile {
[CmdletBinding()]
param (
[string]
$Path = "C:\support\git\gitwork\profile",
[switch]
$Push
)
Push-Location $Path
Copy-Item -Path $profile.CurrentUserAllHosts -Destination .\
if ($Push) {
git commit -am ("Updated Profile {0}" -f ((get-date).ToString("yyyy-MM-dd-hh:mm:ss")))
git push -u origin master
}
Pop-Location
}
function Sort-Reverse {
$rank = [int]::MaxValue
$input | Sort-Object {(--(Get-Variable rank -Scope 1).Value)}
}
# Import module only in VSCode
if ($host.name -eq 'Visual Studio Code Host') {
Import-Module EditorServicesCommandSuite
Import-EditorCommand -Module EditorServicesCommandSuite
Import-CommandSuite
}
# Custom prompt function
function global:prompt {
$global:promptDateTime = [datetime]::Now
$Global:promptDate = $global:promptDateTime.ToString("yyyy/MM/dd")
$Global:promptTime = $global:promptDateTime.ToLongTimeString()
$global:promptPath = $pwd.ToString().split('\')[-2..-1] -join '\'
Write-Host -Object ("[{0} {1}]" -f $global:promptDate, $global:PromptTime) -ForegroundColor Green -NoNewline
(" {0}> " -f $global:promptPath)
}
# Register Argument completer for Internal PSGallery tab completion
Register-ArgumentCompleter -CommandName Find-Module -ParameterName Repository -ScriptBlock {
Get-PSRepository | Select-Object -ExpandProperty Name | foreach-object {
[System.Management.Automation.CompletionResult]::new(
$_
)
}
}
$PSDefaultParameterValues = @{
"Find-Module:Repository" = 'PSGallery Internal'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.