Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for managing PSReadline settings from PSProfile #10

Open
scrthq opened this issue Aug 27, 2019 · 0 comments
Open

Add support for managing PSReadline settings from PSProfile #10

scrthq opened this issue Aug 27, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request hacktoberfest Hacktoberfest issues to address
Milestone

Comments

@scrthq
Copy link
Member

scrthq commented Aug 27, 2019

Goal for this would be to enable storage of PSReadline Options, KeyHandlers, etc in your PSProfile configuration. These would ideally be ran as the appropriate command during PSProfile load, eliminating the need for a separate PSReadline settings script.

Initial approach: The commands below would be turned into the following hashtable property on $PSProfile.Settings:

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Alt+j -BriefDescription ShowDirectoryMarks -LongDescription "Show the currently marked directories" -ScriptBlock {
    param($key, $arg)
    $global:PSReadLineMarks.GetEnumerator() | ForEach-Object {
        [PSCustomObject]@{Key = $_.Key; Dir = $_.Value }
    } | Format-Table -AutoSize | Out-Host
    [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}
$PSProfile.Settings.PSReadline = @{
    Options = @{
        HistorySearchCursorMovesToEnd = $true
    }
    KeyHandlers = @(
        @{
            Chord = 'Tab'
            Function = 'MenuComplete'
        }
        @{
            Key = 'UpArrow'
            Function = 'HistorySearchBackward'
        }
        @{
            Key = 'DownArrow'
            Function = 'HistorySearchForward'
        }
        @{
            Key = 'Alt+j'
            BriefDescription = 'ShowDirectoryMarks'
            LongDescription = 'Show the currently marked directories'
            ScriptBlock = 'param($key, $arg)
            $global:PSReadLineMarks.GetEnumerator() | ForEach-Object {
                [PSCustomObject]@{Key = $_.Key; Dir = $_.Value }
            } | Format-Table -AutoSize | Out-Host
            [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()'
        }
    )
}

During PSProfile import, the hashtable in $PSProfile.Settings.PSReadline would be parsed, converted to the original commands, then executed so they're available in the current session as they would normally be from an ExternalScript.

@scrthq scrthq added the enhancement New feature or request label Aug 27, 2019
@scrthq scrthq self-assigned this Aug 27, 2019
@scrthq scrthq added this to the v0.2.0 Release milestone Aug 28, 2019
@scrthq scrthq changed the title Request: Add support for managing PSReadline settings from PSProfile Add support for managing PSReadline settings from PSProfile Aug 28, 2019
@scrthq scrthq added the hacktoberfest Hacktoberfest issues to address label Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest Hacktoberfest issues to address
Projects
None yet
Development

No branches or pull requests

1 participant