Skip to content

Instantly share code, notes, and snippets.

@mattifestation
Created March 28, 2020 22:16
Show Gist options
  • Save mattifestation/2a22fa713562c22721a31c88a54ec1df to your computer and use it in GitHub Desktop.
Save mattifestation/2a22fa713562c22721a31c88a54ec1df to your computer and use it in GitHub Desktop.
PowerShell profile to add some functionality for Windows Terminal
# Personal preference. I like landing on the Desktop
Set-Location $Env:USERPROFILE\Desktop
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
# If the current session is elevated, prefix the prompt with '[Admin]'
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Set-Item -Path Function:\prompt -Value "`"[Admin] PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) `""
}
# Alias powershell to not display the annoying logo
function powershell { powershell.exe -NoLogo }
# Parse the Terminal profile
function Get-TerminalProfile {
[CmdletBinding()]
param ()
if (Get-Item -Path Env:\WT_SESSION -ErrorAction SilentlyContinue) {
$TerminalAppX = Get-AppxPackage -Name 'Microsoft.WindowsTerminal'
$TerminalProfilePath = "$ENV:LocalAppData\Packages\$($TerminalAppX.PackageFamilyName)\LocalState\profiles.json"
Write-Verbose "Terminal profile path: $TerminalProfilePath"
$TerminalProfileText = Get-Content -Path $TerminalProfilePath -Raw
ConvertFrom-Json -InputObject $TerminalProfileText
}
}
# Launch an elevated terminal
function Start-ElevatedTerminal {
$TerminalAppX = Get-AppxPackage -Name 'Microsoft.WindowsTerminal'
if ($TerminalAppX) {
Start-Process -FilePath "shell:AppsFolder\$($TerminalAppX.PackageFamilyName)!App" -Verb 'RunAs'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment