Skip to content

Instantly share code, notes, and snippets.

@phil-scott-78
Last active November 19, 2022 18:19
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save phil-scott-78/28735ad97f2183a158ae6b830ad5f488 to your computer and use it in GitHub Desktop.
Save phil-scott-78/28735ad97f2183a158ae6b830ad5f488 to your computer and use it in GitHub Desktop.
Powershell Profile
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "yellow",
"properties": {
"root_icon": "\ue0a2"
},
"style": "plain",
"template": " \uf0e7 ",
"type": "root"
},
{
"background": "blue",
"foreground": "transparent",
"leading_diamond": "\ue0b6",
"properties": {
"home_icon": "\uf7db",
"style": "mixed"
},
"style": "powerline",
"template": " {{ .Path }} ",
"powerline_symbol": "\ue0b0",
"type": "path"
},
{
"background": "green",
"foreground": "black",
"style": "powerline",
"powerline_symbol": "\ue0b0",
"type": "git",
"properties": {
"branch_icon": "\uE0A0 "
}
},
{
"background": "darkGray",
"foreground": "lightWhite",
"powerline_symbol": "\ue0b0",
"properties": {
"style": "austin",
"threshold": 500
},
"style": "powerline",
"template": " \uf64f {{ .FormattedMs }} ",
"type": "executiontime"
}
],
"type": "prompt",
"vertical_offset": 1
}
],
"console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}",
"final_space": true,
"osc99": true,
"tooltips": [
{
"background": "blue",
"foreground": "black",
"leading_diamond": "\ue0b6",
"style": "diamond",
"template": " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} ",
"tips": [
"dotnet",
"dv"
],
"trailing_diamond": "\ue0b4",
"type": "dotnet"
}
],
"version": 2
}
function Run-Step([string] $Description, [ScriptBlock]$script)
{
Write-Host -NoNewline "Loading " $Description.PadRight(20)
& $script
Write-Host "`u{2705}" # checkmark emoji
}
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
#hides the cursor
Write-Host "`e[?25l" -NoNewline
Write-Host "Loading PowerShell $($PSVersionTable.PSVersion)..." -ForegroundColor 3
Write-Host
# this takes a sec, but we can also do it concurrently with the rest of the profile loading
$vsshell = Start-ThreadJob {
Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell 8ee891c5 -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" | Out-Null
}
# posh-git
Run-Step "Posh-Git" {
Import-Module posh-git
}
# oh-my-posh
Run-Step "oh-my-posh" {
oh-my-posh init pwsh --config C:\Users\phils\hotstick.omp.json | Invoke-Expression
Enable-Poshtooltips
$DefaultUser = 'phils'
}
Run-Step "ZLocation" {
Import-Module ZLocation
}
# we already started this task earlier, just gotta receive it now
Run-Step "VS2022 Shell" {
Receive-Job $vsshell -Wait -AutoRemoveJob
}
# show the cursor and complete the progress
Write-Host "`e[?25h" -NoNewline
$updateCheckedPath = "$($env:LOCALAPPDATA)\update-checked.txt"
$timespan = new-timespan -days 7
if (((Test-Path $updateCheckedPath) -eq $false) -or ((get-date) - (Get-Item $updateCheckedPath).LastWriteTime -gt $timespan))
{
Write-Host
Write-Host "Been a minute since running global update checks. Doing that now."
Write-Host
Write-Host "Running npm -g outdated"
npm -g outdated
Write-Host
Write-Host "Running choco outdated"
choco outdated
Write-Host
Write-Host "Running dotnet-tools-outdated"
dotnet-tools-outdated
get-date | Out-File -FilePath $updateCheckedPath
}
Write-Host "`nProfile loaded in " $stopwatch.Elapsed.TotalMilliseconds "ms"
// Based on original retro pixel shader
// https://github.com/microsoft/terminal/blob/main/samples/PixelShaders/Retro.hlsl
Texture2D shaderTexture;
SamplerState samplerState;
cbuffer PixelShaderSettings {
float Time;
float Scale;
float2 Resolution;
float4 Background;
};
#define SCANLINE_FACTOR 0.3
#define SCALED_SCANLINE_PERIOD Scale
float SquareWave(float y)
{
return 1 - (floor(y / SCALED_SCANLINE_PERIOD) % 2) * SCANLINE_FACTOR;
}
float4 Scanline(float4 color, float4 pos)
{
float wave = SquareWave(pos.y);
return color * wave;
}
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
{
Texture2D input = shaderTexture;
float4 color = input.Sample(samplerState, tex);
color = Scanline(color, pos);
// brighten this up a bit
color.xyz *= 1.2;
return color;
}
@Cambridgeport90
Copy link

Like this so far... will give me a good live example of a PowerShell profile that has real customizations in it. I might even fork it into my account and add some more stuff to it as well.

@phil-scott-78
Copy link
Author

Glad you like it, @Cambridgeport90!

@Cambridgeport90
Copy link

Cambridgeport90 commented Mar 28, 2022 via email

@oleksbabieiev
Copy link

oleksbabieiev commented Oct 9, 2022

I really like this profile! I will definitely add some features to mine. However, I also found some things that could be improved. When you start VsDevShell, you hard-coded InstanceId of Visual Studio:

Enter-VsDevShell d0d15d66...

But you can find it automatically (regardless of the device) using vswhere.exe tool (more info here). For example, like this:

$VsId = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property instanceid

You can also use Enter-VsDevShell with the Visual Studio installation path. The following script I use is based on this:

$VsPath = &"${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationpath
Import-Module (Join-Path $VsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
$Env:VSCMD_SKIP_SENDTELEMETRY = 1
Enter-VsDevShell -VsInstallPath $VsPath -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64" | Out-Null

@oleksbabieiev
Copy link

oleksbabieiev commented Oct 9, 2022

You can also find the module path automatically:

Import-Module (Get-ChildItem $VsPath -Recurse -File -Filter Microsoft.VisualStudio.DevShell.dll).FullName

But IMO it takes much more time, so I don't use this approach. I hope my comments were useful 🤗

@phil-scott-78
Copy link
Author

You can also find the module path automatically:

Import-Module (Get-ChildItem $VsPath -Recurse -File -Filter Microsoft.VisualStudio.DevShell.dll).FullName

But IMO it takes much more time, so I don't use this approach. I hope my comments were useful 🤗

You know it might be good to hardcore the path, and do a quick check for existence. If it's missing do the search, print a warning and move on

@oleksbabieiev
Copy link

You can also find the module path automatically:

Import-Module (Get-ChildItem $VsPath -Recurse -File -Filter Microsoft.VisualStudio.DevShell.dll).FullName

But IMO it takes much more time, so I don't use this approach. I hope my comments were useful 🤗

You know it might be good to hardcore the path, and do a quick check for existence. If it's missing do the search, print a warning and move on

Oh, I didn't think about it 😂. But I like the idea. I will try to implement something like this.

@Cambridgeport90
Copy link

Cambridgeport90 commented Oct 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment