mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 09:49:12 +08:00
enhance cmder prompt
This commit is contained in:
parent
0ba0dea6a2
commit
96ca7cea4a
@ -1,6 +1,6 @@
|
|||||||
# How to contribute
|
# How to contribute
|
||||||
|
|
||||||
Unfortunately we all can't work on cmder every day of the year, so I have decided to write some guidelines for contributing.
|
Unfortunately we all can't work on Cmder every day of the year, so I have decided to write some guidelines for contributing.
|
||||||
|
|
||||||
If you follow them your contribution will likely be pulled in quicker.
|
If you follow them your contribution will likely be pulled in quicker.
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ function Get-VersionStr {
|
|||||||
|
|
||||||
# Determine if git is available
|
# Determine if git is available
|
||||||
if (Get-Command "git.exe" -ErrorAction SilentlyContinue) {
|
if (Get-Command "git.exe" -ErrorAction SilentlyContinue) {
|
||||||
# Determine if the current diesctory is a git repository
|
# Determine if the current directory is a git repository
|
||||||
$GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -erroraction SilentlyContinue
|
$GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if ( $GitPresent -eq 'true' ) {
|
if ( $GitPresent -eq 'true' ) {
|
||||||
$string = Invoke-Expression "git describe --abbrev=0 --tags"
|
$string = Invoke-Expression "git describe --abbrev=0 --tags"
|
||||||
|
4
vendor/clink.lua
vendored
4
vendor/clink.lua
vendored
@ -161,6 +161,8 @@ local function set_prompt_filter()
|
|||||||
cr = ' '
|
cr = ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cr = "\x1b[0m" .. cr
|
||||||
|
|
||||||
if env ~= nil then env = "("..env..") " else env = "" end
|
if env ~= nil then env = "("..env..") " else env = "" end
|
||||||
|
|
||||||
if uah ~= '' then uah = get_uah_color() .. uah end
|
if uah ~= '' then uah = get_uah_color() .. uah end
|
||||||
@ -168,7 +170,7 @@ local function set_prompt_filter()
|
|||||||
|
|
||||||
local version_control = prompt_includeVersionControl and "{git}{hg}{svn}" or ""
|
local version_control = prompt_includeVersionControl and "{git}{hg}{svn}" or ""
|
||||||
|
|
||||||
prompt = "{uah}{cwd}" .. version_control .. get_lamb_color() .. cr .. "{env}{lamb} \x1b[0m"
|
prompt = "{uah}{cwd}" .. version_control .. cr .. get_lamb_color() .. "{env}{lamb}\x1b[0m "
|
||||||
prompt = string.gsub(prompt, "{uah}", uah)
|
prompt = string.gsub(prompt, "{uah}", uah)
|
||||||
prompt = string.gsub(prompt, "{cwd}", cwd)
|
prompt = string.gsub(prompt, "{cwd}", cwd)
|
||||||
prompt = string.gsub(prompt, "{env}", env)
|
prompt = string.gsub(prompt, "{env}", env)
|
||||||
|
9
vendor/clink_settings.default
vendored
9
vendor/clink_settings.default
vendored
@ -17,3 +17,12 @@ history.max_lines = 10000
|
|||||||
# name: Share history between instances
|
# name: Share history between instances
|
||||||
# type: boolean
|
# type: boolean
|
||||||
history.shared = True
|
history.shared = True
|
||||||
|
|
||||||
|
# name: Auto-answer terminate prompt
|
||||||
|
# type: enum
|
||||||
|
# options: off,answer_yes,answer_no
|
||||||
|
cmd.auto_answer = answer_yes
|
||||||
|
|
||||||
|
# name: Doskey completions
|
||||||
|
# type: color
|
||||||
|
color.doskey = yellow
|
||||||
|
2
vendor/init.bat
vendored
2
vendor/init.bat
vendored
@ -155,7 +155,7 @@ if "%CMDER_CLINK%" == "1" (
|
|||||||
:: Run Clink
|
:: Run Clink
|
||||||
if defined CMDER_USER_CONFIG (
|
if defined CMDER_USER_CONFIG (
|
||||||
if not exist "%CMDER_USER_CONFIG%\settings" if not exist "%CMDER_USER_CONFIG%\clink_settings" (
|
if not exist "%CMDER_USER_CONFIG%\settings" if not exist "%CMDER_USER_CONFIG%\clink_settings" (
|
||||||
echo Generating clink initial settings in "%CMDER_USER_CONFIG%\clink_settings"
|
echo Generating Clink initial settings in "%CMDER_USER_CONFIG%\clink_settings"
|
||||||
copy "%CMDER_ROOT%\vendor\clink_settings.default" "%CMDER_USER_CONFIG%\clink_settings"
|
copy "%CMDER_ROOT%\vendor\clink_settings.default" "%CMDER_USER_CONFIG%\clink_settings"
|
||||||
echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup.
|
echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup.
|
||||||
)
|
)
|
||||||
|
31
vendor/profile.ps1
vendored
31
vendor/profile.ps1
vendored
@ -1,5 +1,6 @@
|
|||||||
# Init Script for PowerShell
|
# Init Script for PowerShell
|
||||||
# Created as part of cmder project
|
# Created as part of Cmder project
|
||||||
|
# This file must be saved using UTF-8 with BOM encoding for prompt to work correctly.
|
||||||
|
|
||||||
# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
|
# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
|
||||||
# !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands
|
# !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands
|
||||||
@ -16,8 +17,8 @@ if ($ENV:CMDER_USER_CONFIG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# We do this for Powershell as Admin Sessions because CMDER_ROOT is not being set.
|
# We do this for Powershell as Admin Sessions because CMDER_ROOT is not being set.
|
||||||
if ($null -eq $ENV:CMDER_ROOT) {
|
if (!$ENV:CMDER_ROOT) {
|
||||||
if (-Not($null -eq $ENV:ConEmuDir)) {
|
if ($ENV:ConEmuDir) {
|
||||||
$ENV:CMDER_ROOT = Resolve-Path($ENV:ConEmuDir + "\..\..")
|
$ENV:CMDER_ROOT = Resolve-Path($ENV:ConEmuDir + "\..\..")
|
||||||
} else {
|
} else {
|
||||||
$ENV:CMDER_ROOT = Resolve-Path($PSScriptRoot + "\..")
|
$ENV:CMDER_ROOT = Resolve-Path($PSScriptRoot + "\..")
|
||||||
@ -25,7 +26,7 @@ if ($null -eq $ENV:CMDER_ROOT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Remove trailing '\'
|
# Remove trailing '\'
|
||||||
$ENV:CMDER_ROOT = ($ENV:CMDER_ROOT).trimend("\")
|
$ENV:CMDER_ROOT = ($ENV:CMDER_ROOT).TrimEnd("\")
|
||||||
|
|
||||||
# Do not load bundled PsGet if a module installer is already available
|
# Do not load bundled PsGet if a module installer is already available
|
||||||
# -> recent PowerShell versions include PowerShellGet out of the box
|
# -> recent PowerShell versions include PowerShellGet out of the box
|
||||||
@ -85,7 +86,7 @@ if (-Not ($null -eq $ENV:GIT_INSTALL_ROOT)) {
|
|||||||
$env:Path = Configure-Git -gitRoot "$ENV:GIT_INSTALL_ROOT" -gitType $ENV:GIT_INSTALL_TYPE -gitPathUser $gitPathUser
|
$env:Path = Configure-Git -gitRoot "$ENV:GIT_INSTALL_ROOT" -gitType $ENV:GIT_INSTALL_TYPE -gitPathUser $gitPathUser
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Get-Command -Name "vim" -ErrorAction silentlycontinue) {
|
if (Get-Command -Name "vim" -ErrorAction SilentlyContinue) {
|
||||||
New-Alias -name "vi" -value vim
|
New-Alias -name "vi" -value vim
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +99,15 @@ $env:gitLoaded = $false
|
|||||||
[ScriptBlock]$PrePrompt = {}
|
[ScriptBlock]$PrePrompt = {}
|
||||||
[ScriptBlock]$PostPrompt = {}
|
[ScriptBlock]$PostPrompt = {}
|
||||||
[ScriptBlock]$CmderPrompt = {
|
[ScriptBlock]$CmderPrompt = {
|
||||||
|
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
$principal = [Security.Principal.WindowsPrincipal] $identity
|
||||||
|
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||||||
|
$color = "White"
|
||||||
|
if ($principal.IsInRole($adminRole)) { $color = "Red" }
|
||||||
$Host.UI.RawUI.ForegroundColor = "White"
|
$Host.UI.RawUI.ForegroundColor = "White"
|
||||||
Write-Host -NoNewline "PS "
|
Microsoft.PowerShell.Utility\Write-Host -NoNewline "PS " -ForegroundColor $color
|
||||||
Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
|
Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
|
||||||
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"
|
Microsoft.PowerShell.Utility\Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
|
||||||
@ -170,7 +176,7 @@ if ($ENV:CMDER_USER_CONFIG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-Not (Test-Path $CmderUserProfilePath)) {
|
if (-Not (Test-Path $CmderUserProfilePath)) {
|
||||||
Write-Host -BackgroundColor Darkgreen -ForegroundColor White "First Run: Creating user startup file: $CmderUserProfilePath"
|
Write-Host -BackgroundColor DarkGreen -ForegroundColor White "First Run: Creating user startup file: $CmderUserProfilePath"
|
||||||
Copy-Item "$env:CMDER_ROOT\vendor\user_profile.ps1.default" -Destination $CmderUserProfilePath
|
Copy-Item "$env:CMDER_ROOT\vendor\user_profile.ps1.default" -Destination $CmderUserProfilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +196,13 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
|
|||||||
Custom prompt functions are loaded in as constants to get the same behaviour
|
Custom prompt functions are loaded in as constants to get the same behaviour
|
||||||
#>
|
#>
|
||||||
[ScriptBlock]$Prompt = {
|
[ScriptBlock]$Prompt = {
|
||||||
|
$lastSUCCESS = $?
|
||||||
$realLASTEXITCODE = $LASTEXITCODE
|
$realLASTEXITCODE = $LASTEXITCODE
|
||||||
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
|
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
|
||||||
|
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x200B)`r$([char]0x1B)[K"
|
||||||
|
if ($lastSUCCESS -Or ($LASTEXITCODE -ne 0)) {
|
||||||
|
Microsoft.PowerShell.Utility\Write-Host
|
||||||
|
}
|
||||||
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
||||||
CmderPrompt
|
CmderPrompt
|
||||||
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
||||||
@ -216,4 +227,4 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
|
|||||||
}
|
}
|
||||||
|
|
||||||
$CMDER_INIT_END = $(Get-Date -UFormat %s)
|
$CMDER_INIT_END = $(Get-Date -UFormat %s)
|
||||||
# Write-Host "Elapsed Time: $(get-Date) `($($CMDER_INIT_END - $CMDER_INIT_START) total`)"
|
Write-Verbose "Elapsed Time: $(get-Date) `($($CMDER_INIT_END - $CMDER_INIT_START) total`)"
|
||||||
|
Loading…
Reference in New Issue
Block a user