diff --git a/.gitmodules b/.gitmodules index 337f0de..d551f1a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "modules/Git/posh-git"] path = modules/Git/posh-git url = https://github.com/dahlbyk/posh-git.git +[submodule "modules/Cli/ArgParser"] + path = modules/Cli/ArgParser + url = https://github.com/buriedstpatrick/ArgParser diff --git a/modules/AutoHotkey/.gitignore b/modules/AutoHotkey/.gitignore new file mode 100644 index 0000000..26e8f28 --- /dev/null +++ b/modules/AutoHotkey/.gitignore @@ -0,0 +1 @@ +*.ahk \ No newline at end of file diff --git a/modules/AutoHotkey/AutoHotkey.psm1 b/modules/AutoHotkey/AutoHotkey.psm1 new file mode 100644 index 0000000..a207fa5 --- /dev/null +++ b/modules/AutoHotkey/AutoHotkey.psm1 @@ -0,0 +1,54 @@ +function Invoke-AutoHotkeyKeybindings($config) { + Get-ChildItem (Join-Path $env:PWSH_REPO "modules" "AutoHotkey" "*.ahk.TEMPLATE") | ForEach-Object { + $destination = $_.FullName.Replace(".TEMPLATE", "") + if (!(Test-Path $destination)) { + Get-Content $_.FullName | Format-EnvironmentVariables | Format-ConfigValues -Config (Get-Config) | Out-File $destination + } + } + + if ($config.loadKeybindsOnStartup -and !(Test-Path (Join-Path $env:APPDATA "Microsoft" "Windows" "Start Menu" "Programs" "Startup" "Keybinds.ahk"))) { + Install-AutoHotkeyKeybindings + } +} + +function Install-AutoHotkeyKeybindings { + $startupDir = (Join-Path $env:APPDATA "Microsoft" "Windows" "Start Menu" "Programs" "Startup") + + if (!(Test-IsAdministrator)) { + Write-ErrorMessage "Unable to install AutoHotkey keybinds. Please run your as administrator to install." + return + } + + # Create symbolic links in startup directory + Get-ChildItem -Exclude *.TEMPLATE (Join-Path $env:PWSH_REPO "modules" "AutoHotkey" "*.ahk") | ForEach-Object { + $destination = (Join-Path $startupDir $_.Name) + if (!(Test-Path $destination)) { + Write-InfoMessage "Installing $($_.Name)" + + New-Item -ItemType SymbolicLink ` + -Path $destination ` + -Value $_.FullName + } + } +} + +function Uninstall-AutoHotkeyKeybindings { + if (!(Test-IsAdministrator)) { + Write-ErrorMessage "Unable to uninstall AutoHotkey keybinds. Please run this command in an administrator context." + return + } + + $destination = (Join-Path $env:APPDATA "Microsoft" "Windows" "Start Menu" "Programs" "Startup" "Keybinds.ahk") + if (!(Test-Path $destination)) { + Write-ErrorMessage "Unable to uninstall AutoHotkey keybinds. The symbolic link does not exist." + return + } + + Remove-Item $destination +} + +$config = (Get-Config).modules.AutoHotkey + +if ($config.enabled -and !($null -eq $config.config)) { + Invoke-AutoHotkeyKeybindings $config.config +} diff --git a/modules/AutoHotkey/Keybinds.ahk.TEMPLATE b/modules/AutoHotkey/Keybinds.ahk.TEMPLATE new file mode 100644 index 0000000..0bc423c --- /dev/null +++ b/modules/AutoHotkey/Keybinds.ahk.TEMPLATE @@ -0,0 +1,17 @@ +#SingleInstance,Force + +; Open Windows Terminal on Windows+Enter +#{modules.AutoHotkey.config.binds.terminal}:: + Run, "#{terminal.path}" #{terminal.args} + return + +; Open Slack on Super+S +LWin & s:: + Run, "${LOCALAPPDATA}\slack\slack.exe" + return + +; Stop keybinds +#{modules.AutoHotkey.config.binds.stop}::ExitApp + +; Reload keybinds +#{modules.AutoHotkey.config.binds.reload}::Reload diff --git a/modules/AutoHotkey/readme.md b/modules/AutoHotkey/readme.md new file mode 100644 index 0000000..50c0c1c --- /dev/null +++ b/modules/AutoHotkey/readme.md @@ -0,0 +1,9 @@ +# AutoHotkey keybinds + +Adds a couple of global keybinds that work outside of the terminal context. AutoHotkey is required. + +| Keybind | Action | +|---------------|------------------------------------------------------------| +| `Super+Enter` | Open terminal instance (Configure terminal in `pwsh.yaml`) | +| `Super+Q` | Stop all keybinds | +| `Super+R` | Re-load all keybinds | diff --git a/modules/Cli/ArgParser b/modules/Cli/ArgParser new file mode 160000 index 0000000..41e57a8 --- /dev/null +++ b/modules/Cli/ArgParser @@ -0,0 +1 @@ +Subproject commit 41e57a82ee3a4a4ec47593b6becb99b4e68842b4 diff --git a/modules/Cli/Cli.psm1 b/modules/Cli/Cli.psm1 new file mode 100644 index 0000000..0cc565e --- /dev/null +++ b/modules/Cli/Cli.psm1 @@ -0,0 +1,91 @@ +function New-ProfileAlias { + Write-Host "hello!" +} + +$commands = @{ + "alias" = @{ + "add" = "New-ProfileAlias" + } + "keybinds" = @{ + "install" = "Install-AutoHotkeyKeybindings" + "uninstall" = "Uninstall-AutoHotkeyKeybindings" + } +} + +function Invoke-LoadArgParser { + # Check that module was fetched via Git. If not, update submodules. + if (!(Test-Path (Join-Path $env:PWSH_REPO "modules" "Cli" "ArgParser" "Output" "ArgParser" "ArgParser.psd1"))) { + Push-Location $env:PWSH_REPO + try { + git submodule init + git submodule update + } finally { + Pop-Location + } + } + + # Check that module was build. If not, run build + if (!(Test-Path (Join-Path $env:PWSH_REPO "modules" "Cli" "ArgParser" "Output" "ArgParser" "ArgParser.psd1"))) { + Push-Location (Join-Path $env:PWSH_REPO "modules" "Cli" "ArgParser") + try { + .\Install-Requirements.ps1 + .\Start-ModuleBuild.ps1 + } finally { + Pop-Location + } + } + + # Import the module + Import-Module (Join-Path $env:PWSH_REPO "modules" "Cli" "ArgParser" "Output" "ArgParser") +} + +function Invoke-ProfileCli { + # Load ArgParser module + Invoke-LoadArgParser + + # Parse arguments into an array, assume arguments space delimited + try { + $arguments = $args.Split(' ') + } catch { + # Unable to parse arguments which probably means nothing was entered beyond the root command 'profile' + # Print a user-friendly message, perhaps the help documentation + Write-Host "Usage: profile " + return + } + + # Hack: Force $arguments to be an array even if it's only a single entry. + # PowerShell treats single entry arrays as strings otherwise. + if (($arguments -is [string])) { + $arguments = @($arguments) + } + + # Print the version of the CLI if requested + if (Get-ArgParserHasSwitch -Name "version" -ShortName "v" -Arguments $arguments) { + Write-Host "Version: 1.0.0.0" + } + + # Print helpful documentation of the CLI if requested, break out of application flow + if (Get-ArgParserHasSwitch -Name "help" -ShortName "h" -Arguments $arguments) { + Write-Help @args + return + } + + $scope = Get-ArgParserScope -Arguments $arguments + + # $name = Get-ArgParserStringValue -Name "name" -ShortName "n" -Arguments $arguments + # if ($name) { + # Write-Host "Hello, $name! You have been reported to the authorities, have a great day :D" + # } + + $index = 0 + $command = $commands + $scope | ForEach-Object { + $command = $command[$_] + $index++ + } | Select-Object -Last 1 + + $command | Invoke-Expression +} + +Set-Alias profile Invoke-ProfileCli +Export-ModuleMember -Function Invoke-ProfileCli -Alias profile diff --git a/modules/Cli/Write-Help.psm1 b/modules/Cli/Write-Help.psm1 new file mode 100644 index 0000000..1d51e0d --- /dev/null +++ b/modules/Cli/Write-Help.psm1 @@ -0,0 +1,50 @@ +function Write-Help { + $action = (Get-Content (Join-Path $env:PWSH_REPO "modules" "Cli" "actions.json") | ConvertFrom-Json) + $args | Where-Object { !($_ -like '-*') } | ForEach-Object { + $action = $action."$_" + } + + $helpText = $action.helpText + if(!($null -eq $helpText)) { + Write-Output "Description:" + Write-Output ("`t$helpText" | Format-EnvironmentVariables) + } + + $flags = $action.flags + if(!($null -eq $flags) -and ($flags.Length -gt 0)) { + Write-Output "Flags:" + $flags.PSObject.Properties | ForEach-Object { + $required = $_.Value.required -eq $true ? " [REQUIRED]" : "" + + $shortName = $_.Value.shortName ? ", -$($_.Value.shortName)" : $null + Write-Output "`t--$($_.Name)$shortName [$($_.Value.type)]$required" + + if ($_.Value.helpText) { + Write-Output ("`t`t$($_.Value.helpText)" | Format-EnvironmentVariables) + } + + if ($_.Value.default) { + Write-Output ("`t`tDefault: $($_.Value.default)" | Format-EnvironmentVariables) + } + } + } + + $examples = $action.examples + if(!($null -eq $examples) -and ($examples.Length -gt 0)) { + Write-Output "Examples:" + $examples | ForEach-Object { + Write-Output ("`t$_" | Format-EnvironmentVariables) + } + } + + $commands = $action.PSObject.Properties | Where-Object { + !($_.Name -like 'helpText') -and !($_.Name -like 'examples') -and !($_.Name -like 'flags') + } + + if ($commands.Length -gt 0) { + Write-Output "Commands:" + $commands | ForEach-Object { + Write-Output ("`t$($_.Name) - $($_.Value.helpText)" | Format-EnvironmentVariables) + } + } +} \ No newline at end of file diff --git a/modules/Cli/actions.json b/modules/Cli/actions.json new file mode 100644 index 0000000..2523653 --- /dev/null +++ b/modules/Cli/actions.json @@ -0,0 +1,81 @@ +{ + "helpText": "Manage PWSH profile. Use --help for more information about a command scope.", + "config": { + "helpText": "Manage configuration", + "get": { + "helpText": "Display current config" + }, + "find": { + "helpText": "Output the path to the config file" + }, + "edit": { + "helpText": "Edit config with default configured editor (${EDITOR})" + } + }, + "update" : { + "helpText": "Update the PWSH profile to the latest commit on your currently configured branch." + }, + "reload": { + "helpText": "Reload profile" + }, + "alias": { + "helpText": "Manage aliases for this CLI", + "add": { + "helpText": "Add an alias to the profile", + "flags": { + "name": { + "helpText": "Name of the alias", + "type": "string", + "required": true + } + } + }, + "remove": { + "helpText": "Remove a path from the profile", + "flags": { + "name": { + "helpText": "Name of the alias to remove", + "type": "string", + "required": true + } + } + }, + "list": { + "helpText": "List configured profile aliases" + } + }, + "path": { + "helpText": "Manage paths", + "add": { + "helpText": "Add a path to the profile", + "flags": { + "path": { + "helpText": "Path to add", + "type": "string", + "required": true + } + } + }, + "remove": { + "helpText": "Remove a path from the profile", + "flags": { + "path": { + "helpText": "Path to remove", + "type": "string", + "required": true + } + } + }, + "list": { + "helpText": "List profile paths", + "flags": { + "all": { + "helpText": "Print entire path list, not just locally configured in pwsh.yaml", + "shortName": "a", + "type": "switch", + "default": false + } + } + } + } +} diff --git a/modules/Core/Config.psm1 b/modules/Core/Config.psm1 index 27292aa..c5bc532 100644 --- a/modules/Core/Config.psm1 +++ b/modules/Core/Config.psm1 @@ -10,10 +10,18 @@ function Get-Config { $config = $config | Format-EnvironmentVariables | Format-Paths - $config | Where-Object { !($_ -ilike '*#*') -and $_ } > $env:TMP\pwsh.yaml - $config = (ConvertFrom-Yaml -Path $env:TMP\pwsh.yaml) + $hash = Get-Random + $env:TMP = $env:TMP ?? (Join-Path $HOME "tmp") + if (!(Test-Path $env:TMP)) { + New-Item -ItemType Directory -Force -Path $env:TMP + } + + $tempConfigPath = (Join-Path $env:TMP "pwsh.$hash.yaml") - Remove-Item $env:TMP\pwsh.yaml + $config | Where-Object { !($_ -ilike '*#*') -and $_ } | Out-File -Path $tempConfigPath + $config = (ConvertFrom-Yaml -Path $tempConfigPath) + + Remove-Item $tempConfigPath return $config } @@ -35,9 +43,31 @@ function Edit-UserConfig { "$env:EDITOR $env:PWSH_CONFIG" | Invoke-Expression } +function Edit-Configs { + # Paths to potential config files + $configs = @( + (Join-Path $env:APPDATA "alacritty" "alacritty.yml"), + (Get-ChildItem (Join-Path $env:LOCALAPPDATA "Packages" "Microsoft.WindowsTerminal_*" "LocalState" "settings.json")).FullName), + (Join-Path $env:HOME ".gitconfig"), + (Join-Path $env:HOME ".config" "starship.toml") + | Where-Object { Test-Path $_ } + + $config = Read-Option "Select config to edit" $configs + + if ($config) { + "$env:EDITOR $config" | Invoke-Expression + } +} + # Keybinds -Set-PSReadLineKeyHandler -Chord Ctrl+. -Description "Edit pwsh.yaml config with $env:EDITOR" -ScriptBlock { +Set-PSReadLineKeyHandler -Chord "Ctrl+." -Description "Edit pwsh.yaml config with $env:EDITOR" -ScriptBlock { [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() [Microsoft.PowerShell.PSConsoleReadLine]::Insert('Edit-UserConfig') [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() -} \ No newline at end of file +} + +Set-PSReadLineKeyHandler -Chord Ctrl+e -Description "Pick a config file to edit with $env:EDITOR" -ScriptBlock { + [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() + [Microsoft.PowerShell.PSConsoleReadLine]::Insert('Edit-Configs') + [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() +} diff --git a/modules/Core/Environment.psm1 b/modules/Core/Environment.psm1 index bf092b0..1352095 100644 --- a/modules/Core/Environment.psm1 +++ b/modules/Core/Environment.psm1 @@ -23,6 +23,39 @@ function Format-EnvironmentVariables { } } +# Replaces config variables with their given values +function Format-ConfigValues { + [cmdletbinding()] + param( + [parameter( + Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true + )] + [string]$Content, + [parameter( + Mandatory = $true + )] + $Config + ) + process { + $Content | Select-String -Pattern '#\{(.*?)\}' -AllMatches | ForEach-Object { + $_.matches | ForEach-Object { + $propertyNames = $_.groups[1].Value.Split(".") + + $value = $Config + $propertyNames | ForEach-Object { + $value = $value[$_] + } + + $Content = $Content.Replace($_.groups[0], $value) + } + } + + return $Content + } +} + # Ensures paths are correctly formatted function Format-Paths { [cmdletbinding()] diff --git a/modules/Core/Modules.psm1 b/modules/Core/Modules.psm1 new file mode 100644 index 0000000..11f8733 --- /dev/null +++ b/modules/Core/Modules.psm1 @@ -0,0 +1,48 @@ +Import-Module (Join-Path $env:PWSH_REPO "modules" "Core" "Config.psm1") + +<# +.SYNOPSIS +Get PWSH profile modules with status + +.DESCRIPTION +Get PWSH profile modules with status + +.EXAMPLE +Get-ProfileModules -Include Enabled,Disabled + +.NOTES + +#> +function Get-ProfileModules { + [cmdletbinding()] + param ( + [Parameter(Mandatory=$false)] + [string[]]$Include + ) + process { + $config = Get-Config + + return $config.modules.Keys | ForEach-Object { + $module = $null + + if ($Include?.Length -lt 1) { + $module = $_ + } + + if ($config.modules["$($_)"]?.enabled -eq $false -and $Include?.Contains("Disabled")) { + $module = $_ + } + + if ($config.modules["$($_)"]?.enabled -eq $true -and $Include?.Contains("Enabled")) { + $module = $_ + } + + if ($null -ne $module) { + return @{ + Name = $_ + Enabled = $config.modules["$($_)"]?.enabled + } + } + } | Where-Object { !( $_ -eq $null )} + } +} diff --git a/modules/Core/Testers.psm1 b/modules/Core/Testers.psm1 index a5451e4..d2eaa73 100644 --- a/modules/Core/Testers.psm1 +++ b/modules/Core/Testers.psm1 @@ -17,5 +17,5 @@ function Test-Command($command) { } function Test-Module($module) { - return !((Get-Config).modules?."$module"?.disabled ?? $true) -} \ No newline at end of file + return (Get-Config).modules?."$module"?.enabled ?? $false +} diff --git a/modules/FuzzyFinder/FuzzyFinder.psm1 b/modules/FuzzyFinder/FuzzyFinder.psm1 index fa63191..f0095f2 100644 --- a/modules/FuzzyFinder/FuzzyFinder.psm1 +++ b/modules/FuzzyFinder/FuzzyFinder.psm1 @@ -13,7 +13,15 @@ function Invoke-FuzzyFile { # If selection is file, open it if (Test-Path -Path $selection -PathType Leaf) { - Invoke-Item $selection + # If known text file type, open with configured editor + $editor = Get-Editor -FilePath $selection + if ($editor) { + "$($editor.path) $selection" | Invoke-Expression + } + # Otherwise, just open it with default app + else { + Invoke-Item $selection + } } # If selection is a directory, navigate and invoke this function again @@ -21,4 +29,12 @@ function Invoke-FuzzyFile { Set-Location $selection Invoke-FuzzyFile } -} \ No newline at end of file +} + +function Get-Editor($FilePath) { + $extension = (Get-ChildItem (Convert-Path $FilePath)).Extension + + return (Get-Config).editors + | Where-Object { $_.extensions.Contains($extension) } + | Select-Object -First 1 +} diff --git a/modules/Git/Path.psm1 b/modules/Git/Path.psm1 index 7ccaafd..137901d 100644 --- a/modules/Git/Path.psm1 +++ b/modules/Git/Path.psm1 @@ -1,4 +1,4 @@ # Add Git GNU-like utils to PATH on Windows if ($IsWindows) { - $env:Path += ";$env:ProgramFiles\Git\usr\bin" -} \ No newline at end of file + $env:Path += ";$(Join-Path $env:ProgramFiles "Git" "usr" "bin")" +} diff --git a/modules/Lf/Keybindings.psm1 b/modules/Lf/Keybindings.psm1 index 3759e8b..8b13789 100644 --- a/modules/Lf/Keybindings.psm1 +++ b/modules/Lf/Keybindings.psm1 @@ -1,5 +1 @@ -Set-PSReadLineKeyHandler -Chord Ctrl+o -Description "LF: Run lf in current dir, navigate to selection on exit" -ScriptBlock { - [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() - [Microsoft.PowerShell.PSConsoleReadLine]::Insert('Invoke-Lfcd') - [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() -} + diff --git a/modules/Ssh/Ssh.psm1 b/modules/Ssh/Ssh.psm1 index a8050e4..650e1e2 100644 --- a/modules/Ssh/Ssh.psm1 +++ b/modules/Ssh/Ssh.psm1 @@ -1,5 +1,5 @@ $sshConfig = (Get-Config).modules.Ssh -if ($sshConfig.disabled) { +if (!($sshConfig.enabled)) { return } @@ -13,10 +13,24 @@ if ($sshConfig.disabled) { function Set-GitEnvironmentVars { # Set git SSH agent to whatever is set as the ssh agent in the PATH - $env:GIT_SSH=$((Get-Command -Name ssh).Source) + if ($sshConfig.config.binaries -eq "windows_openssh") { + $binaries = "C:\WINDOWS\System32\OpenSSH" + } + + if ($sshConfig.config.binaries -eq "windows_git") { + $binaries = Convert-Path (Join-Path (Get-Command git).Source ".." ".." "usr" "bin") + } + + $env:PWSH_SSH_BINARIES = $binaries + $env:GIT_SSH = (Join-Path $binaries "ssh.exe") } function Start-OpenSshAgent { + if (!($sshConfig.config.binaries -eq "windows_openssh")) { + Write-WarningMessage "Cannot start non built in ssh-agent for now :(" + return + } + if (!(Get-Process | Where-Object { $_.Name -eq 'ssh-agent'})) { $service = Get-Service ssh-agent @@ -47,9 +61,10 @@ if ($IsWindows) { # For each ssh-agent connection, add the specified public key to the agent. if ($sshConfig.config.keys.Length -gt 0) { $keys = $sshConfig.config.keys | ForEach-Object { Get-Item $_ } - $currentlyAddedSshKeys = $(ssh-add -l)?.Split(" ")?[3]?.Replace("(", "").Replace(")", "").ToLower() ?? @() + $current = "$(Join-Path "$env:PWSH_SSH_BINARIES" "ssh-add") -l" | Invoke-Expression + $currentlyAddedSshKeys = $current.Split(" ")?[3]?.Replace("(", "").Replace(")", "").ToLower() ?? @() $keys | Where-Object { !($_.Name.Replace("id_", "") -in $currentlyAddedSshKeys) } | ForEach-Object { - ssh-add $_.FullName + "$(Join-Path "$env:PWSH_SSH_BINARIES" "ssh-add") $($_.FullName)" | Invoke-Expression } } } diff --git a/pwsh.yaml b/pwsh.yaml index 7c9cc7a..6acad48 100644 --- a/pwsh.yaml +++ b/pwsh.yaml @@ -14,11 +14,16 @@ # "config" => The module will be loaded with the given configuration modules: FuzzyFinder: - disabled: false + enabled: false config: Ssh: - disabled: false + enabled: false config: + # Path to ssh binaries + # Options: + # windows_git | windows_openssh + # Default: windows_openssh + binaries: windows_openssh # List of paths to SSH keys to load on shell init # Default: empty # Example: @@ -27,19 +32,19 @@ modules: # - ~/.ssh/id_github keys: Dotnet: - disabled: false + enabled: false config: Git: - disabled: false + enabled: false config: Lf: - disabled: false + enabled: false config: Misc: - disabled: false + enabled: false config: Prompt: - disabled: false + enabled: false config: # The shell prompt to invoke # Options: @@ -71,39 +76,100 @@ modules: # Whether to import folder icons using the Terminal-Icons module # Options: - # true | false + # false | false # Default: false - folderIcons: true + folderIcons: false Vim: - disabled: false + enabled: false config: # Sets vim (or neovim) as the default $env:EDITOR # This will be moved to a generalized option in the future - setDefaultEditor: true + setDefaultEditor: false # Aliases vim so that it points to nvim instead - useNeovim: true + useNeovim: false PasswordState: - disabled: false + enabled: false config: baseUrl: domain: Postgres: - disabled: false - config: + enabled: false Kubectl: - disabled: false + enabled: false config: Helm: - disabled: false - config: + enabled: false Npm: - disabled: false - config: + enabled: false Yarn: - disabled: false + enabled: false + AutoHotkey: + enabled: false config: + # Whether AutoHotkey keybinds should be loaded when signing in + # Requires admin-session to initialize + # Default: false + loadKeybindsOnStartup: false + + # Keybindings for various functionality + # Full key list: https://www.autohotkey.com/docs/KeyList.htm + binds: + # Launch configured terminal + terminal: "LWin & Enter" -# Paths to add to the session + # Reload all AutoHotkey keybinds + reload: "LWin & R" + + # Stop all AutoHotkey keybinds + stop: "LWin & Q" + +# Configure paths paths: -- ${HOME}/tools + # Paths to append to the PATH environment variable + include: + - ${HOME}/tools + # Exact paths remove from the PATH environment variable + exclude: + +# Terminal emulator settings +terminal: + # Active terminal emulator + # Default: wt.exe + path: wt.exe + + # Any arguments to pass to the terminal emulator + # Example: + # args: --fullscreen split-pane + args: + +# Default editors when opening certain files +editors: + - path: nvim + extensions: + - .txt + - .md + - .yml + - .yaml + - .html + - .htm + - .js + - .ts + - .json + - .toml + - .xml + - .config + - .css + - .scss + - .less + - .ps1 + - .psm1 + - .psd1 + - .sh + - .gitmodules + - .gitattributes + - .editorconfig + - .gitconfig + - path: code + extensions: + - .cs \ No newline at end of file diff --git a/pwshrc.ps1 b/pwshrc.ps1 index e601d63..833c724 100644 --- a/pwshrc.ps1 +++ b/pwshrc.ps1 @@ -28,9 +28,8 @@ function Invoke-Core { function Invoke-Modules($config) { # Get disabled module names - $disabledModules = $config.modules.PSObject.Properties ` - | Where-Object { $_.Value.disabled } ` - | Select-Object -ExpandProperty Name + $modules = $config.modules + $disabledModules = $modules.Keys | Where-Object { !$modules[$_].enabled } # Load enabled feature modules Get-ChildItem (Join-Path $env:PWSH_REPO modules) -Directory ` @@ -40,10 +39,11 @@ function Invoke-Modules($config) { } function Invoke-Path($config) { - $path = $env:Path.Split(";") | Where-Object { $_ } | Sort-Object | Get-Unique - $path += $config.paths + $path = $env:PATH.Split(";") | Where-Object { $_ } | Sort-Object | Get-Unique + $path += $config.paths.include + $path = $path | Where-Object { !( $config.paths.exclude.Contains($_)) } - $env:Path = [string]::Join(";", $path) + $env:PATH = [string]::Join(";", $path) } # Load environment variables @@ -65,4 +65,6 @@ Invoke-Modules $config Invoke-Path $config # Start prompt -Invoke-Prompt $config.modules?.Prompt?.config +if ($config.modules?.Prompt?.enabled ?? $false) { + Invoke-Prompt $config.modules?.Prompt?.config +} diff --git a/readme.md b/readme.md index ea592bd..2759f51 100644 --- a/readme.md +++ b/readme.md @@ -49,7 +49,7 @@ You can very quickly open the config-file using `Ctrl+.` in your PowerShell sess ## Modules -The different modules have certain dependencies, and some of them might not be relevant to you. You can disable them by setting the `modules..disabled` property to true in the config. The only module that can't be disabled (unless you change the script) is the Core module, since the other modules depend on some common functionality like writing readable info messages. +The different modules have certain dependencies, and some of them might not be relevant to you. They are all disabled by default (Except `Core`). You can enabled them by setting the `modules..enabled` property to true in the config. ## Keybindings