internal/configurations/configuration.ps1

<#
This is an example configuration file
 
By default, it is enough to have a single one of them,
however if you have enough configuration settings to justify having multiple copies of it,
feel totally free to split them into multiple files.
#>


<#
# Example Configuration
Set-PSFConfig -Module 'CmdFav' -Name 'Example.Setting' -Value 10 -Initialize -Validation 'integer' -Handler { } -Description "Example configuration setting. Your module can then use the setting using 'Get-PSFConfigValue'"
#>


Set-PSFConfig -Module 'CmdFav' -Name 'Import.DoDotSource' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be dotsourced on import. By default, the files of this module are read as string value and invoked, which is faster but worse on debugging."
Set-PSFConfig -Module 'CmdFav' -Name 'Import.IndividualFiles' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be imported individually. During the module build, all module code is compiled into few files, which are imported instead by default. Loading the compiled versions is faster, using the individual files is easier for debugging and testing out adjustments."
Set-PSFConfig -Module 'CmdFav' -Name 'History' -Value @() -Initialize -Description "Storage of the saved history" -AllowDelete
Set-PSFConfig -Module 'CmdFav' -Name 'HistorySave.Path' -Value "$($env:AppData)\PowerShell\PSFramework\Config" -Initialize -Validation string -Description "DEPRECATED: Where should the history be saved?"

# AutoBackup default config
Set-PSFConfig -Module 'CmdFav' -Name 'AutoBackup.Enabled' -Value $false -Initialize -Validation bool -Description "Enable automatic backup for CmdFav"
Set-PSFConfig -Module 'CmdFav' -Name 'HistorySave.File' -Value "cmdfav.json" -Initialize -Validation string -Description "DEPRECATED: Where should the history be saved?"
Set-PSFConfig -Module 'CmdFav' -Name 'Repository.PERSONALDEFAULT.Path' -Value "$($env:AppData)\PowerShell\PSFramework\Config\cmdfav.xml" -Initialize -Validation string -Description "Where should the history be saved by Default?"

# Determine external editor path (VSCode, Notepad, Nano)
$editorPath = $null
$nppPath = ($editorPath = @(
        "$env:ProgramFiles\Notepad++\notepad++.exe",
        "$env:ProgramFiles(x86)\Notepad++\notepad++.exe",
        "$env:LOCALAPPDATA\Programs\Notepad++\notepad++.exe"
    ) | Where-Object { Test-Path $_ } | Select-Object -First 1)
if (Get-Command code -ErrorAction SilentlyContinue) {
    $editorPath = (Get-Command code).Source
    $waitMode = 'ReadKey'
    $editorParam = '[PATH]'
}
elseif ($nppPath) {
    $editorPath = $nppPath
    $waitMode = 'ReadKey'
    $editorParam = '[PATH]'
}
elseif (Get-Command notepad -ErrorAction SilentlyContinue) {
    $editorPath = (Get-Command notepad).Source
    $waitMode = 'Process'
    $editorParam = '[PATH]'
}
elseif (Get-Command nano -ErrorAction SilentlyContinue) {
    $editorPath = (Get-Command nano).Source
    $waitMode = 'Process'
    $editorParam = '[PATH]'
}

if ($editorPath) {
    Set-PSFConfig -Module 'CmdFav' -Name 'ExternalEditor.Path' -Value $editorPath -Initialize -Validation string -Description "Path to the preferred external editor (VSCode, Notepad, Nano)"
    Set-PSFConfig -Module 'CmdFav' -Name 'ExternalEditor.WaitMode' -Value $waitMode -Initialize -Validation string -Description "How CmdFav should wait for the editor to finish (Process or ReadKey)"
    Set-PSFConfig -Module 'CmdFav' -Name 'ExternalEditor.Parameter' -Value $editorParam -Initialize -Validation string -Description "Parameter for Nano ([PATH] as placeholder for file)"
}


$settings = @{
    IncludeRules = @(
        'PSPlaceOpenBrace',
        'PSPlaceCloseBrace',
        'PSUseConsistentWhitespace',
        'PSUseConsistentIndentation',
        'PSAlignAssignmentStatement',
        'PSUseCorrectCasing'
    )

    Rules        = @{
        PSAvoidUsingCmdletAliases  = @{}
        PSPlaceOpenBrace           = @{
            Enable             = $true
            OnSameLine         = $true
            NewLineAfter       = $true
            IgnoreOneLineBlock = $true
        }

        PSPlaceCloseBrace          = @{
            Enable             = $true
            NewLineAfter       = $true
            IgnoreOneLineBlock = $true
            NoEmptyLineBefore  = $false
        }

        PSUseConsistentIndentation = @{
            Enable              = $true
            Kind                = 'space'
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            IndentationSize     = 4
        }

        PSUseConsistentWhitespace  = @{
            Enable                                  = $true
            CheckInnerBrace                         = $true
            CheckOpenBrace                          = $true
            CheckOpenParen                          = $true
            CheckOperator                           = $true
            CheckPipe                               = $true
            CheckPipeForRedundantWhitespace         = $false
            CheckSeparator                          = $true
            CheckParameter                          = $false
            IgnoreAssignmentOperatorInsideHashTable = $true
        }

        PSAlignAssignmentStatement = @{
            Enable         = $true
            CheckHashtable = $true
        }

        PSUseCorrectCasing         = @{
            Enable = $true
        }
    }
}

Set-PSFConfig -Module 'CmdFav' -Name 'Formatting.Settings' -Value $settings -Initialize -Description "Formatting settings for Invoke-Formatter used by CmdFav"