@@ -31,9 +31,10 @@ title: Windows
3131 - Follow the [ instructions here] ( https://github.com/seagull/disable-automaticrestarts/issues/4#issuecomment-521382489 )
3232 - Alternatively, go into advanced power plan options and disable wake timers
3333
34- ### PowerShell Profile
34+ ### PowerShell Profile and Utilities
3535
36- ``` PowerShell
36+ ``` powershell
37+ Set-StrictMode -Version Latest
3738if ($(Get-Location).Path -eq 'C:\WINDOWS\system32') {
3839 Set-Location $Env:USERPROFILE
3940}
@@ -46,14 +47,46 @@ Set-PSReadLineKeyHandler -Chord Ctrl+Shift+RightArrow SelectForwardWord
4647$PSDefaultParameterValues['*:Encoding'] = 'utf8'
4748$Env:PYTHONIOENCODING = 'utf-8'
4849
49- function b {
50+ # window title https://stackoverflow.com/q/29211928
51+ if (-not (Get-Variable _windowTitleDefault -ValueOnly -ErrorAction SilentlyContinue)) {
52+ $global:_windowTitleDefault = $host.ui.rawui.WindowTitle
53+ }
54+ function prompt {
55+ $host.ui.rawui.WindowTitle = "$_windowTitleDefault : $($executionContext.SessionState.Path.CurrentLocation | Split-Path -Leaf)"
56+ return "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";
57+ }
58+ Set-PSReadLineKeyHandler -Key Enter `
59+ -BriefDescription RunWithTitle `
60+ -LongDescription "Set the console title to the command, then run the command" `
61+ -ScriptBlock {
62+ param($key, $arg)
63+
64+ $line = $null
65+ $cursor = $null
66+ [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
67+ if ($line.Length -gt 1023) {
68+ $Host.UI.RawUI.WindowTitle = $line.Substring(0,1023)
69+ }
70+ else {
71+ $Host.UI.RawUI.WindowTitle = $line
72+ }
73+ [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
74+ }
75+
76+ if ($PSEdition -eq 'Core'){
77+ $PSStyle.Progress.View = 'Classic'
78+ }
79+
80+ function Set-DisplayBrightness {
5081 param(
5182 [Parameter(Position=0,Mandatory=$true)]
5283 [int]
5384 $Brightness
5485 )
86+ # https://www.nirsoft.net/utils/control_my_monitor.html
5587 controlmymonitor /SetValue Primary 10 $Brightness
5688}
89+ Set-Alias b Set-DisplayBrightness
5790
5891function Set-SuspendState {
5992 param(
@@ -68,4 +101,45 @@ function Set-SuspendState {
68101 [System.Windows.Forms.Application]::SetSuspendState($PowerState, $true, $true)
69102}
70103
104+ function touch {
105+ param(
106+ [Parameter(Mandatory,Position=1)][string]$Item,
107+ [DateTime]$t = (Get-Date),
108+ [ValidateSet('CreationTime','CreationTimeUtc','LastAccessTime','LastAccessTimeUtc','LastWriteTime','LastWriteTimeUtc')]
109+ [string]$Time = 'LastWriteTime'
110+ )
111+ if (-not (Test-Path -LiteralPath $Item)) {
112+ New-Item $Item >$null
113+ }
114+ Get-Item $Item | % {
115+ $_.$Time = $t
116+ }
117+ }
118+
119+ function unset-histfile {
120+ Set-PSReadLineOption -HistorySaveStyle SaveNothing
121+ }
122+
123+ function bell {
124+ echo "`a"
125+ }
126+
127+ function beep {
128+ param(
129+ [Parameter(Position=0)]
130+ [int]
131+ $Frequency = 1000,
132+ [Parameter(Position=1)]
133+ [int]
134+ $Milliseconds = 1000
135+ )
136+ [Console]::Beep($Frequency, $Milliseconds)
137+ }
138+
139+ function sha256sum {
140+ param([Parameter(Mandatory,Position=1)][string]$Path)
141+ (Get-FileHash -Path $Path).Hash.ToLower()
142+ }
143+
144+ Set-StrictMode -Off
71145```
0 commit comments