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

Git opt out #2199

Merged
merged 14 commits into from
Nov 9, 2019
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vendor/*/*
!vendor/bin/*
!vendor/lib/*
!vendor/*
!vendor/psmodules/PsGet
!vendor/psmodules/*

config/*
!config/Readme.md
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

## [Unreleased]

## [1.3.13](https://github.com/cmderdev/cmder/tree/v1.3.12) (2019-10-27)
## [1.3.13](https://github.com/cmderdev/cmder/tree/v1.3.12) (2019-11-03)

### Adds

* #2197, #1364, #447 Add ability to disable git status either globally or for individual repos.
* To disable git status globally add the following to `~/.gitconfig` or locally for a single repo `[repo]/.git/config`:

```
[cmder]
status = false
```

* #2174 `--` Syntax to pass command line options to Conemu.
* Disable Clink Logging
* Add `~` tab completion.


### Fixes

* Fix #2191: profile.ps1: CheckGit does not export $gitLoaded
* Fix #2192: Set default prompt hooks before loading user profile
* Fix #2097, #1899: powershell foreground color changing to green
* Fix #1979: Update Clink Completions to 0.3.4
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ _(Some shortcuts are not yet documented, though they exist - please document the
### Access to multiple shells in one window using tabs
You can open multiple tabs each containing one of the following shells:

| Task | Shell | Description |
| ---- | ----- | ----------- |
| Task | Shell | Description |
| ---- | ----- | ----------- |
| Cmder | `cmd.exe` | Windows `cmd.exe` shell enhanced with Git, Git aware prompt, Clink (GNU Readline), and Aliases. |
| Cmder as Admin | `cmd.exe` | Administrative Windows `cmd.exe` Cmder shell. |
| PowerShell | `powershell.exe` | Windows PowerShell enhanced with Git and Git aware prompt . |
Expand Down Expand Up @@ -164,17 +164,28 @@ Single user portable configuration is possible using the cmder specific shell co
| ------------- | ----------------------------------------- |
| Cmder | `%CMDER_ROOT%\config\user_profile.cmd` |
| PowerShell | `$ENV:CMDER_ROOT\config\user_profile.ps1` |
| Bash/Mintty | `$CMDER_ROOT/config/user_profile.sh` |
| Bash/Mintty | `$CMDER_ROOT/config/user_profile.sh` |

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

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 |
| ------------- | --------------------------------------------------|
| Cmder | `%CMDER_ROOT%\config\profile.d\*.bat and *.cmd` |
| PowerShell | `$ENV:CMDER_ROOT\config\profile.d\*.ps1` |
| Bash/Mintty | `$CMDER_ROOT/config/profile.d/*.sh` |
| Shell | Cmder `Profile.d` Scripts |
| ------------- | -------------------------------------------------- |
| Cmder | `%CMDER_ROOT%\config\profile.d\*.bat and *.cmd` |
| PowerShell | `$ENV:CMDER_ROOT\config\profile.d\*.ps1` |
| Bash/Mintty | `$CMDER_ROOT/config/profile.d/*.sh` |

#### Git Status Opt-Out

To disable Cmder prompt git status globally add the following to `~/.gitconfig` or locally for a single repo `[repo]/.git/config` and start a new session.

*Note: This configuration is not portable*

```
[cmder]
status = false
```

### Aliases
#### Cmder(`Cmd.exe`) Aliases
Expand Down
61 changes: 41 additions & 20 deletions vendor/clink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ local function get_svn_status()
return true
end

---
-- Get the status of working dir
-- @return {bool}
---
local function get_git_status_setting()
gitStatusSetting = io.popen("git config cmder.status")

for line in gitStatusSetting:lines() do
if string.match(line, 'false') then
gitStatusSetting:close()
return false
end
end
gitStatusSetting:close()

return true
end

local function git_prompt_filter()

-- Colors for git status
Expand All @@ -290,27 +308,30 @@ local function git_prompt_filter()
}

local git_dir = get_git_dir()
if git_dir then
-- if we're inside of git repo then try to detect current branch
local branch = get_git_branch(git_dir)
local color
if branch then
-- Has branch => therefore it is a git folder, now figure out status
local gitStatus = get_git_status()
local gitConflict = get_git_conflict()

color = colors.dirty
if gitStatus then
color = colors.clean
end

if gitConflict then
color = colors.conflict
end

clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
return false
end
if get_git_status_setting() then
if git_dir then
-- if we're inside of git repo then try to detect current branch
local branch = get_git_branch(git_dir)
local color
if branch then
-- Has branch => therefore it is a git folder, now figure out status
local gitStatus = get_git_status()
local gitConflict = get_git_conflict()

color = colors.dirty
if gitStatus then
color = colors.clean
end

if gitConflict then
color = colors.conflict
end

clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
return false
end
end
end

-- No git present or not in git file
Expand Down
25 changes: 21 additions & 4 deletions vendor/git-prompt.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
function getGitStatusSetting() {
gitStatusSetting=$(git config cmder.status 2>/dev/null)

if [[ -n ${gitStatusSetting} ]] && [[ ${gitStatusSetting} == false ]]
then
echo false
else
echo true
fi
}

if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
Expand All @@ -7,7 +18,10 @@ fi

if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
if [[ $(getGitStatusSetting) == true ]]
then
. ~/.config/git/git-prompt.sh
fi
else
PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]' # set window title
# PS1="$PS1"'\n' # new line
Expand All @@ -26,9 +40,12 @@ else
if test -f "$COMPLETION_PATH/git-prompt.sh"
then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function
if [[ $(getGitStatusSetting) == true ]]
then
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
fi
PS1="$PS1"'\[\033[0m\]' # change color
Expand Down
49 changes: 5 additions & 44 deletions vendor/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,13 @@ $moduleInstallerAvailable = [bool](Get-Command -Name 'Install-Module' -ErrorActi
# Add Cmder modules directory to the autoload path.
$CmderModulePath = Join-path $PSScriptRoot "psmodules/"

$CmderFunctions = Join-Path $CmderModulePath "Cmder.ps1"
. $CmderFunctions

if(-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderModulePath) ){
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
}

function Configure-Git($GIT_INSTALL_ROOT){
$env:Path += $(";" + $GIT_INSTALL_ROOT + "\cmd")

# Add "$GIT_INSTALL_ROOT\usr\bin" to the path if exists and not done already
$GIT_INSTALL_ROOT_ESC=$GIT_INSTALL_ROOT.replace('\','\\')
if ((test-path "$GIT_INSTALL_ROOT\usr\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\usr\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\usr\bin"
}

# Add "$GIT_INSTALL_ROOT\mingw[32|64]\bin" to the path if exists and not done already
if ((test-path "$GIT_INSTALL_ROOT\mingw32\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw32\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\mingw32\bin"
} elseif ((test-path "$GIT_INSTALL_ROOT\mingw64\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw64\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\mingw64\bin"
}
}

$gitLoaded = $false
function Import-Git($Loaded){
if($Loaded) { return }
$GitModule = Get-Module -Name Posh-Git -ListAvailable
if($GitModule | select version | where version -le ([version]"0.6.1.20160330")){
Import-Module Posh-Git > $null
}
if(-not ($GitModule) ) {
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
}
# Make sure we only run once by alawys returning true
return $true
}

function checkGit($Path) {
if (Test-Path -Path (Join-Path $Path '.git') ) {
$gitLoaded = Import-Git $gitLoaded
Write-VcsStatus
return
}
$SplitPath = split-path $path
if ($SplitPath) {
checkGit($SplitPath)
}
}

try {
# Check if git is on PATH, i.e. Git already installed on system
Get-command -Name "git" -ErrorAction Stop >$null
Expand All @@ -97,6 +57,7 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
}

# Pre assign default prompt hooks so the first run of cmder gets a working prompt.
$env:gitLoaded = $false
[ScriptBlock]$PrePrompt = {}
[ScriptBlock]$PostPrompt = {}
[ScriptBlock]$CmderPrompt = {
Expand All @@ -106,6 +67,7 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
if (get-command git -erroraction silentlycontinue) {
checkGit($pwd.ProviderPath)
}
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
}

# Enhance Path
Expand Down Expand Up @@ -195,7 +157,6 @@ if ( $(get-command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
CmderPrompt
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
$global:LASTEXITCODE = $realLASTEXITCODE
return " "
Expand Down
56 changes: 56 additions & 0 deletions vendor/psmodules/Cmder.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function Configure-Git($GIT_INSTALL_ROOT){
$env:Path += $(";" + $GIT_INSTALL_ROOT + "\cmd")

# Add "$GIT_INSTALL_ROOT\usr\bin" to the path if exists and not done already
$GIT_INSTALL_ROOT_ESC=$GIT_INSTALL_ROOT.replace('\','\\')
if ((test-path "$GIT_INSTALL_ROOT\usr\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\usr\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\usr\bin"
}

# Add "$GIT_INSTALL_ROOT\mingw[32|64]\bin" to the path if exists and not done already
if ((test-path "$GIT_INSTALL_ROOT\mingw32\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw32\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\mingw32\bin"
} elseif ((test-path "$GIT_INSTALL_ROOT\mingw64\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw64\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\mingw64\bin"
}
}

function Import-Git(){
$GitModule = Get-Module -Name Posh-Git -ListAvailable
if($GitModule | select version | where version -le ([version]"0.6.1.20160330")){
Import-Module Posh-Git > $null
}
if(-not ($GitModule) ) {
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
}
# Make sure we only run once by alawys returning true
return $true
}

function checkGit($Path) {
if (Test-Path -Path (Join-Path $Path '.git') ) {
if($env:gitLoaded -eq 'false') {
$env:gitLoaded = Import-Git
}

if (getGitStatusSetting -eq $true) {
Write-VcsStatus
}

return
}
$SplitPath = split-path $path
if ($SplitPath) {
checkGit($SplitPath)
}
}

function getGitStatusSetting() {
$gitStatus = (git config cmder.status) | out-string

if (($gitStatus -replace "`n" -replace "`r") -eq "false") {
return $false
} else {
return $true
}
}