#2226: show IDEasy project, workspace and repository in the git-bash window title - #2227
Open
maybeec wants to merge 2 commits into
Open
#2226: show IDEasy project, workspace and repository in the git-bash window title#2227maybeec wants to merge 2 commits into
maybeec wants to merge 2 commits into
Conversation
…w title Git Bash rewrites the window title on every prompt via an escape sequence in PS1, so terminal tabs and windows cannot be told apart. Remove that sequence and write "ideasy>«project»>«workspace»" instead, degrading to "ideasy>«project»" outside a workspace and "ideasy" outside any project. The workspace is derived from PWD because the WORKSPACE variable always defaults to "main", even outside of any workspace or IDEasy project. Limited to git-bash: on macOS and Linux the prompt is configured by the user or the distribution and must not be touched, and zsh has no PROMPT_COMMAND.
…egment detection The title now also shows the repository below the workspace, e.g. "ideasy>devonfw>main>IDEasy". Like "icd -r" hidden folders are not treated as repositories and for a nested repository the top-level folder is shown. Extract _ide_path_segment as the single place that determines a path segment below a base directory and use it for the workspace and repository of the title as well as for the project inference of _icd_project_dir. The result is passed via a variable instead of being echoed to avoid a subshell per prompt.
Collaborator
Coverage Report for CI Build 30397974379Coverage increased (+0.02%) to 72.614%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #2226
Git Bash bakes a window title escape sequence into
PS1(see/etc/profile.d/git-prompt.sh), so the title is rewritten toMINGW64:«current-directory»on every prompt and cannot be set permanently. All git-bash tabs and windows therefore look alike in the taskbar and inAlt+Tab.This PR removes that sequence and writes an IDEasy specific title instead, so you can see at a glance which project and workspace a shell is initialized for.
Implemented changes:
Added
_ide_titletocli/src/main/package/functions, which writes the terminal title and degrades gracefully depending on the available context:ideasy>devonfw>main>IDEasyideasy>devonfw>mainideasy>devonfwideasyThe repository is the counterpart of
icd -r, i.e. the first folder below the workspace. Consistent with the implicit-rresolution, hidden folders (e.g..vscode) are not treated as repositories, and for a nested repository such asbackend/coreonly the top-level folder is shown to keep the title short.Workspace and repository are derived from
PWDand not from theWORKSPACEvariable, becauseideasy env --bashalways emitsWORKSPACE="main"as a default - even when the current directory is completely outsideIDE_ROOT. As a side effect the title also follows a plaincd, not onlyide/icd.Extracted
_ide_path_segmentas the single place that determines a path segment below a base directory. It is used for the workspace and the repository of the title as well as for the project inference in_icd_project_dir, which previously duplicated this logic. Its result is passed via a variable rather than echoed, so that no subshell is forked -_ide_titleruns on every prompt and process creation is expensive on Windows.The git-bash title sequence is removed from
PS1and_ide_titleis hooked intoPROMPT_COMMAND. Both steps are idempotent, so sourcing the functions file again (e.g. viasource ~/.bashrc) does not duplicate the hook or stripPS1twice.The whole block is guarded by the existing
_ide_is_msyshelper plus aBASH_VERSIONcheck, so macOS, Linux and Cygwin are not touched at all - their prompt is configured by the user or the distribution. TheBASH_VERSIONcheck is needed because the functions file is also sourced from zsh, which has noPROMPT_COMMAND(it usesprecmd).An existing
PROMPT_COMMANDis preserved, including the array form supported since bash 5.1. The IDEasy hook is prepended so a user's own hook runs afterwards and can still override the title.The
PS1rewrite only triggers when the title sequence is at the very beginning of the prompt, so a custom prompt (e.g. via the~/.config/git/git-prompt.shhook honored by git-bash) is left untouched.Added 18 tests to
cli/src/test/functions-test.shand documented the behavior indocumentation/advanced-tooling-windows.adoc.Testing instructions
Automated:
bash cli/src/test/functions-test.sh- this is the same entry point CI uses (.github/workflows/build-pr.yml). All tests must pass.Note that the zsh cases are skipped when zsh is not on the
PATH(e.g. on Windows). They were verified onubuntu:24.04with zsh 5.9, where the suite reports 43 of 43 passed, includingzsh -nparsing of the functions file.bash cli/src/test/icd-completion-test.sh-_icd_project_dirwas refactored, so the icd completion tests must still pass.Manual (Windows, git-bash):
source ~/.bashrc.icd -rinto a repository - the window/tab title showsideasy>«your-project»>«workspace»>«repository».cd ..up into the workspace - the title showsideasy>«your-project»>«workspace».cdinto a hidden folder of the workspace (e.g..vscode) - the title still showsideasy>«your-project»>«workspace».icdinto the project root (outsideworkspaces) - the title showsideasy>«your-project».cd ~and runide- the title showsideasy.$MSYSTEM, the working directory and the git branch from__git_ps1are all still there.icd -p«Tab»,icd -w«Tab»andicd -r«Tab»still complete as before.Manual (macOS/Linux, regression):
source ~/.bashrc(or~/.zshrc).Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internal