Skip to content

Instantly share code, notes, and snippets.

@hexnaught
Last active December 15, 2019 18:46
Show Gist options
  • Save hexnaught/3073e837949bc90a99fbd8e11ea5080c to your computer and use it in GitHub Desktop.
Save hexnaught/3073e837949bc90a99fbd8e11ea5080c to your computer and use it in GitHub Desktop.
My personal PowerShell profile. As a GIST because I tend to use it on multiple machines and having it somewhere central is just helpful.
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
# Dirty Env Vars
#$env:Path = $env:Path + ";..."
# Just some helpful commands/shortcuts
function global:touch {
PARAM (
[Parameter(Mandatory = $True, Position = 1)] [STRING] $file_name
)
New-Item ($MyInvocation.MyCommand.Path + $file_name)
}
function global:vi {
PARAM (
[Parameter(Mandatory = $True, Position = 1)] [STRING] $file_name
)
$fullFilePath = ('./' + $file_name) -replace "\\", "/"
bash -c "vim $fullFilePath"
}
function global:psprofile {
`code $profile`
}
function global:rm {
PARAM(
[Parameter(Mandatory = $True, Position = 1)] [STRING] $itemPath,
[Parameter(Mandatory = $False, Position = 2)] [STRING] $flag1
)
$flags = ""
if ($flag1 -eq "-r") {
$flags += "-recursive "
}
Remove-Item (-path $itemPath $flags)
}
function global:Reload-Profile {
& $profile
}
# Custom powershell prompt, shows git branch too
function prompt {
$currentBranch = (&git rev-parse --abbrev-ref HEAD)
# If we are in debug prompt
if (test-path variable:/PSDebugContext) {
Write-Host "[DBG] " -NoNewline -ForegroundColor Grey
}
Write-Host "$(Get-Location)" -NoNewline -ForegroundColor Yellow
if ($currentBranch) {
Write-Host " [$currentBranch]" -NoNewline -ForegroundColor Cyan
}
if ($nestedpromptlevel -ge 1) {
Write-Host ">>" -NoNewline
}
Write-Host ">" -NoNewline -ForegroundColor Red
return " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment