Skip to content

Instantly share code, notes, and snippets.

@pwxcoo
Last active August 26, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwxcoo/c0db12df18d608ce107e14d37fec412d to your computer and use it in GitHub Desktop.
Save pwxcoo/c0db12df18d608ce107e14d37fec412d to your computer and use it in GitHub Desktop.
my customized powershell profile
# http://joonro.github.io/blog/posts/powershell-customizations.html
Import-Module PSReadLine
# Oh-My-Posh https://github.com/pecigonzalo/Oh-My-Posh
Import-Module "Oh-My-Posh" -DisableNameChecking -NoClobber
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 4000
# history substring search
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
# Tab completion
Set-PSReadlineKeyHandler -Chord 'Shift+Tab' -Function Complete
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
function which($name) { Get-Command $name | Select-Object Definition }
function rm-rf($item) { Remove-Item $item -Recurse -Force }
function touch($file) { "" | Out-File $file -Encoding ASCII }
function admin() {Start-Process powershell -verb runas}
function grep {
[cmdletbinding()]
param (
[Parameter(
Mandatory = $True,
ValueFromPipeline = $true)]
$input,
[Parameter(
Mandatory = $True,
ValueFromPipeline = $false,
Position = 0)]
[string] $SearchString
)
Process {
$input | Out-String -Stream | Select-String -Pattern $SearchString
}
}
function timestamp() {
$unixEpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc)
$timestamp = [int]([DateTime]::UtcNow - $unixEpochStart).TotalSeconds
Write-Host $timestamp
# set clipboard
Write-Host "`nclipboard has set!`n" -ForegroundColor Yellow
Set-Clipboard -Value $timestamp
}
function 2date($timestamp) {
[DateTimeOffset]::FromUnixTimeSeconds($timestamp)
}
function Restart-PowerShell{
Start-Process PowerShell # Launch PowerShell host in new window
exit # Exit existing PowerShell host window
}
# Add any alias if you want, for ex. rps (rp already occupied by "Remove-ItemProperty”)
Set-Alias -Name rps -Value Restart-PowerShell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment