Skip to content

Instantly share code, notes, and snippets.

@josephb4224
Forked from zadjii-msft/README.md
Created October 13, 2025 21:24
Show Gist options
  • Select an option

  • Save josephb4224/b57dac1a5ac5795bd9e13ac2e9c3a69e to your computer and use it in GitHub Desktop.

Select an option

Save josephb4224/b57dac1a5ac5795bd9e13ac2e9c3a69e to your computer and use it in GitHub Desktop.

Revisions

  1. @zadjii-msft zadjii-msft revised this gist Mar 27, 2023. 2 changed files with 11 additions and 3 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Terminal 1.18 Selfhost Settings

    Collection of settings for our 1.18 bug bash.
    Collection of settings for our 1.18 bug bash. Last updated for 1.18.833


    There's also a collection of files for your shell config as well. I made them all separate, especially the pwsh ones, so people could combine as needed. I know folks have complicated shell prompts already. The one I have there is fairly trivial, but should include all the marks you need to get started. Wrap your own prompt as needed.
    @@ -32,11 +32,13 @@ both rely on the `"experimental.autoMarkPrompts": true,` setting being enabled.
    * microsoft/terminal#14938 -Add Suggestions UI & experimental shell completions support
    * microsoft/terminal#14939 - Add tooltips to the Suggestions Control
    * microsoft/terminal#14943 - Add support for opening the Suggestions UI with recent commands
    * microsoft/terminal#15027 - Add a useCommandline property to the suggestions action
    * Context menu
    * microsoft/terminal#14775
    * microsoft/terminal#15020 - Add buttons for selecting commands, output to context menu
    * Shell integration improvements
    * microsoft/terminal#14807 - Add the ability to select a whole command (or its output)
    * Buffer rewrite
    * microsoft/terminal#14821 -Add an efficient text stream write function
    * microsoft/terminal#14821 - Add an efficient text stream write function


    8 changes: 7 additions & 1 deletion settings.jsonc
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,10 @@
    // Add support for opening the Suggestions UI with recent commands #14943
    // (Also required ANY shell integration)
    {
    "keys": "ctrl+shift+h", "command": { "action": "suggestions", "source": "commandHistory" },
    "keys": "ctrl+shift+h", "command": { "action": "suggestions", "source": "commandHistory", "useCommandline":true },
    },
    {
    "keys": "ctrl+shift+y", "command": { "action": "suggestions", "source": "commandHistory", "useCommandline":false },
    },
    ],

    @@ -38,6 +41,9 @@
    // This isn't expected to work well at all right now, but included for completion's sake
    "compatibility.isolatedMode": true,

    // For shell completions to be enabled.
    "experimental.enableShellCompletionMenu": true,

    "profiles":
    {
    "defaults":
  2. @zadjii-msft zadjii-msft revised this gist Mar 13, 2023. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,3 +16,27 @@ These are snippets for:
    * microsoft/terminal#14807 "Add the ability to select a whole command (or its output)"

    both rely on the `"experimental.autoMarkPrompts": true,` setting being enabled.

    ## PRs

    * Tear out
    * microsoft/terminal#14825
    * microsoft/terminal#14843
    * microsoft/terminal#14851
    * microsoft/terminal#14866
    * microsoft/terminal#14901
    * microsoft/terminal#14935 - Enable tearing out tabs to create new windows
    * Headless mode
    * microsoft/terminal#14944 - Add support for running the Terminal without _any_ windows
    * Suggestions UI
    * microsoft/terminal#14938 -Add Suggestions UI & experimental shell completions support
    * microsoft/terminal#14939 - Add tooltips to the Suggestions Control
    * microsoft/terminal#14943 - Add support for opening the Suggestions UI with recent commands
    * Context menu
    * microsoft/terminal#14775
    * Shell integration improvements
    * microsoft/terminal#14807 - Add the ability to select a whole command (or its output)
    * Buffer rewrite
    * microsoft/terminal#14821 -Add an efficient text stream write function


  3. @zadjii-msft zadjii-msft revised this gist Mar 13, 2023. 2 changed files with 2 additions and 16 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Terminal 1.18 Selfhost Settings

    Collection of settings for our 1.18 bug bash.


    16 changes: 0 additions & 16 deletions Terminal 1.18 Selfhost Settings.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +0,0 @@
    Collection of settings for our 1.18 bug bash.


    There's also a collection of files for your shell config as well. I made them all separate, especially the pwsh ones, so people could combine as needed. I know folks have complicated shell prompts already. The one I have there is fairly trivial, but should include all the marks you need to get started. Wrap your own prompt as needed.

    ### Shell-completion integration

    Make sure that the key in `Set-MappedKeyHandlers` matches the contents of the `sendInput` command bound in the `actions`. In this sample, the Terminal internally passes <kbd>F12</kbd><kbd>b</kbd> to pwsh to drive the menu.

    ### Shell integration prompts

    These are snippets for:
    * microsoft/terminal#14943 "Add support for opening the Suggestions UI with recent commands"
    * microsoft/terminal#14807 "Add the ability to select a whole command (or its output)"

    both rely on the `"experimental.autoMarkPrompts": true,` setting being enabled.
  4. @zadjii-msft zadjii-msft revised this gist Mar 13, 2023. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    Collection of settings for our 1.18 bug bash.


    There's also a collection of files for your shell config as well. I made them all separate, especially the pwsh ones, so people could combine as needed. I know folks have complicated shell prompts already. The one I have there is fairly trivial, but should include all the marks you need to get started. Wrap your own prompt as needed.

    ### Shell-completion integration

    Make sure that the key in `Set-MappedKeyHandlers` matches the contents of the `sendInput` command bound in the `actions`. In this sample, the Terminal internally passes <kbd>F12</kbd><kbd>b</kbd> to pwsh to drive the menu.

    ### Shell integration prompts

    These are snippets for:
    * microsoft/terminal#14943 "Add support for opening the Suggestions UI with recent commands"
    * microsoft/terminal#14807 "Add the ability to select a whole command (or its output)"

    both rely on the `"experimental.autoMarkPrompts": true,` setting being enabled.
  5. @zadjii-msft zadjii-msft renamed this gist Mar 13, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @zadjii-msft zadjii-msft renamed this gist Mar 13, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @zadjii-msft zadjii-msft created this gist Mar 13, 2023.
    16 changes: 16 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    Collection of settings for our 1.18 bug bash.


    There's also a collection of files for your shell config as well. I made them all separate, especially the pwsh ones, so people could combine as needed. I know folks have complicated shell prompts already. The one I have there is fairly trivial, but should include all the marks you need to get started. Wrap your own prompt as needed.

    ### Shell-completion integration

    Make sure that the key in `Set-MappedKeyHandlers` matches the contents of the `sendInput` command bound in the `actions`. In this sample, the Terminal internally passes <kbd>F12</kbd><kbd>b</kbd> to pwsh to drive the menu.

    ### Shell integration prompts

    These are snippets for:
    * microsoft/terminal#14943 "Add support for opening the Suggestions UI with recent commands"
    * microsoft/terminal#14807 "Add the ability to select a whole command (or its output)"

    both rely on the `"experimental.autoMarkPrompts": true,` setting being enabled.
    57 changes: 57 additions & 0 deletions settings.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@

    {
    "actions":
    [
    // Add the ability to select a whole command (or its output) #14807
    { "keys": "ctrl+shift+w", "command": { "action": "selectOutput", "direction": "prev" }, },
    { "keys": "ctrl+shift+s", "command": { "action": "selectOutput", "direction": "next" }, },

    { "keys": "ctrl+alt+shift+w", "command": { "action": "selectCommand", "direction": "prev" }, },
    { "keys": "ctrl+alt+shift+s", "command": { "action": "selectCommand", "direction": "next" }, },

    // Enable tearing out tabs to create new windows #14935
    { "keys": "f1", "command": { "action": "moveTab", "window": "1" }, },
    { "keys": "f2", "command": { "action": "moveTab", "window": "2" }, },
    { "keys": "f3", "command": { "action": "movePane", "window": "1" }, },
    { "keys": "f4", "command": { "action": "movePane", "window": "2" }, },

    // Add Suggestions UI & experimental shell completions support #14938
    // (Also required pwsh shell integration)
    {
    "command": { "action": "sendInput", "input": "\u001b[24~b" },
    "keys": "ctrl+space",
    "name": "magic",
    "description": "not for real use - helper for autocomplete."
    },

    // Add support for opening the Suggestions UI with recent commands #14943
    // (Also required ANY shell integration)
    {
    "keys": "ctrl+shift+h", "command": { "action": "suggestions", "source": "commandHistory" },
    },
    ],

    // Add support for running the Terminal without _any_ windows #14944
    // (you probably also want at least `quakeMode` or a `globalSummon`)
    "compatibility.allowHeadless": true,

    // This isn't expected to work well at all right now, but included for completion's sake
    "compatibility.isolatedMode": true,

    "profiles":
    {
    "defaults":
    {
    // Marks in general
    "experimental.showMarksOnScrollbar": true,

    // NEEDED for both pwsh and CMD shell integration
    "experimental.autoMarkPrompts": true,

    // Add support for a right-click context menu #14775
    "experimental.rightClickContextMenu": true,

    "useAtlasEngine": true
    },
    }
    }
    79 changes: 79 additions & 0 deletions shell-completions.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@

    # Send tab completion to terminal
    function Send-Completions {
    # Get current command line
    $commandLine = ""
    # TODO: Take cursor into account
    $cursor = 0
    # TODO: Since fuzzy matching exists, should completions be provided only for character after the
    # last space and then filter on the client side? That would let you trigger ctrl+space
    # anywhere on a word and have full completions available
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursor)
    # Get and send completions
    $completionPrefix = $commandLine
    if ($completionPrefix.Length -eq 0) {
    # TODO: Send bell instead?
    $result = "`e]633;Completions`a"
    Write-Host -NoNewLine $result
    return
    }
    $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $completionPrefix.Length
    if ($null -eq $completions.CompletionMatches) {
    $result = "`e]633;Completions`a"
    } else {
    $result = "`e]633;Completions;$($completions.ReplacementIndex);$($completions.ReplacementLength);"
    $serialized = $completions.CompletionMatches | ConvertTo-Json -Compress
    $result += $serialized
    $result += "`a"
    }
    Write-Host -NoNewLine $result
    }
    function Send-Completions2 {
    $commandLine = ""
    $cursorIndex = 0
    # TODO: Since fuzzy matching exists, should completions be provided only for character after the
    # last space and then filter on the client side? That would let you trigger ctrl+space
    # anywhere on a word and have full completions available
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
    $completionPrefix = $commandLine

    # Get completions
    $result = "`e]633;Completions"
    if ($completionPrefix.Length -gt 0) {
    # Get and send completions
    $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
    if ($null -ne $completions.CompletionMatches) {
    $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
    $result += $completions.CompletionMatches | ConvertTo-Json -Compress
    }
    }
    $result += "`a"

    Write-Host -NoNewLine $result
    }

    function Set-MappedKeyHandlers {

    # # Conditionally enable suggestions
    # if ($env:VSCODE_SUGGEST -eq '1') {
    # Remove-Item Env:VSCODE_SUGGEST

    # VS Code send completions request (may override Ctrl+Spacebar)
    Set-PSReadLineKeyHandler -Chord 'F12,b' -ScriptBlock {
    Send-Completions2
    }

    # MIKE TODO! This is awesome but doesn't work now, because we backspace and
    # retype the command, re-triggering the '-' to get sent. Dumb.

    # # Suggest trigger characters
    # Set-PSReadLineKeyHandler -Chord "-" -ScriptBlock {
    # [Microsoft.PowerShell.PSConsoleReadLine]::Insert("-")
    # Send-Completions2
    # }
    # }
    }
    # Register key handlers if PSReadLine is available
    if (Get-Module -Name PSReadLine) {
    Set-MappedKeyHandlers
    }
    3 changes: 3 additions & 0 deletions shell-integration-prompt.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    @echo off

    PROMPT $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\$e[107;30m$T]$e[97;46m$G$P$e[36;49m$G$e[0m$_$e[0m$e[94m%username%$e[0m@$e[32m%computername%$e[0m$G$e]133;B$e
    42 changes: 42 additions & 0 deletions shell-integration-prompt.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@

    $Global:__LastHistoryId = -1

    function Global:__Terminal-Get-LastExitCode {
    if ($? -eq $True) {
    return 0
    }
    # TODO: Should we just return a string instead?
    # return -1
    if ("$LastExitCode" -ne "") { return $LastExitCode }
    return -1
    }

    function prompt {
    $gle = $(__Terminal-Get-LastExitCode);
    $LastHistoryEntry = $(Get-History -Count 1)
    # Skip finishing the command if the first command has not yet started
    if ($Global:__LastHistoryId -ne -1) {
    if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
    # Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
    $out += "`e]133;D`a"
    } else {
    # Command finished exit code
    # OSC 133 ; D [; <ExitCode>] ST
    $out += "`e]133;D;$gle`a"
    }
    }


    $loc = $($executionContext.SessionState.Path.CurrentLocation);
    # IMPORTANT: Make sure there's a printable charater _last_ in the prompt.
    # Otherwise, PSReadline is gonna use the terminating `\` here and colorize
    # that if it detects a syntax error
    $out += "`e]133;A$([char]07)"; # Prompt started
    $out += "`e]9;9;`"$loc`"$([char]07)"; # CWD
    $out += "PWSH $loc$('>' * ($nestedPromptLevel + 1)) "; # { your prompt here }
    $out += "`e]133;B$([char]07)"; # Prompt ended == Command started

    $Global:__LastHistoryId = $LastHistoryEntry.Id

    return $out
    }