mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 01:12:11 +08:00 
			
		
		
		
	Add branchonly option to cmdstatus
This commit is contained in:
		| @@ -194,10 +194,11 @@ You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in t | ||||
|  | ||||
|  ``` | ||||
|  [cmder] | ||||
|    status = false      # Opt out of Git status for 'ALL' Cmder supported shells. | ||||
|    cmdstatus = false   # Opt out of Git status for 'Cmd.exe' shells. | ||||
|    psstatus = false    # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. | ||||
|    shstatus = false    # Opt out of Git status for 'bash.exe' shells. | ||||
|    status = false          # Opt out of Git status for 'ALL' Cmder supported shells. | ||||
|    cmdstatus = false       # Opt out of Git status for 'Cmd.exe' shells. | ||||
|    cmdstatus = branchonly  # Show branch name in 'Cmd.exe' shells, but don't color according to status (faster) | ||||
|    psstatus = false        # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. | ||||
|    shstatus = false        # Opt out of Git status for 'bash.exe' shells. | ||||
|  ``` | ||||
|  | ||||
| ### Aliases | ||||
|   | ||||
							
								
								
									
										53
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										53
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							| @@ -41,6 +41,10 @@ local function get_conflict_color() | ||||
|   return conflict_color or "\x1b[31;1m" | ||||
| end | ||||
|  | ||||
| local function get_unknown_color() | ||||
|   return unknown_color or "\x1b[30;1m" | ||||
| end | ||||
|  | ||||
| --- | ||||
| -- Makes a string safe to use as the replacement in string.gsub | ||||
| --- | ||||
| @@ -361,27 +365,29 @@ end | ||||
|  | ||||
| --- | ||||
| -- Get the status of working dir | ||||
| -- @return {bool} | ||||
| -- @return {bool|'branchonly'} | ||||
| --- | ||||
| local function get_git_status_setting() | ||||
|     local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul") | ||||
|     local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") | ||||
|     for line in gitCmdStatusConfig:lines() do | ||||
|         if string.match(line, 'false') then | ||||
|           gitCmdStatusConfig:close() | ||||
|           return false | ||||
|         elseif string.match(line, 'branchonly') then | ||||
|           gitCmdStatusConfig:close() | ||||
|           return 'branchonly' | ||||
|         end | ||||
|     end | ||||
|     gitCmdStatusConfig:close() | ||||
|  | ||||
|     local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul") | ||||
|     for line in gitStatusConfig:lines() do | ||||
|         if string.match(line, 'false') then | ||||
|           gitStatusConfig:close() | ||||
|           return false | ||||
|         end | ||||
|     end | ||||
|  | ||||
|     local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") | ||||
|     for line in gitCmdStatusConfig:lines() do | ||||
|         if string.match(line, 'false') then | ||||
|           gitCmdStatusConfig:close() | ||||
|           return false | ||||
|         end | ||||
|     end | ||||
|     gitStatusConfig:close() | ||||
|     gitCmdStatusConfig:close() | ||||
|  | ||||
|     return true | ||||
| end | ||||
| @@ -392,7 +398,8 @@ local function git_prompt_filter() | ||||
|     local colors = { | ||||
|         clean = get_clean_color(), | ||||
|         dirty = get_dirty_color(), | ||||
|         conflict = get_conflict_color() | ||||
|         conflict = get_conflict_color(), | ||||
|         unknown = get_unknown_color() | ||||
|     } | ||||
|  | ||||
|     local git_dir = get_git_dir() | ||||
| @@ -403,17 +410,21 @@ local function git_prompt_filter() | ||||
|           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() | ||||
|               if cmderGitStatusOptIn ~= 'branchonly' 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 | ||||
|                 color = colors.dirty | ||||
|                 if gitStatus then | ||||
|                     color = colors.clean | ||||
|                 end | ||||
|  | ||||
|               if gitConflict then | ||||
|                   color = colors.conflict | ||||
|                 if gitConflict then | ||||
|                     color = colors.conflict | ||||
|                 end | ||||
|               else | ||||
|                 color = colors.unknown | ||||
|               end | ||||
|  | ||||
|               clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") | ||||
|   | ||||
							
								
								
									
										1
									
								
								vendor/cmder_prompt_config.lua.default
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/cmder_prompt_config.lua.default
									
									
									
									
										vendored
									
									
								
							| @@ -43,3 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color | ||||
| clean_color = "\x1b[1;37;40m" | ||||
| dirty_color = "\x1b[33;3m" | ||||
| conflict_color = "\x1b[31;1m" | ||||
| unknown_color = "\x1b[30;1m" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user