-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
119 lines (95 loc) · 4.19 KB
/
Microsoft.PowerShell_profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Simplify Powershell debugging
Set-PSDebug -strict
# Various PowerShell modules
Import-Module PSReadLine
Import-Module AngleParse
function Test-IsElevated
{
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object System.Security.Principal.WindowsPrincipal($id)
if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
{
Write-Output $true
}
else
{
Write-Output $false
}
}
function s { Set-Location .. }
## Load various utils by me - see https://github.com/dontrolle/Powershell
$private:ProductType = "GeForce"
$private:ProductSeries = "GeForce RTX 30 Series"
$private:Product = "GeForce RTX 3080"
$private:OperatingSystem = "Windows 10 64-bit"
$private:DownloadType = "Game Ready Driver (GRD)"
$private:Language = "English (US)"
Import-Module -Name "C:\src\Powershell\nvidiadrivercheck.psm1" -ArgumentList "NVIDIA GeForce RTX 3080", $ProductType, $ProductSeries, $Product, $OperatingSystem, $DownloadType, $Language
. "c:\src\Powershell\out-clip.ps1"
. "C:\src\Powershell\Get-FileDefiningFunction.ps1"
. "C:\src\Powershell\close-vshandles.ps1"
### Posh git stuff
# Ensure that Get-ChildItemColor is loaded
Import-Module Get-ChildItemColor
# Set l and ls alias to use the new Get-ChildItemColor cmdlets
Set-Alias l Get-ChildItemColor -Option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope
# Ensure posh-git is loaded
Import-Module -Name posh-git
# oh-my-posh load and set theme
# * Remember to install a nerd font and use it your shell (I like Terminal), see https://ohmyposh.dev/docs/fonts
# * For font, I like "FuraCode Nerd Font Mono", because it has nordic characters
# Set prompt theme
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/powerlevel10k_rainbow.omp.json" | Invoke-Expression
# winget autocomplete
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# A little header with some reminders, because I forget things
function _Write-HeaderInfo($line)
{
Write-Host $line -ForegroundColor Yellow
}
Write-Host "Installing stuff" -ForegroundColor DarkYellow
_Write-HeaderInfo " [apps] winget install"
_Write-HeaderInfo " [apps] choco install"
_Write-HeaderInfo " [powershell] install-module"
_Write-HeaderInfo " [npm] npm "
Write-Host "Other" -ForegroundColor DarkYellow
_Write-HeaderInfo " Check NVIDIA drivers Test-NvidiaDriver"
_Write-HeaderInfo " List loaded PS Modules Get-Module -ListAvailable"
_Write-HeaderInfo ""
# check for outdated packages now and then
$private:outedDatedLastCheckFile = "$Home\.outdatedLastCheck"
$private:outedDatedLastCheckDateFormat = 'dd-MM-yyyy'
$private:outedDatedLastCheckPeriodInDays = 21
$private:performOutdatedCheck = $false
if(!(Test-Path -Path $outedDatedLastCheckFile)){
# no date for last check recorded; we should check and create file
$performOutdatedCheck = $true
}
else {
# has relevant number of days gone by since last check?
$lastCheckString = Get-Content -Path $outedDatedLastCheckFile
$lastCheck = [DateTime]::ParseExact($lastCheckString, $outedDatedLastCheckDateFormat, $null)
$lastCheckAddDays = $lastCheck.AddDays($outedDatedLastCheckPeriodInDays)
$today = Get-Date
if($lastCheckAddDays -lt $today){
$performOutdatedCheck = $true
}
}
if($performOutdatedCheck){
# check for winget upgradeable
_Write-HeaderInfo ""
_Write-HeaderInfo "Winget upgradeable:"
winget upgrade
# Write current date to file, recording that we've performed the check today
Get-Date -format $outedDatedLastCheckDateFormat | Out-File -FilePath $outedDatedLastCheckFile
}
Set-Location -Path "c:\src"