Last active
December 12, 2023 22:58
-
-
Save smarkwell/da55cb71f8ca3773395bb6f19f03d1ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Located %USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 | |
Set-StrictMode -Version 2.0 | |
Set-PSReadlineOption -BellStyle Visual | |
$env:NOENV_PATH = $env:Path | |
$env:JAVA8_HOME = "C:\Program Files\Eclipse Adoptium\jdk-8.0.345.1-hotspot" | |
$env:JAVA17_HOME = "C:\Program Files\Eclipse Adoptium\jdk-17.0.5.8-hotspot" | |
$env:JAVA11_HOME = "C:\Program Files\Eclipse Adoptium\jdk-11.0.17.8-hotspot" | |
$env:CLOUD_SQL_PROXY = "${home}\dev\cloud_sql_proxy\cloud_sql_proxy_x64.exe" | |
$env:ANT10_HOME = $null | |
$env:ANT9_HOME = $null | |
$env:ANT_ARGS = $null | |
$env:MAVEN_HOME = "${home}\dev\maven\apache-maven-3.8.6" | |
$env:GRADLE_HOME = $null | |
$env:RUBY23_HOME = $null | |
$env:TOMCAT6_BASE = $null | |
$env:NODEJS_9_HOME = $null | |
$env:NPM_GLOBAL = $null | |
$env:GIT_HOME = $null | |
$env:PYTHON_27_HOME = $null | |
$env:PYTHON_310_HOME = "C:\Program Files\Python310" | |
$env:NUGET_HOME = $null | |
function loadenv($DevEnv) | |
{ | |
$env:Path = $env:NOENV_PATH | |
#Default Mappings | |
$env:NODEJS_HOME = $env:NODEJS_9_HOME | |
switch ($DevEnv) | |
{ | |
"java17" | |
{ | |
$env:JAVA_HOME = $env:JAVA17_HOME | |
} | |
"java11" | |
{ | |
$env:JAVA_HOME = $env:JAVA11_HOME | |
} | |
default | |
{ | |
$env:JAVA_HOME = $env:JAVA8_HOME | |
$env:ANT_HOME = $env:ANT10_HOME | |
addtopath $env:ANT_HOME "bin" | |
addtopath $env:RUBY23_HOME "bin" | |
addtopath $env:GRADLE_HOME "bin" | |
} | |
} | |
$env:JDK_HOME = $env:JAVA_HOME | |
addPythonToPath $env:PYTHON_310_HOME | |
addtopath $env:JAVA_HOME "bin" $true | |
addtopath $env:MAVEN_HOME "bin" | |
addtopath $env:GIT_HOME "bin" | |
addtopath $env:NODEJS_HOME | |
addtopath $env:NPM_GLOBAL | |
addtopath $env:NUGET_HOME | |
addtopath $env:CLOUD_SQL_PROXY | |
} | |
# Python uses Scripts\ instead of bin/ | |
function addPythonToPath($pythonHome) | |
{ | |
addtopath $pythonHome | |
addtopath $pythonHome "Scripts" | |
} | |
function addtopath([String] $path,[String] $subfolder, [bool] $override = $false) | |
{ | |
if ($null -ne $path) | |
{ | |
if($null -ne $subfolder) | |
{ | |
$path = $path + "\" + $subfolder | |
} | |
if ($override) { | |
$env:Path = ($path + ";" + $env:Path) | |
} else { | |
$env:Path = ($env:Path + ";" +$path) | |
} | |
} | |
} | |
# Prompt gets called to display the prompt on every line by the system. | |
function prompt | |
{ | |
$host.ui.RawUI.WindowTitle = $(get-location).toString() + " - P:" + (get-process).count + " Cmd@:" + (get-date -displayhint time) +" - Pow Pow Powershell!" | |
Write-Host("" + $(get-location) + ">") -nonewline -foreground $env:console_bg -backgroundColor $env:console_fg | |
return " " | |
} | |
function clippath() | |
{ | |
Set-Clipboard -Text $(get-location).toString() | |
} | |
function isAdmin() | |
{ | |
return (New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
} | |
function reload() | |
{ | |
split.target $(get-location).toString() $false | |
Stop-Process -Id $PID | |
} | |
function goAdmin() | |
{ | |
split.target $(get-location).toString() $true | |
Stop-Process -Id $PID | |
} | |
function split() | |
{ | |
split.target $(get-location).toString() $false | |
} | |
function db($targets) | |
{ | |
$connections = [System.Collections.Generic.List[string]]::new() | |
switch($targets) | |
{ | |
{"dev" -contains $_} | |
{ | |
$connections.Add("-instances=<ADDRESS>=tcp:<EXPOSE>") | |
} | |
} | |
foreach($connect in $connections) | |
{ | |
start-process $env:CLOUD_SQL_PROXY -ArgumentList $connect | |
} | |
} | |
function open.sqlite($target) | |
{ | |
if($target) | |
{ | |
$file = Resolve-Path $target | |
$launchArgs = "-con ""driver=sqlite|database=${file}|name=${file}|openConsole=true|folder=SQLite""" | |
Start-Process dbeaver-cli.exe -ArgumentList $launchArgs | |
} | |
else | |
{ | |
"Provide a SQLite File Path" | |
} | |
} | |
function split.target($target, $admin) | |
{ | |
$launchArgs = "" | |
if(!$target) | |
{ | |
$launchArgs ="new-tab powershell -NoExit" | |
} | |
else | |
{ | |
$command = 'push-location ''' + $target + '''' | |
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command) | |
$encodedCMD = [Convert]::ToBase64String($bytes) | |
$launchArgs = "new-tab powershell -NoExit -encodedCommand $encodedCMD" | |
} | |
if($admin) | |
{ | |
start-process wt -Verb runAs -ArgumentList $launchArgs | |
} | |
else | |
{ | |
start-process wt -ArgumentList $launchArgs | |
} | |
} | |
New-Alias which Get-Command | |
# Load the default ENV | |
loadenv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment