Skip to content

Instantly share code, notes, and snippets.

@tterb
Last active April 26, 2017 21:45
Show Gist options
  • Save tterb/61357320ed3e35ec7b3007356612768d to your computer and use it in GitHub Desktop.
Save tterb/61357320ed3e35ec7b3007356612768d to your computer and use it in GitHub Desktop.
Powershell Profile
# Set-Up
$Shell = $Host.UI.RawUI
$size = $Shell.WindowSize
$size.width=90
$size.height=30
$Shell.WindowSize = $size
$size = $Shell.BufferSize
$size.width=140
$size.height=2500
$Shell.BufferSize = $size
$Shell.WindowTitle="One Shell to Rule Them All"
set-location C:\Users\there
Remove-Module PSReadline # Get rid of yellow input text
# Functions
Function Edit-PowerShellProfile { atom $profile }
Function cd-dash { if ($args[0] -eq '-') { $pwd=$OLDPWD; } else { $pwd=$args[0]; } $tmp=pwd; if ($pwd) { Set-Location $pwd; } Set-Variable -Name OLDPWD -Value $tmp -Scope global; } #cdDash
Function New-Window { C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe $args }
Function Read-Content { Get-Content (join-path (Get-Item -Path ".\" -Verbose) $args) }
Function Nav-Home { cd 'C:\Users\there' }
Function Nav-School { cd 'C:\Users\there\Documents\School\Spring 2017' }
Function Nav-Folder { cd C:\Users\there\Desktop\Folder }
Function Nav-Site { cd C:\Users\there\Desktop\Folder\JonSn0w.github.io }
Function Nav-Rainmeter { cd C:\Users\there\Documents\Rainmeter\Skins }
Function SSH-Pengo { ssh bstevens@pengo.cabrillo.edu }
#Function Find-Everything { Everything -s $args }
Function Git-Push { git push origin master }
Function Git-Pull { git pull origin master }
Function Bundle-Serve { bundle exec jekyll serve }
Function Atom-Clear { atom --clear-window-state . }
Function Atom-Clear-Dev { atom --clear-window-state --dev . }
Function Run-CCleaner { C:\Users\there\Scripts\ccleaner.ps1 }
Function Run-GPMDP { C:\Users\there\AppData\Local\GPMDP_3\Update.exe --processStart Google%20Play%20Music%20Desktop%20Player.exe }
Function Run-Putty { C:\Program Files\PuTTY\putty.exe }
Function Run-WinSCP { & "C:\Program Files (x86)\WinSCP\WinSCP.exe" }
Function Run-Mail { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Mail.lnk" }
Function Run-Calendar { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Calendar.lnk" }
Function Run-VPN { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\NordVPN.lnk" }
Function Run-Network { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Killer Network Manager.lnk" }
Function Run-Netflix { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Netflix.lnk"}
Function Run-Colorize { python C:\Users\there\Scripts\colorize.py $args }
Function Run-devArt { python C:\Users\there\Scripts\devArt.py $args }
Function Run-Find { python C:\Users\there\Scripts\find.py $args }
Function Restore-Point { Invoke-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Create Restore Point.lnk" }
Function Git-Origin { git remote add origin https://github.com/JonSn0w/$args }
Function Run-Github { Invoke-Item "C:\Users\there\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub.appref-ms" }
Function Run-Haroopad { Invoke-Item "C:\Users\there\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Haroopad.lnk" }
Function Run-Screenpresso { Invoke-Item "C:\Users\there\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Screenpresso.lnk" }
Function Run-Discord { Invoke-Item "C:\Users\there\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Discord.lnk" }
Function sudo {
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi);
}
#Function f--k {
# $cmd = (Get-History ((Get-History).Count))[0].CommandLine
# Write-Host "Running $cmd in $PWD"
# sudo powershell -NoExit -Command "pushd '$PWD'; Write-host 'cmd to run: $cmd'; $cmd"
#}
# Aliases
Set-Alias -Name cd -value cd-dash -Option AllScope
Set-Alias subl 'C:\Program Files\Sublime Text 3\sublime_text.exe'
Set-Alias cppcheck 'C:\Program Files\Cppcheck\Cppcheck.exe'
Set-Alias ~ 'C:\Users\there'
#Set-Alias find Find-Everything
#Set-Alias sudo -value Fn-sudo -Option AllScope
#Set-Alias ls Get-ChildItem-Color -option AllScope -Force
Set-Alias echo { Write-Host $args }
Set-Alias cat Read-Content -option AllScope
Set-Alias -Name ls -Value PowerLS -Option AllScope
Set-Alias home Nav-Home
Set-Alias school Nav-School
Set-Alias folder Nav-Folder
Set-Alias site Nav-Site
Set-Alias rain Nav-Rainmeter
Set-Alias new New-Window
Set-Alias pengo SSH-Pengo
Set-Alias push Git-Push
Set-Alias pull Git-Pull
Set-Alias addorigin Git-Origin
Set-Alias github Run-Github
Set-Alias serve Bundle-Serve
Set-Alias 'atom -c .' Atom-Clear
Set-Alias 'atom -c -d .' Atom-Clear-Dev
New-Alias config Edit-PowerShellProfile
Set-Alias ccleaner Run-CCleaner
Set-Alias gpmdp Run-GPMDP
Set-Alias putty Run-Putty
Set-Alias scp Run-WinSCP
Set-Alias mail Run-Mail
Set-Alias cal Run-Calendar
Set-Alias vpn Run-VPN
Set-Alias network Run-Network
Set-Alias netflix Run-Netflix
Set-Alias colorize Run-Colorize
Set-Alias devArt Run-devArt
Set-Alias find Run-Find
Set-Alias haroo Run-Haroopad
Set-Alias screencap Run-Screenpresso
Set-Alias -Name cd -value cd-dash -Option AllScope
Set-Alias restorepoint Restore-Point
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
Import-Module posh-git
# Customize Powershell prompt
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
if (Test-Administrator) { # Use different username if elevated
Write-Host "r00t:" -NoNewline -ForegroundColor darkmagenta
}
Write-Host "$ENV:USERNAME" -NoNewline -ForegroundColor darkgreen
Write-Host "@" -NoNewline -ForegroundColor darkcyan
Write-Host "$ENV:COMPUTERNAME" -NoNewline -ForegroundColor darkgray
if ($s -ne $null) { # color for PSSessions
Write-Host " (`$s: " -NoNewline -ForegroundColor darkgray
Write-Host "$($s.Name)" -NoNewline -ForegroundColor yellow
Write-Host ") " -NoNewline -ForegroundColor darkgray
}
Write-Host ":" -NoNewline -ForegroundColor gray
Write-Host $($(Get-Location) -replace "C:\\Users\\there", "~") -NoNewline -ForegroundColor cyan
#Write-Host " : " -NoNewline -ForegroundColor DarkGray
#Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta
#Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE
#Write-VcsStatus
#Write-Host ""
return ">$ "
}
Pop-Location
Start-SshAgent -Quiet
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
Import-Module posh-git
## customize git prompt display settings
$global:GitPromptSettings.BeforeText = '['
$global:GitPromptSettings.AfterText = ']'
$global:GitPromptSettings.BranchAheadStatusForegroundColor = [ConsoleColor]::Green
$global:GitPromptSettings.WorkingForegroundColor = [ConsoleColor]::Red
# Get rid of all PowerShell crap
Clear-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment