Skip to content

Add Windows Terminal shell integration installer#449

Open
Copilot wants to merge 10 commits intodevelopmentfrom
copilot/add-shell-integration-installer
Open

Add Windows Terminal shell integration installer#449
Copilot wants to merge 10 commits intodevelopmentfrom
copilot/add-shell-integration-installer

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

  • Create installer script pengwin-setup.d/shell-integration.sh for Windows Terminal shell integration
  • Add menu entry in pengwin-setup.d/shells.sh for the new installer
  • Create uninstaller script pengwin-setup.d/uninstall/shell-integration.sh
  • Add uninstall menu entry in pengwin-setup.d/uninstall.sh
  • Update bash completions in completions/pengwin-setup
  • Create unit test tests/shell-integration.sh
  • Add test to tests/run_tests.sh
  • Add missing PS0 for command executed mark (133;C)
  • Move shell integration script to /usr/local/share/pengwin/wt-shell-integration.sh
  • Use sudo_rem_file helper function in uninstaller
  • Add enable_should_restart to signal distro restart after installation
  • Fix PS0 command substitution syntax
  • Fix: Preserve command-start OSC marker (133;B) in prompt updates
Original prompt

windows terminal shell integration need a modification in the prompt. but in debian as the prompt is defined in .bashrc it is not possible to change it in /etc/profile.d the only way is to add changes in .bashrc. The original script is the following: https://github.com/WhitewaterFoundry/pengwin-enterprise-rootfs-builds/blob/main/linux_files/bash-prompt-wsl.sh

create a new installer in pengwin-setup in the shells section to install the windows terminal shell integration: for reference: https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration

the installer will add a modification to .bashrc with marks to be able to do an uninstall if the user decides to


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 26, 2025 11:44
Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Windows Terminal shell integration installer for Pengwin setup Add Windows Terminal shell integration installer Nov 26, 2025
Copilot AI requested a review from crramirez November 26, 2025 11:47
@crramirez
Copy link
Collaborator

@copilot looks like PS0 was missed, __wt_mark_command_executed is not used. by the way where did you took anything from the oriiginal script I sent?

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot looks like PS0 was missed, __wt_mark_command_executed is not used. by the way where did you took anything from the oriiginal script I sent?

Fixed in d91a9f8. The shell integration now properly uses PS0 for the command executed mark (133;C) based on the original script at https://github.com/WhitewaterFoundry/pengwin-enterprise-rootfs-builds/blob/main/linux_files/bash-prompt-wsl.sh. The implementation now directly sets PS0 and PS1 with the OSC escape sequences rather than using wrapper functions.

@crramirez
Copy link
Collaborator

@copilot well i was just asking, i prefer your original implementation is cleaner and look more professional just add the PS0 that you missed

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot well i was just asking, i prefer your original implementation is cleaner and look more professional just add the PS0 that you missed

Restored the original cleaner implementation with wrapper functions and added the missing PS0 in f562e00. Now __wt_mark_command_executed is properly used via PS0='\[\$(__wt_mark_command_executed)\]'.

@crramirez
Copy link
Collaborator

@copilot ok now, i think that this will clutter the .bashrc, is any way to put everything in a file to be included?

…bashrc clutter

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot ok now, i think that this will clutter the .bashrc, is any way to put everything in a file to be included?

Done in c74cfcd. The shell integration code is now in a separate file /etc/profile.d/wt-shell-integration.sh. The .bashrc now only contains a minimal 3-line source block:

### PENGWIN WINDOWS TERMINAL SHELL INTEGRATION
# Source Windows Terminal shell integration (needs to run after PS1 is set)
[[ -f "/etc/profile.d/wt-shell-integration.sh" ]] && source "/etc/profile.d/wt-shell-integration.sh"
### PENGWIN WINDOWS TERMINAL SHELL INTEGRATION

@crramirez
Copy link
Collaborator

@copilot ok but if you put it in /etc/profile.d/ it will be executed also before .bashrc creating (i think) a mess. better if you put it in /usr/local/bin or /usr/local/share

…ofile.d execution order issues

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot ok but if you put it in /etc/profile.d/ it will be executed also before .bashrc creating (i think) a mess. better if you put it in /usr/local/bin or /usr/local/share

Done in 71a9a7b. Moved the script to /usr/local/share/pengwin/wt-shell-integration.sh which is only sourced explicitly from .bashrc after PS1 is set, avoiding the profile.d execution order issues.

fi

# Remove the shell integration script
echo "Removing ${SHELL_INTEGRATION_SCRIPT}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use sudo_rem_file for that also save it into the instructions for the repo or your memory because i had to tell it more than once, priorize using the helper functions from uninstall-common.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c5e2e15. Now using sudo_rem_file from uninstall-common.sh.


# Install shell integration script
# Based on: https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration
# and https://github.com/WhitewaterFoundry/pengwin-enterprise-rootfs-builds/blob/main/linux_files/bash-prompt-wsl.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# and https://github.com/WhitewaterFoundry/pengwin-enterprise-rootfs-builds/blob/main/linux_files/bash-prompt-wsl.sh


