Skip to content

Commit

Permalink
removed Set-Prompt alias to fix #27 and cleaned up classes a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Nov 2, 2019
1 parent 4239ac6 commit 9a9e39c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 82 deletions.
162 changes: 81 additions & 81 deletions PSProfile/Classes/PSProfile.Classes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ class PSProfile {
Default = "AWS: "
}
}
PSReadline = @{
Options = @{}
KeyHandlers = @{}
PSReadline = @{
Options = @{ }
KeyHandlers = @{ }
}
}
$this.RefreshFrequency = (New-TimeSpan -Hours 1).ToString()
$this.LastRefresh = [datetime]::Now.AddHours(-2)
$this.LastSave = [datetime]::Now
$this.ProjectPaths = @()
$this.PluginPaths = @()
$this.InitScripts = @{}
$this.InitScripts = @{ }
$this.ScriptPaths = @()
$this.PathAliases = @{
'~' = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
Expand Down Expand Up @@ -245,7 +245,7 @@ if ($env:AWS_PROFILE) {
"`n>> "'
$plugPaths = @((Join-Path $PSScriptRoot "Plugins"))
$curVer = (Import-Metadata (Join-Path $PSScriptRoot "PSProfile.psd1")).ModuleVersion
$this.PluginPaths | Where-Object {-not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
$this.PluginPaths | Where-Object { -not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
$plugPaths += $_
}
$this.PluginPaths = $plugPaths | Select-Object -Unique
Expand Down Expand Up @@ -351,16 +351,16 @@ if ($env:AWS_PROFILE) {
"Verbose"
)
[hashtable[]]$final = @()
$this.$section | Where-Object {$_ -is [hashtable] -and $_.Name} | ForEach-Object {
$this.$section | Where-Object { $_ -is [hashtable] -and $_.Name } | ForEach-Object {
$final += $_
}
$this.$section | Where-Object {$_ -is [string]} | ForEach-Object {
$this.$section | Where-Object { $_ -is [string] } | ForEach-Object {
$this._log(
"[$section] Converting module string to hashtable: $_",
"CleanConfig",
"Verbose"
)
$final += @{Name = $_}
$final += @{Name = $_ }
}
$this.$section = $final
}
Expand All @@ -371,7 +371,7 @@ if ($env:AWS_PROFILE) {
"Verbose"
)
[string[]]$final = @()
$this.$section | Where-Object {-not [string]::IsNullOrEmpty($_)} | ForEach-Object {
$this.$section | Where-Object { -not [string]::IsNullOrEmpty($_) } | ForEach-Object {
$final += $_
}
$this.$section = $final
Expand Down Expand Up @@ -638,33 +638,33 @@ if ($env:AWS_PROFILE) {
$g = 0
$b = 0
$pInfo.EnumerateDirectories('.git',[System.IO.SearchOption]::AllDirectories) | ForEach-Object {
$PathName = $_.Parent.BaseName
$PathName = $_.Parent.Name
$FullPathName = $_.Parent.FullName
$g++
$this._log(
"Found git project @ $($FullPathName)",
'FindProjects',
'Verbose'
)
$currPath = $_
while($this.GitPathMap.ContainsKey($PathName)){
$currPath = $currPath.Parent
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
$this.GitPathMap["$($doublePath.Parent)\$($doublePath.BaseName)"] = $doublePath.FullName
$this.GitPathMap.Remove($PathName)
if($this.PSBuildPathMap.ContainsKey($PathName)){
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
$this.PSBuildPathMap["$($PSBuildPath.Parent)\$($PSBuildPath.BaseName)"] = $doublePath.FullName
$this.PSBuildPathMap.Remove($PathName)
}
$PathName = "$($currPath.Parent.BaseName)\$PathName"
$currPath = $_
while ($this.GitPathMap.ContainsKey($PathName)) {
$currPath = $currPath.Parent
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
$this.GitPathMap["$($doublePath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($doublePath.Name)"] = $doublePath.FullName
$this.GitPathMap.Remove($PathName)
if ($this.PSBuildPathMap.ContainsKey($PathName)) {
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
$this.PSBuildPathMap["$($PSBuildPath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($PSBuildPath.Name)"] = $doublePath.FullName
$this.PSBuildPathMap.Remove($PathName)
}
$PathName = "$($currPath.Parent.BaseName)$([System.IO.Path]::DirectorySeparatorChar)$PathName"
}
$this.GitPathMap[$PathName] = $FullPathName
$bldPath = [System.IO.Path]::Combine($FullPathName,'build.ps1')
if ([System.IO.File]::Exists($bldPath)) {
$b++
$this._log(
"Found build script @ $($_.FullName)",
"Found build script @ $($bldPath)",
'FindProjects',
'Verbose'
)
Expand Down Expand Up @@ -954,74 +954,74 @@ if ($env:AWS_PROFILE) {
)
if ($this.Plugins.Count) {
$this.Plugins.ForEach( {
if ($_.Name -ne 'PSProfile.PowerTools') {
$plugin = $_
$this._log(
"'$($plugin.Name)' Searching for plugin",
'LoadPlugins',
'Verbose'
)
try {
$found = $null
$importParams = @{
ErrorAction = 'Stop'
Global = $true
}
if ($plugin.ArgumentList) {
$importParams['ArgumentList'] = $plugin.ArgumentList
}
[string[]]$pathsToSearch = @($this.PluginPaths)
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
$pathsToSearch += $_
}
foreach ($plugPath in $pathsToSearch) {
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
$this._log(
"'$($plugin.Name)' Checking path: $fullPath",
'LoadPlugins',
'Debug'
)
if (Test-Path $fullPath) {
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
if ($plugin.ArgumentList) {
.$sb($plugin.ArgumentList)
}
else {
.$sb
}
$found = $fullPath
break
if ($_.Name -ne 'PSProfile.PowerTools') {
$plugin = $_
$this._log(
"'$($plugin.Name)' Searching for plugin",
'LoadPlugins',
'Verbose'
)
try {
$found = $null
$importParams = @{
ErrorAction = 'Stop'
Global = $true
}
}
if ($null -ne $found) {
$this._log(
"'$($plugin.Name)' plugin loaded from path: $found",
'LoadPlugins',
'Verbose'
)
}
else {
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
Import-Module $plugin.Name @importParams
if ($plugin.ArgumentList) {
$importParams['ArgumentList'] = $plugin.ArgumentList
}
[string[]]$pathsToSearch = @($this.PluginPaths)
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
$pathsToSearch += $_
}
foreach ($plugPath in $pathsToSearch) {
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
$this._log(
"'$($plugin.Name)' plugin loaded from PSModulePath!",
'LoadPlugins'
"'$($plugin.Name)' Checking path: $fullPath",
'LoadPlugins',
'Debug'
)
if (Test-Path $fullPath) {
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
if ($plugin.ArgumentList) {
.$sb($plugin.ArgumentList)
}
else {
.$sb
}
$found = $fullPath
break
}
}
else {
if ($null -ne $found) {
$this._log(
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
"'$($plugin.Name)' plugin loaded from path: $found",
'LoadPlugins',
'Warning'
'Verbose'
)
}
else {
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
Import-Module $plugin.Name @importParams
$this._log(
"'$($plugin.Name)' plugin loaded from PSModulePath!",
'LoadPlugins'
)
}
else {
$this._log(
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
'LoadPlugins',
'Warning'
)
}
}
}
catch {
throw
}
}
catch {
throw
}
}
})
})
}
else {
$this._log(
Expand Down
1 change: 0 additions & 1 deletion PSProfile/PSProfile.Aliases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'Save-Prompt' = 'Add-PSProfilePrompt'
'Get-Prompt' = 'Get-PSProfilePrompt'
'Edit-Prompt' = 'Edit-PSProfilePrompt'
'Set-Prompt' = 'Switch-PSProfilePrompt'
'Switch-Prompt' = 'Switch-PSProfilePrompt'
'Remove-Prompt' = 'Remove-PSProfilePrompt'
'Copy-DynamicParameters' = 'Copy-Parameters'
Expand Down

0 comments on commit 9a9e39c

Please sign in to comment.