# switch profile based on platform, architecture, IDE -- this isn't complete
############
# PLATFORM #
############
if ($IsLinux -or $IsMacOS){
<#
You will not have the environment PSProvider called $env: on linux machines. You will either have to...
a. create a variable using New-Variable (e.g., 'New-Variable -Name zenv:TEMP -Value ...' )
b. modify built-in environment file (e.g., '/etc/environment/', '~/.profile', '~/.bashrc')
ba. I'm not sure if you can prefix a variable with a '$'.
c. create the environment PSProvider (e.g., New-PSDrive -PSProvider Environment -Name zEnv: ...')
.LINKS
https://www.redhat.com/sysadmin/linux-environment-variables
https://www.certdepot.net/rhel7-set-environment-variable/
#>
$env:USERNAME = [System.Environment]::UserName
$env:COMPUTERNAME = [System.Environment]::MachineName
$env:TEMP = [System.IO.Path]::GetTempPath()
}
###############
# CREDENTIALS #
###############
$adminCreds = Get-Credential
############################################
# Integrated Development Environment (IDE) #
############################################
$hostProfiles = Get-Content -Path .\host_profiles.json | ConvertFrom-Json
$myProfile = @{
Exists = Test-Path -Path $profile
Host = [PSCustomObject]@{
'ConsoleHost' = [PSCustomObject]@{
'Windows PowerShell' = $hostProfiles.'Windows PowerShell'
'PowerShell 7' = $hostProfiles.'PowerShell 7'
}
'Windows PowerShell ISE Host' = $hostProfiles.'Windows PowerShell ISE Host'
'Visual Studio Code Host' = $hostProfiles.'Visual Studio Code Host'
}
}
$architecture = if ([System.Environment]::Is64BitOperatingSystem -eq $true){
'x64'
} else {
'x86'
}
if ($myProfile.Exists -eq $false){
switch ($Host.Name){
'ConsoleHost' {
if ($Host.Version -lt [version]'6.0.0.0'){
Write-Verbose -Message ('Windows PowerShell (v{0} {1})' -f $Host.Version, $architecture) -Verbose
New-Item -Path $profile -ItemType File -Value $myProfile.Host.ConsoleHost.'Windows PowerShell'
} else {
Write-Verbose -Message ('PowerShell 7 (v{0} {1})' -f $Host.Version, $architecture) -Verbose
New-Item -Path $profile -ItemType File -Value $myProfile.Host.ConsoleHost.'PowerShell 7'
}
break
}
'Windows PowerShell ISE Host' {
Write-Verbose -Message ('{0} (v{1} {2})' -f $host.Name, $host.Version, $architecture) -Verbose
New-Item -Path $profile -ItemType File -Value $myProfile.Host.'Windows PowerShell ISE Host'
break
}
'Visual Studio Code Host' {
Write-Verbose -Message ('{0} (v{1} {2})' -f $host.Name, $host.Version, $architecture) -Verbose
New-Item -Path $profile -ItemType File -Value $myProfile.Host.'Visual Studio Code Host'
break
}
default {
Write-Warning -Message 'Unknown host...' -Verbose
exit
}
}
}
Last active
June 4, 2023 05:46
-
-
Save gonzalc/0991b0319763f41b60c045c3d10a3eb3 to your computer and use it in GitHub Desktop.
This contains my PowerShell profiles and IDE configuration.
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
# $env:OneDrive\Documents\WindowsPowerShell | |
oh-my-posh init pwsh --config "C:\Users\gonza\OneDrive\Documents\oh-my-posh\easy-term.omp.json" | Invoke-Expression |
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
# $env:OneDrive\Documents\WindowsPowerShell | |
$HOST.UI.RawUI.WindowTitle = "Windows PowerShell ISE - {0}" -f $PSVersionTable.PSVersion.ToString() | |
$psISE.PowerShellTabs.SelectedPowerShellTab.ShowCommands = $false | |
$psISE.Options.SelectedScriptPaneState = 'Right' | |
$psISE.Options.SelectedScriptPaneState = 'Top' | |
###################### | |
# DEFAULT PARAMETERS # | |
###################### | |
try { | |
[void]$PSDefaultParameterValues.Add('Export-Csv:NoTypeInformation', $true) | |
[void]$PSDefaultParameterValues.Add('Format-*:Wrap', $true) | |
[void]$PSDefaultParameterValues.Add('Enter-PSSession:Credential', $adminCreds) | |
[void]$PSDefaultParameterValues.Add('*-AD*:Credential', $adminCreds) | |
} | |
catch { | |
$throw | |
} |
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
# $env:OneDrive\Documents\PowerShell | |
oh-my-posh init pwsh --config "$env:OneDrive\Documents\oh-my-posh\easy-term.omp.json" | Invoke-Expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment