Merge pull request #2199 from daxgames/git_opt_out

Git opt out
This commit is contained in:
Dax T Games 2019-11-09 17:03:07 -05:00 committed by GitHub
commit 67f35bc05d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 151 additions and 76 deletions

2
.gitignore vendored
View File

@ -8,7 +8,7 @@ vendor/*/*
!vendor/bin/* !vendor/bin/*
!vendor/lib/* !vendor/lib/*
!vendor/* !vendor/*
!vendor/psmodules/PsGet !vendor/psmodules/*
config/* config/*
!config/Readme.md !config/Readme.md

View File

@ -2,10 +2,18 @@
## [Unreleased] ## [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 ### 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. * #2174 `--` Syntax to pass command line options to Conemu.
* Disable Clink Logging * Disable Clink Logging
* Add `~` tab completion. * Add `~` tab completion.
@ -13,6 +21,7 @@
### Fixes ### Fixes
* Fix #2191: profile.ps1: CheckGit does not export $gitLoaded
* Fix #2192: Set default prompt hooks before loading user profile * Fix #2192: Set default prompt hooks before loading user profile
* Fix #2097, #1899: powershell foreground color changing to green * Fix #2097, #1899: powershell foreground color changing to green
* Fix #1979: Update Clink Completions to 0.3.4 * Fix #1979: Update Clink Completions to 0.3.4

View File

@ -176,6 +176,17 @@ You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in t
| PowerShell | `$ENV:CMDER_ROOT\config\profile.d\*.ps1` | | PowerShell | `$ENV:CMDER_ROOT\config\profile.d\*.ps1` |
| Bash/Mintty | `$CMDER_ROOT/config/profile.d/*.sh` | | 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 ### Aliases
#### Cmder(`Cmd.exe`) Aliases #### Cmder(`Cmd.exe`) Aliases
You can define simple aliases for `cmd.exe` sessions with a command like `alias name=command`. Cmd.exe aliases support optional parameters through the `$1-9` or the `$*` special characters so the alias `vi=vim.exe $*` typed as `vi [filename]` will open `[filename]` in `vim.exe`. You can define simple aliases for `cmd.exe` sessions with a command like `alias name=command`. Cmd.exe aliases support optional parameters through the `$1-9` or the `$*` special characters so the alias `vi=vim.exe $*` typed as `vi [filename]` will open `[filename]` in `vim.exe`.

21
vendor/clink.lua vendored
View File

@ -280,6 +280,24 @@ local function get_svn_status()
return true return true
end 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() local function git_prompt_filter()
-- Colors for git status -- Colors for git status
@ -290,6 +308,8 @@ local function git_prompt_filter()
} }
local git_dir = get_git_dir() local git_dir = get_git_dir()
if get_git_status_setting() then
if git_dir then if git_dir then
-- if we're inside of git repo then try to detect current branch -- if we're inside of git repo then try to detect current branch
local branch = get_git_branch(git_dir) local branch = get_git_branch(git_dir)
@ -312,6 +332,7 @@ local function git_prompt_filter()
return false return false
end end
end end
end
-- No git present or not in git file -- No git present or not in git file
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "") clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "")

17
vendor/git-prompt.sh vendored
View File

@ -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 if test -f /etc/profile.d/git-sdk.sh
then then
TITLEPREFIX=SDK-${MSYSTEM#MINGW} TITLEPREFIX=SDK-${MSYSTEM#MINGW}
@ -6,8 +17,11 @@ else
fi fi
if test -f ~/.config/git/git-prompt.sh if test -f ~/.config/git/git-prompt.sh
then
if [[ $(getGitStatusSetting) == true ]]
then then
. ~/.config/git/git-prompt.sh . ~/.config/git/git-prompt.sh
fi
else else
PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]' # set window title PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]' # set window title
# PS1="$PS1"'\n' # new line # PS1="$PS1"'\n' # new line
@ -26,11 +40,14 @@ else
if test -f "$COMPLETION_PATH/git-prompt.sh" if test -f "$COMPLETION_PATH/git-prompt.sh"
then then
. "$COMPLETION_PATH/git-completion.bash" . "$COMPLETION_PATH/git-completion.bash"
if [[ $(getGitStatusSetting) == true ]]
then
. "$COMPLETION_PATH/git-prompt.sh" . "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function PS1="$PS1"'`__git_ps1`' # bash function
fi fi
fi fi
fi
PS1="$PS1"'\[\033[0m\]' # change color PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line PS1="$PS1"'\n' # new line
PS1="$PS1"'λ ' # prompt: always λ PS1="$PS1"'λ ' # prompt: always λ

49
vendor/profile.ps1 vendored
View File

@ -32,53 +32,13 @@ $moduleInstallerAvailable = [bool](Get-Command -Name 'Install-Module' -ErrorActi
# Add Cmder modules directory to the autoload path. # Add Cmder modules directory to the autoload path.
$CmderModulePath = Join-path $PSScriptRoot "psmodules/" $CmderModulePath = Join-path $PSScriptRoot "psmodules/"
$CmderFunctions = Join-Path $CmderModulePath "Cmder.ps1"
. $CmderFunctions
if(-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderModulePath) ){ if(-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderModulePath) ){
$env:PSModulePath = $env:PSModulePath.Insert(0, "$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 { try {
# Check if git is on PATH, i.e. Git already installed on system # Check if git is on PATH, i.e. Git already installed on system
Get-command -Name "git" -ErrorAction Stop >$null Get-command -Name "git" -ErrorAction Stop >$null
@ -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. # Pre assign default prompt hooks so the first run of cmder gets a working prompt.
$env:gitLoaded = $false
[ScriptBlock]$PrePrompt = {} [ScriptBlock]$PrePrompt = {}
[ScriptBlock]$PostPrompt = {} [ScriptBlock]$PostPrompt = {}
[ScriptBlock]$CmderPrompt = { [ScriptBlock]$CmderPrompt = {
@ -106,6 +67,7 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
if (get-command git -erroraction silentlycontinue) { if (get-command git -erroraction silentlycontinue) {
checkGit($pwd.ProviderPath) checkGit($pwd.ProviderPath)
} }
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
} }
# Enhance Path # Enhance Path
@ -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 $host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
CmderPrompt CmderPrompt
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
$global:LASTEXITCODE = $realLASTEXITCODE $global:LASTEXITCODE = $realLASTEXITCODE
return " " return " "

56
vendor/psmodules/Cmder.ps1 vendored Normal file
View File

@ -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
}
}