2019-10-21 19:37:23 -05:00
|
|
|
# My powershell profile.
|
|
|
|
|
|
|
|
# customize the prompt to be a little more useful
|
|
|
|
function prompt {
|
|
|
|
Write-Host -NoNewLine "["
|
|
|
|
Write-Host -NoNewLine -Fore Green ("{0:HH}:{0:mm}" -f $(get-date))
|
|
|
|
Write-Host -NoNewLine "] "
|
|
|
|
Write-Host -Fore Cyan "${pwd}"
|
|
|
|
"PS> "
|
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Invoke a scriptblock with evelvated permissions.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function Invoke-Elevated {
|
|
|
|
param (
|
|
|
|
[ScriptBlock]
|
|
|
|
$code
|
2020-02-09 07:44:46 -06:00
|
|
|
)
|
|
|
|
$outTmpFile = [System.IO.Path]::GetTempFileName()
|
|
|
|
$errTmpFile = [System.IO.Path]::GetTempFileName()
|
|
|
|
|
|
|
|
$code | Write-Output
|
|
|
|
$outTmpFile | Write-Output
|
|
|
|
$errTmpFile | Write-Output
|
|
|
|
# TODO(jwall): Work on figuring out how to properly redirect output here
|
|
|
|
Start-Process powershell.exe -ArgumentList { &$code 1>$outTmpFile 2>$errTmpFile } -WindowStyle hidden -Verb RunAs
|
|
|
|
Get-Content $outTmpFile | Write-Output
|
|
|
|
Get-Content $errTmpFile | Write-Output
|
|
|
|
Remove-Item $outTmpFile
|
|
|
|
Remove-Item $errTmpFile
|
2019-10-21 19:37:23 -05:00
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Returns true if you are running with elevated privileges.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function Get-Elevated {
|
|
|
|
([Security.Principal.WindowsPrincipal] `
|
|
|
|
[Security.Principal.WindowsIdentity]::GetCurrent() `
|
|
|
|
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Create a symlink from a source to a destination.
|
|
|
|
|
|
|
|
.Description
|
|
|
|
Creates a symlink from a $Source to a $Destination.
|
|
|
|
Automatically elevates to administrator privileges
|
|
|
|
if necessary.
|
|
|
|
|
|
|
|
.Parameter Source
|
|
|
|
Required source to create the symlink from.
|
|
|
|
|
|
|
|
.Parameter Destination
|
|
|
|
Required destination to create the symlink at.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function New-Link {
|
|
|
|
param (
|
|
|
|
[Parameter(Position=0, Mandatory=$true)]
|
2020-02-09 07:44:46 -06:00
|
|
|
[string[]]
|
2019-10-21 19:37:23 -05:00
|
|
|
$Source,
|
|
|
|
|
|
|
|
[Parameter(Position=1, Mandatory=$true)]
|
2020-02-09 07:44:46 -06:00
|
|
|
[string[]]
|
2019-10-21 19:37:23 -05:00
|
|
|
$Destination
|
|
|
|
)
|
|
|
|
|
|
|
|
# This is a bit of a hack but it's necessary until they make it possible
|
|
|
|
# to do symbolic links without administrator privileges
|
|
|
|
if (Get-Elevated) {
|
|
|
|
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
|
|
|
|
} else {
|
|
|
|
# Elevate our permissions for this first.
|
|
|
|
Invoke-Elevated {
|
|
|
|
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
|
|
|
|
}
|
|
|
|
}
|
2019-10-26 14:59:31 -05:00
|
|
|
}
|
|
|
|
|
2020-02-09 07:44:46 -06:00
|
|
|
function grep {
|
|
|
|
$input | out-string -stream | select-string $args
|
|
|
|
}
|
|
|
|
|
2019-10-26 14:59:31 -05:00
|
|
|
# It's way more useful to call this open than ii
|
2019-11-09 19:52:12 -06:00
|
|
|
Set-Alias -Name open -Value Invoke-Item
|
2020-02-09 07:44:46 -06:00
|
|
|
Set-Alias -Name ln -Value New-Link
|
2019-11-09 19:52:12 -06:00
|
|
|
# Add make to our powershell path
|
2020-02-09 07:44:46 -06:00
|
|
|
$env:PATH="$env:PATH;C:\Program Files (x86)\GnuWin32\bin;C:\Users\jerem\AppData\Local\Julia-1.3.0\bin"
|