echo "Windows Terminal shell integration installed successfully."
message --title "Shell Integration Installed" --msgbox "Windows Terminal shell integration has been installed.\n\nScript location: ${SHELL_INTEGRATION_SCRIPT}\nSource added to: ${bashrc}\n\nPlease close and re-open your terminal or run 'source ~/.bashrc' to apply the changes.\n\nThis provides:\n- Command marks for scroll-to-command\n- Current working directory tracking\n- Command exit status reporting" 16 80
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot put the flag to restart the distro. this is another thing that i need constantly repeating. if the installer needs a reload of the environment like source ~/.bashrc, use the function in commons.sh to signal a distro restart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c5e2e15. Added enable_should_restart call after successful installation.

… comment

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
@crramirez crramirez marked this pull request as ready for review November 26, 2025 13:53
Copilot AI review requested due to automatic review settings November 26, 2025 13:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new installer for Windows Terminal shell integration to pengwin-setup, enabling OSC sequence support for features like scroll-to-command, working directory tracking, and command status reporting in Windows Terminal and WezTerm.

Key Changes

  • Adds a shell integration installer that creates a script in /usr/local/share/pengwin/ and modifies ~/.bashrc to source it, with marker-based tracking for clean uninstallation
  • Implements Windows Terminal's OSC 133 sequences (A, B, C, D) for command lifecycle tracking, plus OSC 9;9 for current working directory
  • Adds comprehensive test coverage for both installation and uninstallation scenarios

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pengwin-setup.d/shell-integration.sh Main installer that creates shell integration script and modifies .bashrc with markers
pengwin-setup.d/uninstall/shell-integration.sh Uninstaller that removes .bashrc modifications and cleans up script file
pengwin-setup.d/shells.sh Adds SHELLINT menu entry and handler in the shells menu
pengwin-setup.d/uninstall.sh Adds SHELLINT to uninstall menu in correct alphabetical position
completions/pengwin-setup Adds SHELLINT to bash completion for both SHELLS and UNINSTALL contexts
tests/shell-integration.sh Unit tests verifying installation, script content, and uninstallation
tests/run_tests.sh Integrates new test into CI test suites

PROMPT_COMMAND="__wt_update_prompt${PROMPT_COMMAND:+;}${PROMPT_COMMAND}"
PS1="\[\$(__wt_mark_command_start)\]${PS1}"
# PS0 is executed after reading a command but before executing it
PS0='\[\$(__wt_mark_command_executed)\]'
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backslash before the dollar sign in PS0 will prevent command substitution from working correctly. When bash expands PS0, \$ is interpreted as an escape sequence meaning "$ if UID != 0, otherwise #", not as the start of command substitution $(...).

This means PS0 will display the literal text $(__wt_mark_command_executed) instead of executing the function.

The fix is to remove the backslash before the dollar sign:

PS0='\[$(__wt_mark_command_executed)\]'

For reference, line 77 correctly uses \$ within double quotes to prevent expansion during assignment, which results in PS1 containing $(...) without the backslash. But line 79 uses single quotes where everything is already literal, so the \$ results in PS0 containing the backslash, which then gets interpreted as an escape sequence during prompt expansion.

Suggested change
PS0='\[\$(__wt_mark_command_executed)\]'
PS0='\[$(__wt_mark_command_executed)\]'

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 66 to 70
local last_exit_code="$?"
__wt_mark_command_finished "${last_exit_code}"
__wt_set_cwd
__wt_mark_prompt_start
PS1="${__wt_original_ps1}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve command-start OSC in prompt updates

The integration script resets PS1 to __wt_original_ps1 on every prompt (in __wt_update_prompt), but the PS1 update that prepends __wt_mark_command_start is only applied once during initialization below. Because PROMPT_COMMAND runs before the first prompt, the reset strips the 133;B command-start marker before any prompt is shown, so Windows Terminal never receives the command-start OSC sequence and features like scroll-to-command aren’t activated even after installation.

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot check this out

…otes

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
@crramirez
Copy link
Collaborator

@copilot codex put the following feedback:

P1 Badge Preserve command-start OSC in prompt updates

The integration script resets PS1 to __wt_original_ps1 on every prompt (in __wt_update_prompt), but the PS1 update that prepends __wt_mark_command_start is only applied once during initialization below. Because PROMPT_COMMAND runs before the first prompt, the reset strips the 133;B command-start marker before any prompt is shown, so Windows Terminal never receives the command-start OSC sequence and features like scroll-to-command aren’t activated even after installation.

Can you check?

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 26, 2025

@copilot codex put the following feedback:

P1 Badge Preserve command-start OSC in prompt updates
...

The codex feedback is correct. Fixed in e5e903f. The __wt_update_prompt function now preserves the command-start marker by setting PS1="\[\$(__wt_mark_command_start)\]${__wt_original_ps1}" instead of just PS1="${__wt_original_ps1}".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants