Skip to content

Instantly share code, notes, and snippets.

@techthoughts2 techthoughts2/PSProfile
Last active Mar 5, 2019

Embed
What would you like to do?
#_________________________________________________________________________________________
Write-Host "Initializing the Shell..." -ForegroundColor DarkCyan -BackgroundColor White
$global:sysvars = Get-Variable | Select-Object -ExpandProperty Name
$global:sysvars += 'sysvars'
$greetings =
'Welcome back Jake',
'Glad to see you Jake!',
'Happy coding Jake!',
'Have a great day Jake!',
'Be one with the Snover!',
'May the PowerShell be with you!'
#_________________________________________________________________________________________
<#
.SYNOPSIS
Clears all errors, variables, console, and sets locations back to C:\
.NOTES
System variables are not cleared - as they are gathered previously and left un-touched.
#>
function Clear-All {
$sysvariables = $sysvars
#clear all errors
$error.clear()
#clear all non-system variables
Get-Variable |
Where-Object {$sysvariables -notcontains $_.Name -and $_.Name -ne "sysvariables"} |
ForEach-Object {Remove-Variable $_.name -Scope Global}
Clear-Host
Set-Location C:\
}
<#
.SYNOPSIS
Opens explorer window to the current console path location
#>
function Open-Here {
explorer $pwd
}
<#
.SYNOPSIS
Get beautiful syntax for any cmdlet
#>
function Get-Syntax {
[CmdletBinding()]
param (
$Command,
[switch]
$PrettySyntax
)
$check = Get-Command -Name $Command
$params = @{
Name = if ($check.CommandType -eq 'Alias') {
Get-Command -Name $check.Definition
}
else {
$Command
}
Syntax = $true
}
$pretty = $true
if ($pretty -eq $true) {
(Get-Command @params) -replace '(\s(?=\[)|\s(?=-))', "`r`n "
}
else {
Get-Command @params
}
}
<#
.SYNOPSIS
Quickly and easily reverses a list
#>
function Sort-Reverse {
$rank = [int]::MaxValue
$input | Sort-Object {(--(Get-Variable rank -Scope 1).Value)}
}
#_________________________________________________________________________________________
# set easy aliases for various functions
New-Alias -Name ca -value Clear-All
New-Alias -Name op -value Open-Here
New-Alias -Name syn -value Get-Syntax
New-Alias -Name sr -value Sort-Reverse
#_________________________________________________________________________________________
# Custom prompt function
function global:prompt {
$global:promptDateTime = [datetime]::Now
$Global:promptDate = $global:promptDateTime.ToString("dd/MM/yyyy")
$Global:promptTime = $global:promptDateTime.ToLongTimeString()
$global:promptPath = $pwd.ToString().split('\')[-2..-1] -join '\'
Write-Host -Object ("[{0} {1}]" -f $global:promptDate, $global:PromptTime) -ForegroundColor Green -NoNewline
(" {0}> " -f $global:promptPath)
Write-VcsStatus
return " "
}
#_________________________________________________________________________________________
# load up any desired modules
$modulesToLoad = @(
'posh-git'
)
foreach ($module in $modulesToLoad) {
Write-Host -ForegroundColor Gray ("Jake, at your request I am loading up the $module module...")
try {
Import-Module $module -ErrorAction Stop
Write-Host "$module loaded." -ForegroundColor Magenta
}
catch{
Write-Host "Jake, $module has failed to load." -ForegroundColor DarkRed
}
}
#_________________________________________________________________________________________
Set-PSReadlineOption -ContinuationPrompt ">>>"
Write-Host "Initilization complete." ($greetings | Get-Random) -ForegroundColor Cyan -BackgroundColor Black
#_________________________________________________________________________________________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.