class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator { static [hashtable]$configDirectory = @{}; static ReloadConfigPaths() { [MyConfig]::ConfigDirectory = [ordered]@{ 'vi' = '~/.virc' 'vim' = '~/.vimrc','~/.vim/vimrc' 'neovim' = '~/.config/nvim/init.vim','~/.config/nvim/vim-plug/plugins.vim','#vim','#vi' 'zshrc' = '~/.zshrc' 'sz-zshrc' = '~/.sz.zshrc.sh', '#zshrc' 'sz-local-rc' = '~/.sz.local.sh' 'sz-aliases-sh' = '~/.sz.aliases.sh' 'sz-shrc' = '~/.sz.shrc.sh' 'sz-rc-all' = '#sz-aliases-sh', '#sz-local-rc', '#sz-shrc', '#sz-zshrc', '#zshrc' 'tmux' = '~/.tmux.conf', '~/.byobu/.tmux.conf' 'ansible' = '/etc/ansible/ansible.cfg', '/opt/ansible/ansible.cfg' } } static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) { [MyConfig]::ReloadConfigPaths() $local:result = [string[]]@() $local:flat = $false while(-not $flat) { $flat = $true $ConfigNames += $ConfigNames | ForEach-Object { [MyConfig]::configDirectory[$_] } | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object { $_.Substring(1) } | Where-Object { $_ -notin $ConfigNames } | ForEach-Object { $flat = false; $_; } } $local:flatConfigList = $ConfigNames | ForEach-Object { [MyConfig]::configDirectory[$_] } | Where-Object { $_ -notmatch '^#[\w-\.]+$' } $local:exists = $false; $local:first = $null foreach( $local:configPath in $flatConfigList ) { if( -not $first ) { $first = $configPath } if( $Force -or (Test-Path $configPath) ) { $result += Resolve-Path $configPath $exists = $true } } if( -not $exists -and -not $Force ) { $result += $first } return $result } static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) { [MyConfig]::ReloadConfigPaths() $local:possibleValues = [MyConfig]::configDirectory.Keys return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict ); } [String[]] GetValidValues() { return [MyConfig]::_GetValidValues('',$true) } }