|
Write-Host "Loading tren custom profile" |
|
# Place file in this location |
|
# C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 |
|
# for powershell 6, location is here |
|
# C:\Program Files\PowerShell\6\pwsh.exe |
|
|
|
# Get-Alias # output the current aliases |
|
|
|
# Add menu option |
|
# Found here http://michlstechblog.info/blog/powershell-a-text-based-menu/ |
|
$script:MyInvocation.MyCommand.Path |
|
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path |
|
. $ScriptDir\Menu.ps1 |
|
|
|
# todo, change information to be table friendly (automatic spacing) |
|
$i = @(); |
|
# add the powershell scripts to my command line |
|
# Remove-Module Common-MMX # -ErrorAction ignore |
|
Import-Module \\wexfs\users\MMX\Scripts\Powershell\Common-MMX.psm1 -ErrorAction silentlycontinue -WarningAction 0 # ignore warning actions |
|
|
|
$i += "" |
|
$i += "## MACROS -------------------------------------------" |
|
$i += '```' |
|
|
|
function Get-Edit { & code C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 } |
|
New-Alias -Name edit -Value Get-Edit |
|
$i += "edit -> open up powershell profile to edit macros" |
|
|
|
function Touch { & New-Item -ItemType file $args } |
|
New-Alias -Name t -Value Touch |
|
$i += "t, touch -> create file 'New-Item <file name>'" |
|
|
|
function Get-OpenExplorerHere { |
|
if ($args) { |
|
explorer $args |
|
} else { |
|
& explorer . |
|
} |
|
} |
|
# todo, if args provided, use the args instead |
|
New-Alias -Name e -Value Get-OpenExplorerHere |
|
$i += "e -> open up explorer window in current directory" |
|
|
|
function Get-OpenWexfs { & explorer \\wexfs\users\mmx\scripts } |
|
New-Alias -Name w -Value Get-OpenWexfs |
|
New-Alias -Name wex -Value Get-OpenWexfs |
|
$i += "w, wex -> open up explorer to wexfs scripts directory" |
|
|
|
function Get-OpenCodeHere { & code . } |
|
New-Alias -Name c -Value Get-OpenCodeHere |
|
$i += "c -> open up vs code in current directory" |
|
|
|
function Get-OpenLuaMacros { & 'C:\Users\trrensha\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\LuaMacros.exe - load file.lnk' } |
|
New-Alias -Name lua -Value Get-OpenLuaMacros |
|
$i += "lua -> run Lua Macros with config file" |
|
|
|
function Get-OpenVsHere { & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe" . } |
|
New-Alias -Name vss -Value Get-OpenVsHere |
|
$i += "vss -> open up visual studio" |
|
|
|
function Get-OpenVs { |
|
Write-Host Opening Visual Studio |
|
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe" $args |
|
} |
|
New-Alias -Name vs -Value Get-OpenVs |
|
New-Alias -Name visual-studio -Value Get-OpenVs |
|
$i += "vs, visual-studio -> open up visual studio, arg for directory" |
|
|
|
function Get-OpenAndroidStudio { |
|
Write-Host Opening Android Studio |
|
& "C:\Program Files\Android\Android Studio\bin\studio64.exe" $args |
|
} |
|
New-Alias -Name as -Value Get-OpenAndroidStudio |
|
New-Alias -Name android-studio -Value Get-OpenAndroidStudio |
|
$i += "as, android-studio -> open up android studio" |
|
|
|
|
|
function Get-OpenStackOverflow { |
|
Write-Host Opening Stack Overflow |
|
$uri = [uri]::EscapeDataString($args); |
|
& start chrome https://stackoverflow.com/search?q=$uri |
|
} |
|
New-Alias -Name so -Value Get-OpenStackOverflow |
|
New-Alias -Name stackoverflow -Value Get-OpenStackOverflow |
|
$i += "so, stackoverflow -> open up stack overflow with query" |
|
|
|
|
|
function Get-OpenGoogle { |
|
Write-Host Opening Google |
|
$uri = [uri]::EscapeDataString($args); |
|
& start chrome https://www.google.com/search?q=$uri |
|
} |
|
New-Alias -Name g -Value Get-OpenGoogle |
|
New-Alias -Name google -Value Get-OpenGoogle |
|
$i += "g, google -> open up google with query" |
|
|
|
|
|
function Get-OpenGoogleFilterToStackOverflow { |
|
Write-Host Opening Google to search Stack Overflow |
|
$uri = [uri]::EscapeDataString($args + " site:stackoverflow.com"); |
|
& start chrome https://www.google.com/search?q=$uri |
|
} |
|
New-Alias -Name gs -Value Get-OpenGoogleFilterToStackOverflow |
|
$i += "gs -> open up google with query filtered to stack overflow" |
|
|
|
function Get-OpenDashboard { |
|
Write-Host Opening Current Dashboard |
|
& start chrome https://microsoft.visualstudio.com/DefaultCollection/OS/_sprints/taskboard/MMX_YourPhone%20Foundations/ |
|
} |
|
New-Alias -Name d -Value Get-OpenDashboard |
|
New-Alias -Name dash -Value Get-OpenDashboard |
|
New-Alias -Name dashboard -Value Get-OpenDashboard |
|
$i += "d, dash, dashboard -> open up current sprint dashboard" |
|
|
|
function isAdmin() { |
|
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
|
# $arguments = "& '" + $myinvocation.mycommand.definition + "'" |
|
# Start-Process powershell -Verb runAs -ArgumentList $arguments |
|
# Break |
|
return $false |
|
} |
|
return $true |
|
} |
|
|
|
|
|
function runAsAdmin() { |
|
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
|
$arguments = $myinvocation.mycommand.definition |
|
# Write-Host "Running with args: $arguments" |
|
Start-Process powershell -Verb runAs -ArgumentList $arguments |
|
Break |
|
|
|
} |
|
Write-Host "Finished, in admin role" |
|
} |
|
|
|
function Open-AdminPowershell { |
|
Write-Host Opening admin window |
|
|
|
Write-Host "$args" |
|
& Start-Process pwsh -workingdirectory . -verb runas -argumentlist "$args" |
|
} |
|
New-Alias -Name admin -Value Open-AdminPowershell |
|
$i += "admin -> open up admin powershell window" |
|
|
|
function Toggle-SpotifyConnection { |
|
param([switch] $block) |
|
# For this one, make a rule on the windows defender firewall that blocks the spotify connection and disable it |
|
# when you enabled this, it will enable blocking spotify |
|
# Disable-NetFirewallRule -DisplayName "Spotify Music" |
|
# Enable-NetFirewallRule -DisplayName "Spotify Music" |
|
if (isAdmin) { |
|
if ($args) { |
|
Write-Host "Connecting Spotify to the internet" |
|
Enable-NetFirewallRule -Name "{78E1CD88-49E3-476E-B926-580E596AD309}" |
|
} else { |
|
Write-Host "Disconnecting Spotify from the internet" |
|
Enable-NetFirewallRule -Name "{78E1CD88-49E3-476E-B926-580E596AD309}" |
|
} |
|
} else { |
|
Write-Host "Copy the following command in the new window, or run command again from there" -ForegroundColor DarkMagenta |
|
if ($args) { |
|
Write-Host "Connecting Spotify to the internet" |
|
Write-Host ' Enable-NetFirewallRule -Name "{78E1CD88-49E3-476E-B926-580E596AD309}"' -ForegroundColor DarkBlue |
|
} else { |
|
Write-Host "Disconnecting Spotify from the internet" |
|
Write-Host ' Enable-NetFirewallRule -Name "{78E1CD88-49E3-476E-B926-580E596AD309}"' -ForegroundColor DarkBlue |
|
} |
|
admin # open admin window to run command |
|
} |
|
} |
|
New-Alias -Name spotify -Value Toggle-SpotifyConnection |
|
New-Alias -Name ss -Value Toggle-SpotifyConnection |
|
$i += "ss, spotify -> toggle spotify firewall rule on or off" |
|
|
|
# function ss { |
|
# write-host "ssss" |
|
# write-host "$myinvocation.mycommand.definition" |
|
# If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){ |
|
# $arguments = "& '" + $myinvocation.mycommand.definition + "'" |
|
# Start-Process powershell -Verb runAs -ArgumentList $arguments |
|
# Break |
|
# } |
|
# } |
|
|
|
function List-History { |
|
$hash = GetHistory |
|
$command = fShowMenu "Select command from history" $hash |
|
write-host "history $command" |
|
Invoke-Expression $command |
|
# & git checkout $checkout |
|
} |
|
New-Alias -Name hi -Value List-History |
|
New-Alias -Name lh -Value List-History |
|
$i += "hi, lh -> get list of history of commands and execute selected again" |
|
|
|
|
|
function GetHistory { |
|
$history = history |
|
$hash = @{ } |
|
$history | foreach { |
|
write-host $_.CommandLine |
|
$hash.add($_.CommandLine, $_.CommandLine) |
|
|
|
} |
|
write-host $hash |
|
return $hash |
|
} |
|
$i += '```' |
|
|
|
$i += "" |
|
$i += "## GIT ----------------------------------------------" |
|
$i += '```' |
|
|
|
# git status |
|
# usage s |
|
function GitStatus { |
|
GitBranch |
|
Blue("Changes") |
|
& git status $args |
|
} |
|
New-Alias -Name s -Value GitStatus |
|
$i += "s -> git status" |
|
|
|
# git commit |
|
# usage co "Commit message" |
|
# c -> git add -A; git commit -am <commit message> |
|
function GitCommit { |
|
Write-Host "Git add -A; Git commit <message>" |
|
& git add -A; git commit -am $args |
|
} |
|
New-Alias -Name co -Value GitCommit |
|
New-Alias -Name commit -Value GitCommit |
|
New-Alias -Name aa -Value GitCommit |
|
$i += "co, commit, aa -> git add -A, git commit <message>" |
|
|
|
# a -> git add -A |
|
function GitAdd { & git add -A } |
|
New-Alias -Name a -Value GitAdd |
|
$i += "a -> git add -A" |
|
|
|
# branch -> git branch |
|
function GitBranch { |
|
Blue("Branch") |
|
& git branch |
|
} |
|
New-Alias -Name b -Value GitBranch |
|
New-Alias -Name branch -Value GitBranch |
|
$i += "b, branch -> git branch" |
|
|
|
function GitBranchesToHashtable { |
|
$branches = git branch |
|
$hash = @{ } |
|
$branches | foreach { |
|
$value = $_.trim() |
|
$displayName = $value.replace( '*', '').trim() |
|
$hash.add($displayName, $value) |
|
} |
|
write-host $hash |
|
return $hash |
|
} |
|
|
|
# branch -> git branch |
|
function GitDeleteBranch { |
|
$hash = GitBranchesToHashtable |
|
$toDelete = fShowMenu "Delete Branch" $hash -highlight 4 |
|
& git branch -d $toDelete |
|
} |
|
New-Alias -Name db -Value GitDeleteBranch |
|
New-Alias -Name delete -Value GitDeleteBranch |
|
$i += "db, delete -> delete branch" |
|
|
|
# nbranch -> git checkout -b <branch name> |
|
function Git-CheckoutNewBranch { & git checkout -b $args } |
|
New-Alias -Name nbr -Value Git-CheckoutNewBranch |
|
New-Alias -Name nbranch -Value Git-CheckoutNewBranch |
|
$i += "nbr, nbranch -> git checkout -b <branch name>" |
|
|
|
# nbranch -> git checkout -b <branch name> |
|
function Git-Checkout { |
|
if ([string]::IsNullOrEmpty($args)) { |
|
$hash = GitBranchesToHashtable |
|
$checkout = fShowMenu "Checkout Branch" $hash |
|
write-host "checkout $checkout" |
|
& git checkout $checkout |
|
} else { |
|
& git checkout $args |
|
} |
|
} |
|
New-Alias -Name check -Value Git-Checkout |
|
New-Alias -Name checkout -Value Git-Checkout |
|
$i += "check, checkout -> git checkout <branch name> | args, alternately use empty and checkout from menu" |
|
|
|
|
|
# push -> set upstream and push |
|
function GitPushSetUpstream { |
|
& git push --set-upstream origin $(git branch --show-current) |
|
} |
|
New-Alias -Name push -Value GitPushSetUpstream |
|
$i += "push -> git push set upstream" |
|
|
|
# todo add way to checkout with find, takes in list of "git branch" then autocompletes |
|
|
|
# todo add way to set automatically when pushing and I get this error git branch --set-upstream-to=origin/<branch> user/tren/syncRefactor |
|
|
|
function GitClean { & git clean -fdx } |
|
New-Alias -Name clean -Value GitClean |
|
$i += "clean -> git clean -fdx, clears all non-tracked files in repo" |
|
|
|
# dev -> git checkout development |
|
function CheckoutDevelopment { & git checkout development } |
|
New-Alias -Name dev -Value CheckoutDevelopment |
|
$i += "dev -> git checkout development" |
|
|
|
# dev -> git checkout development |
|
function GitPull { & git pull } |
|
New-Alias -Name p -Value GitPull |
|
New-Alias -Name pull -Value GitPull |
|
$i += "p, pull -> git pull" |
|
|
|
function GitLog { & git log } |
|
New-Alias -Name l -Value GitLog |
|
New-Alias -Name log -Value GitLog |
|
$i += "l, log -> git log" |
|
|
|
function GitLogOneLine { & git log --oneline } |
|
New-Alias -Name lo -Value GitLogOneLine |
|
$i += "lo -> git log --oneline" |
|
|
|
function GitSoft { & git reset --soft HEAD~ } |
|
New-Alias -Name gitsoft -Value GitSoft |
|
New-Alias -Name soft -Value GitSoft |
|
$i += "soft, gitsoft -> git reset --soft HEAD~" |
|
|
|
function GitResetToLastCommit { |
|
Write-Host "Resetting git to last commit (git add -A; git reset --hard)" |
|
& git add -A; git reset --hard |
|
} |
|
New-Alias -Name reset -Value GitResetToLastCommit |
|
New-Alias -Name re -Value GitResetToLastCommit |
|
$i += "re, reset -> git add -A; git reset --hard" |
|
|
|
function GitStash { |
|
Write-Host "Adding changes and stashing (git add -A; git stash $args)" |
|
& git add -A; git stash $args |
|
} |
|
New-Alias -Name stash -Value GitStash |
|
$i += "stash -> git add -A; git stash" |
|
|
|
function GitDiff { & git diff } |
|
New-Alias -Name di -Value GitDiff |
|
$i += "di -> git diff" |
|
$i += '```' |
|
|
|
$i += "" |
|
$i += "## Folders ------------------------------------------" |
|
$i += '```' |
|
function CdPr { & cd C:\Users\trrensha\code\PR_FOLDER\Shell.MMX } |
|
New-Alias -Name pr -Value CdPr |
|
$i += "pr -> cd to pr directory" |
|
|
|
function CdFirst { & cd C:\Users\trrensha\code\Shell.MMX } |
|
New-Alias -Name first -Value CdFirst |
|
New-Alias -Name one -Value CdFirst |
|
$i += "one, first -> cd to first code folder (C:\Users\trrensha\code\Shell.MMX)" |
|
|
|
|
|
function CdSecond { & cd C:\Users\trrensha\code\DUPLICATE\Shell.MMX } |
|
New-Alias -Name second -Value CdSecond |
|
New-Alias -Name dup -Value CdSecond |
|
New-Alias -Name two -Value CdSecond |
|
$i += "two, second, dup -> cd to second code folder" |
|
|
|
|
|
function CdThird { & cd C:\Users\trrensha\code\TRIPLICATE\Shell.MMX } |
|
New-Alias -Name third -Value CdThird |
|
New-Alias -Name trip -Value CdThird |
|
New-Alias -Name three -Value CdThird |
|
$i += "three, third, trip -> cd to third code folder" |
|
|
|
function CdFourth { & cd C:\Users\trrensha\code\QUATERNARY\Shell.MMX } |
|
New-Alias -Name fourth -Value CdFourth |
|
New-Alias -Name quat -Value CdFourth |
|
New-Alias -Name quad -Value CdFourth |
|
New-Alias -Name four -Value CdFourth |
|
$i += "four, fourth, quad -> cd to fourth code folder, also quat works" |
|
|
|
# go to code base directory |
|
function CdCode { & cd C:\Users\trrensha\code } |
|
New-Alias -Name cdc -Value CdCode |
|
New-Alias -Name cc -Value CdCode |
|
$i += "cc, cdc -> cd to base code folder" |
|
|
|
function CdData { & cd C:\Users\trrensha\code\data } |
|
New-Alias -Name dat -Value CdData |
|
$i += "dat -> cd to data repo" |
|
|
|
function CdCDP { & cd C:\Users\trrensha\code\cdp } |
|
New-Alias -Name cdp -Value CdCDP |
|
$i += "cdp -> cd to cdp repo" |
|
|
|
function CdAppManager { & cd C:\Users\trrensha\code\YourPhoneCompanion } |
|
New-Alias -Name appManager -Value CdAppManager |
|
New-Alias -Name ypc -Value CdAppManager |
|
$i += "ypc, appManager -> cd to YPC repo" |
|
|
|
function CdDownloads { & cd C:\Users\trrensha\Downloads } |
|
New-Alias -Name down -Value CdDownloads |
|
New-Alias -Name download -Value CdDownloads |
|
New-Alias -Name downloads -Value CdDownloads |
|
$i += "down, download/s -> cd to downloads folder" |
|
|
|
function CdDocuments { & cd C:\Users\trrensha\Documents } |
|
New-Alias -Name docs -Value CdDocuments |
|
New-Alias -Name documents -Value CdDocuments |
|
New-Alias -Name doc -Value CdDocuments |
|
$i += "doc/s, documents -> cd to documents folder" |
|
|
|
# go to code base directory |
|
function See-MyBranches { |
|
$loc = Get-Location |
|
"First" |
|
cd C:\Users\trrensha\code\Shell.MMX; git branch |
|
"Dup" |
|
cd C:\Users\trrensha\code\DUPLICATE\Shell.MMX; git branch |
|
"Trip" |
|
cd C:\Users\trrensha\code\TRIPLICATE\Shell.MMX; git branch |
|
"Quat" |
|
cd C:\Users\trrensha\code\QUATERNARY\Shell.MMX; git branch |
|
"PR" |
|
cd C:\Users\trrensha\code\PR_FOLDER\Shell.MMX; git branch |
|
& cd $loc |
|
} |
|
New-Alias -Name lb -Value See-MyBranches |
|
New-Alias -Name branches -Value See-MyBranches |
|
$i += "lb, branches -> see what branches my repos are in" |
|
|
|
$i += '```' |
|
$i += "## Functions ----------------------------------------" |
|
$i += '```' |
|
function Blue() { |
|
Write-Host |
|
Write-Host $args -ForegroundColor DarkBlue |
|
} |
|
$i += "blue() -> print out string with blue foreground" |
|
|
|
|
|
$i += "he, macro-help -> print out this information, add -raw or other flag to print out md to console" |
|
function Get-MacroHelp { |
|
if ($args){ |
|
write-host "Printing out raw format" |
|
} |
|
& Write-Host Macro usage, file found: |
|
$PSCommandPath |
|
foreach ($item in $i) { |
|
# -or $item[0] -eq '#' |
|
if (!$args -and ($item[0] -eq '`') ){ |
|
# write-host "Don't print" |
|
} else { |
|
Write-Host $item |
|
} |
|
} |
|
# clear |
|
} |
|
New-Alias -Name he -Value Get-MacroHelp |
|
New-Alias -Name macro-help -Value Get-MacroHelp |
|
$i += '```' |
|
|
|
|
|
he # print out on load |