Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.ps1 text eol=crlf
*.md text eol=lf
*.sh text eol=lf
/vendor/cmder_exinit text eol=lf
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

## Unreleased

### Adds

- Offer to configure Cmder startup for external Git Bash installations without replacing existing hooks. Answering No skips one launch; answering `never` disables future offers for that installation.

### Changes

- Bundled and external Cmder hooks load the same `vendor\cmder.sh` startup script.
- Enable Bash and Mintty startup debug messages with a positive `debug_output` value, matching the command-script debug setting.
- Use a shared shell console helper for Bash startup debug messages, including the external Git Bash hook.
- Store external Git Bash setup opt-outs by computer name and Git path in the portable `config/user_cmder_state.txt` file.
- Automatically migrate an existing external `cmder_exinit.sh` hook to `zz-cmder_exinit.sh`, preserving the old hook in a dated `.bak` file without an installation-confirmation prompt. UAC approval may still be required if the Git profile directory is not writable.

### Fixes

- Remove the legacy bundled `cmder.sh` hook at shell startup only when `zz-cmder.sh` exists, rather than rewriting it during package builds.
- Make the Git Bash/MinTTY launchers use the same bundled and external Git discovery, PATH setup, MSYSTEM selection, and Cmder startup hook as the running `bash.exe`.
- Fix no Git in path when launching `Cmder - Bash` from the unreleased `main` branch.
- Preserve Git Bash's normal startup PATH, including native tools and entries with spaces, with Cmder's bin directories at the front.
- Support Git for Windows' `ucrt64` directory in fresh and cached command startup, PowerShell Git discovery, and Git Bash, while retaining older `mingw64` and `mingw32` layouts. This prepares the Git security update in [#3093](https://github.com/cmderdev/cmder/pull/3093).
- Show vendor build badges for the requested release ref, with a verified check-runs fallback when the README badge is unavailable. Fix missing README fallback and Azure build-link matching from [#3103](https://github.com/cmderdev/cmder/pull/3103), and link truncated release notes to their full text.

Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Single user portable configuration is possible using the Cmder specific shell co

**Note:** Bash and Mintty sessions will also source the `$HOME/.bashrc` file if it exists after it sources `$CMDER_ROOT/config/user_profile.sh`.

To see Bash or Mintty startup debug messages, set `debug_output` to a positive integer in the environment before launching the shell (for example, `set debug_output=1` in Command Prompt). The bundled and external Git Bash hooks use the same setting.

You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in the `%CMDER_ROOT%\config\profile.d` folder to add startup config to Cmder.

| Shell | Cmder `Profile.d` Scripts |
Expand Down Expand Up @@ -245,7 +247,7 @@ Bash shells support simple and complex aliases with optional parameters natively

To make an alias and/or any other profile settings permanent add it to one of the following:

Note: These are loaded in this order by `$CMDER_ROOT/vendor/git-for-windows/etc/profile.d/cmder.sh`. Anything stored in `$CMDER_ROOT` will be a portable setting and will follow Cmder to another machine.
Bundled Git Bash sets up its normal PATH first, then `zz-cmder.sh` in `etc/profile.d` adds Cmder's bin directories at the front and loads its portable settings. The Git Bash launcher removes the older `cmder.sh` hook only if `zz-cmder.sh` is present. Bash handles personal login files normally; source `~/.bashrc` from your login profile if needed.

* `$CMDER_ROOT/config/profile.d/*.sh`
* `$CMDER_ROOT/config/user_profile.sh`
Expand Down Expand Up @@ -287,19 +289,29 @@ You may run bash (the default shell used on Linux, macOS and GNU/Hurd) externall

**Recommended Optional Steps:**

When Cmder uses external Git for Windows, the Git Bash launcher offers to install `/etc/profile.d/zz-cmder_exinit.sh` if no Cmder hook exists. If the older `cmder_exinit.sh` hook is present, Cmder automatically renames it to a dated `.bak` file and installs the new hook without prompting. The backup is not a `.sh` file, so Git Bash will not source it. This hook and the bundled `zz-cmder.sh` load [`vendor/cmder.sh`](vendor/cmder.sh), included in full and no-Git packages. For bundled Git, the launcher removes the older `cmder.sh` hook at startup only when `zz-cmder.sh` is present.

- At the prompt:
- `Y` Integrates `Cmder` into the external `Git` Install.
- `N` Skips integration this launch.
- `never` Suppresses future offers for that Git path on this computer.
- Opt-outs are stored as tab-separated computer name and Git path pairs under `[external-git-bash-opt-outs]` in `config/user_cmder_state.txt`.
- Remove an entry to allow the offer again.
- Repeated section headers let Cmder append entries without rewriting existing state.

Copy the `vendor/cmder_exinit` file to the Cygwin/Babun, MSys2, or Git for Windows SDK environments `/etc/profile.d/` folder to use portable settings in the `$CMDER_ROOT/config` folder.

Note: MinGW could work if the init scripts include `profile.d` but this has not been tested.

The destination file extension depends on the shell you use in that environment. For example:

* bash - Copy to `/etc/profile.d/cmder_exinit.sh`
* zsh - Copy to `/etc/profile.d/cmder_exinit.zsh`
* bash - Copy to `/etc/profile.d/zz-cmder_exinit.sh`
* zsh - Copy to `/etc/profile.d/zz-cmder_exinit.zsh`

Uncomment and edit the line below in the script to use Cmder config even when launched from outside Cmder.

```
# CMDER_ROOT=${USERPROFILE}/cmder # This is not required if launched from Cmder.
# CMDER_ROOT="${USERPROFILE}/cmder" # Not required when launched from Cmder.
```

### Customizing user sessions using `init.cmd` custom arguments.
Expand Down
1 change: 0 additions & 1 deletion packignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ icons\icon_256*.png
Cmder.bat
vendor\tmp
appveyor.yml
vendor\cmder.sh
vendor\git-prompt.sh
config\user-*
config\user_*
Expand Down
14 changes: 11 additions & 3 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,18 @@ if (-not $noVendor) {
Copy-Item $WinTermSettingsJsonSave $WinTermSettingsJson
}

# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
# Run after Git Bash's standard PATH hooks, including env.sh.
if ( (Test-Path $($saveTo + "git-for-windows/etc/profile.d") ) ) {
Write-Verbose "Adding cmder.sh /etc/profile.d"
Copy-Item $($saveTo + "cmder.sh") $($saveTo + "git-for-windows/etc/profile.d/cmder.sh")
$bashProfileDir = Join-Path $saveTo 'git-for-windows\etc\profile.d'
Write-Verbose "Installing zz-cmder.sh in $bashProfileDir"
$bundledRootFallback = @'
if [ -z "${CMDER_ROOT:-}" ] && [ -z "${cmder_root:-}" ] && [ -z "${ConEmuDir:-}" ]; then
CMDER_ROOT=$(cd "$(cygpath -am /)/../.." && pwd) || return 1
fi
'@
$shim = [IO.File]::ReadAllText((Join-Path $cmder_root 'vendor\cmder_exinit'))
$hook = "$bundledRootFallback`n`n$shim" -replace "`r`n", "`n"
[IO.File]::WriteAllText((Join-Path $bashProfileDir 'zz-cmder.sh'), $hook)
}

# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty
Expand Down
6 changes: 6 additions & 0 deletions scripts/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ $cmder_root = Resolve-Path $cmderRoot
$ErrorActionPreference = "Stop"
Ensure-Executable "7z"

foreach ($file in @('vendor\cmder.sh', 'vendor\cmder_exinit', 'vendor\lib\lib_console.sh', 'vendor\setup_external_git_bash.ps1')) {
if (-not (Test-Path -LiteralPath (Join-Path $cmder_root $file) -PathType Leaf)) {
throw "Cannot package Cmder: missing required Bash startup file '$file'."
}
}

function Get-ArchiveFlags {
param(
[Parameter(Mandatory = $true)]
Expand Down
51 changes: 51 additions & 0 deletions scripts/test-build-helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,57 @@ try {
}
$cases++

$packageSource = Join-Path $testRoot 'package source'
$packageVendor = Join-Path $packageSource 'vendor'
$profileDir = Join-Path $packageVendor 'git-for-windows\etc\profile.d'
$null = New-Item -ItemType Directory -Path $profileDir
$legacyBundledHook = Join-Path $profileDir 'cmder.sh'
[IO.File]::WriteAllText($legacyBundledHook, 'legacy bundled hook')
$repo = Split-Path $PSScriptRoot -Parent
$startupFiles = @('cmder.sh', 'cmder_exinit', 'lib\lib_console.sh', 'setup_external_git_bash.ps1')
foreach ($file in $startupFiles) {
$destination = Join-Path $packageVendor $file
$null = New-Item -ItemType Directory -Path (Split-Path $destination -Parent) -Force
Copy-Item -LiteralPath (Join-Path $repo "vendor\$file") -Destination $destination
}
$packageConfig = Join-Path $packageSource 'config'
$null = New-Item -ItemType Directory -Path $packageConfig -Force
[IO.File]::WriteAllText((Join-Path $packageConfig 'user_cmder_state.txt'), 'private Git path')
Copy-Item -LiteralPath (Join-Path $repo 'packignore') -Destination $packageSource
$emptyManifest = Join-Path $testRoot 'empty-sources.json'
Set-Content -LiteralPath $emptyManifest -Value '[]' -Encoding ascii
Set-Content -LiteralPath (Join-Path $profileDir 'git-prompt.sh.bak') -Value '' -Encoding ascii
& (Join-Path $PSScriptRoot 'build.ps1') -SourcesPath $emptyManifest -SaveTo $packageVendor -Config $packageSource
$hook = Get-Content -Raw -LiteralPath (Join-Path $profileDir 'zz-cmder.sh')
if (!$hook.Contains('. "$CMDER_ROOT/vendor/cmder.sh"') -or $hook.Contains('__cmder_find_git_root')) {
throw 'Bundled profile hook must source the shared startup rather than copy it.'
}
if ([IO.File]::ReadAllText($legacyBundledHook) -ne 'legacy bundled hook') {
throw 'Package building must not rewrite the legacy bundled hook.'
}
$packageOutput = Join-Path $testRoot 'archives'
& (Join-Path $PSScriptRoot 'pack.ps1') -CmderRoot $packageSource -SaveTo $packageOutput
foreach ($profile in Get-CmderPackageProfiles) {
foreach ($package in $profile.packages) {
$archive = Join-Path $packageOutput "$($profile.outputFolder)\$($package.name)"
$listing = & 7z l -slt -ba $archive
if ($LASTEXITCODE) { throw "Cannot list $archive." }
if ($listing -contains 'Path = config\user_cmder_state.txt') {
throw "$($package.name) contains user-owned Cmder state."
}
foreach ($file in $startupFiles) {
if ($listing -notcontains "Path = vendor\$file") {
throw "$($package.name) is missing vendor\$file."
}
}
$hasBundledHook = $listing -contains 'Path = vendor\git-for-windows\etc\profile.d\zz-cmder.sh'
if ($hasBundledHook -ne ($package.name -notlike '*_nogit.zip')) {
throw "$($package.name) has incorrect bundled hook inclusion."
}
$cases++
}
}

Push-Location -LiteralPath $testRoot
try {
$version = Get-VersionStr
Expand Down
Loading
Loading