mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 17:32:27 +08:00 
			
		
		
		
	Add branchonly option to cmdstatus
This commit is contained in:
		| @@ -196,6 +196,7 @@ You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in t | |||||||
|  [cmder] |  [cmder] | ||||||
|    status = false          # Opt out of Git status for 'ALL' Cmder supported 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 = 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. |    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. |    shstatus = false        # Opt out of Git status for 'bash.exe' shells. | ||||||
|  ``` |  ``` | ||||||
|   | |||||||
							
								
								
									
										35
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							| @@ -41,6 +41,10 @@ local function get_conflict_color() | |||||||
|   return conflict_color or "\x1b[31;1m" |   return conflict_color or "\x1b[31;1m" | ||||||
| end | 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 | -- Makes a string safe to use as the replacement in string.gsub | ||||||
| --- | --- | ||||||
| @@ -361,27 +365,29 @@ end | |||||||
|  |  | ||||||
| --- | --- | ||||||
| -- Get the status of working dir | -- Get the status of working dir | ||||||
| -- @return {bool} | -- @return {bool|'branchonly'} | ||||||
| --- | --- | ||||||
| local function get_git_status_setting() | 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 |     for line in gitStatusConfig:lines() do | ||||||
|         if string.match(line, 'false') then |         if string.match(line, 'false') then | ||||||
|           gitStatusConfig:close() |           gitStatusConfig:close() | ||||||
|           return false |           return false | ||||||
|         end |         end | ||||||
|     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() |     gitStatusConfig:close() | ||||||
|     gitCmdStatusConfig:close() |  | ||||||
|  |  | ||||||
|     return true |     return true | ||||||
| end | end | ||||||
| @@ -392,7 +398,8 @@ local function git_prompt_filter() | |||||||
|     local colors = { |     local colors = { | ||||||
|         clean = get_clean_color(), |         clean = get_clean_color(), | ||||||
|         dirty = get_dirty_color(), |         dirty = get_dirty_color(), | ||||||
|         conflict = get_conflict_color() |         conflict = get_conflict_color(), | ||||||
|  |         unknown = get_unknown_color() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     local git_dir = get_git_dir() |     local git_dir = get_git_dir() | ||||||
| @@ -403,6 +410,7 @@ local function git_prompt_filter() | |||||||
|           local branch = get_git_branch(git_dir) |           local branch = get_git_branch(git_dir) | ||||||
|           local color |           local color | ||||||
|           if branch then |           if branch then | ||||||
|  |               if cmderGitStatusOptIn ~= 'branchonly' then | ||||||
|                 -- Has branch => therefore it is a git folder, now figure out status |                 -- Has branch => therefore it is a git folder, now figure out status | ||||||
|                 local gitStatus = get_git_status() |                 local gitStatus = get_git_status() | ||||||
|                 local gitConflict = get_git_conflict() |                 local gitConflict = get_git_conflict() | ||||||
| @@ -415,6 +423,9 @@ local function git_prompt_filter() | |||||||
|                 if gitConflict then |                 if gitConflict then | ||||||
|                     color = colors.conflict |                     color = colors.conflict | ||||||
|                 end |                 end | ||||||
|  |               else | ||||||
|  |                 color = colors.unknown | ||||||
|  |               end | ||||||
|  |  | ||||||
|               clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") |               clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") | ||||||
|               return false |               return false | ||||||
|   | |||||||
							
								
								
									
										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" | clean_color = "\x1b[1;37;40m" | ||||||
| dirty_color = "\x1b[33;3m" | dirty_color = "\x1b[33;3m" | ||||||
| conflict_color = "\x1b[31;1m" | conflict_color = "\x1b[31;1m" | ||||||
|  | unknown_color = "\x1b[30;1m" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user