Browse Source

MyConfig modifications

Moved configuration into src/config.files.json, it will also load
src/config.files.local.json (which will not be included in the git repo)

Added Git-Path to resolve paths simply, even when Path does not exist.
master
lksz 1 year ago
parent
commit
524bce25de
4 changed files with 65 additions and 20 deletions
  1. +2
    -0
      Edit-MyConfig.ps1
  2. +8
    -0
      Get-Path.ps1
  3. +18
    -20
      profile.d/MyConfig.class.ps1
  4. +37
    -0
      src/config.files.json

+ 2
- 0
Edit-MyConfig.ps1 View File

@@ -20,3 +20,5 @@ if( -not $ConfigName ) {
$local:ScriptPaths = [MyConfig]::GetConfigPaths($ConfigName,$Force)

Edit-TextFile -sudo:$sudo $ScriptPaths

$null = [MyConfig]::_GetValidValues('', $true)

+ 8
- 0
Get-Path.ps1 View File

@@ -0,0 +1,8 @@
[CmdletBinding()]param([string]$Path)

try {
get-item $Path -Force -ErrorAction Stop |
Select-Object -ExpandProperty FullName
} catch {
$_.targetObject
}

+ 18
- 20
profile.d/MyConfig.class.ps1 View File

@@ -1,28 +1,27 @@
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'
hidden static [string[]]$_MyConfigDictionaryPath = @(
$(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'config.files.json'),
$(Join-Path $(Join-Path $MyPSScriptRoot 'src') 'config.files.local.json')
)
static [hashtable]GetConfigDictionary() {
$local:result = @{}
$result['myconfig'] = [MyConfig]::_MyConfigDictionaryPath;
foreach( $local:jsonSource in [MyConfig]::_MyConfigDictionaryPath ) {
if( -not ( Test-Path $jsonSource ) ) { continue }
foreach( $local:prop in $(Get-Content $jsonSource | ConvertFrom-Json).PSObject.Properties ) {
$result[$prop.Name] = $prop.Value
}
}
return $result;
}
static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) {
[MyConfig]::ReloadConfigPaths()
$local:configDirectory = [MyConfig]::GetConfigDictionary()
$local:result = [string[]]@()
$local:flat = $false
while(-not $flat) {
$flat = $true
$ConfigNames += $ConfigNames | ForEach-Object {
[MyConfig]::configDirectory[$_]
$configDirectory[$_]
} | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object {
$_.Substring(1)
} | Where-Object { $_ -notin $ConfigNames } | ForEach-Object {
@@ -31,7 +30,7 @@ class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
}

$local:flatConfigList = $ConfigNames | ForEach-Object {
[MyConfig]::configDirectory[$_]
$configDirectory[$_]
} | Where-Object { $_ -notmatch '^#[\w-\.]+$' }

$local:exists = $false;
@@ -39,7 +38,7 @@ class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
foreach( $local:configPath in $flatConfigList ) {
if( -not $first ) { $first = $configPath }
if( $Force -or (Test-Path $configPath) ) {
$result += Resolve-Path $configPath
$result += Get-Path $configPath
$exists = $true
}
}
@@ -49,8 +48,7 @@ class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
return $result
}
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
[MyConfig]::ReloadConfigPaths()
$local:possibleValues = [MyConfig]::configDirectory.Keys
$local:possibleValues = [MyConfig]::GetConfigDictionary().Keys
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
}



+ 37
- 0
src/config.files.json View File

@@ -0,0 +1,37 @@
{
"neovim": [
"~/.config/nvim/init.vim",
"~/.config/nvim/vim-plug/plugins.vim",
"#vim",
"#vi"
],
"sz-shrc": "~/.sz.shrc.sh",
"sz-rc-all": [
"#sz-aliases-sh",
"#sz-local-rc",
"#sz-shrc",
"#sz-zshrc",
"#zshrc"
],
"vi": "~/.virc",
"sz-local-rc": "~/.sz.local.sh",
"zshrc": "~/.zshrc",
"ansible": [
"/etc/ansible/ansible.cfg",
"/opt/ansible/ansible.cfg",
"/opt/ansible/hosts"
],
"sz-aliases-sh": "~/.sz.aliases.sh",
"vim": [
"~/.vimrc",
"~/.vim/vimrc"
],
"sz-zshrc": [
"~/.sz.zshrc.sh",
"#zshrc"
],
"tmux": [
"~/.tmux.conf",
"~/.byobu/.tmux.conf"
]
}

Loading…
Cancel
Save