mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 17:32:27 +08:00 
			
		
		
		
	add configurable prompt
This commit is contained in:
		
							
								
								
									
										52
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										52
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							| @@ -21,6 +21,16 @@ local function verbatim(s) | |||||||
|     return s |     return s | ||||||
| end | end | ||||||
|  |  | ||||||
|  | -- Extracts only the folder name from the input Path | ||||||
|  | -- Ex: Input C:\Windows\System32 returns System32 | ||||||
|  | --- | ||||||
|  | local function get_folder_name(path) | ||||||
|  |   local reversePath = string.reverse(path) | ||||||
|  |   local slashIndex = string.find(reversePath, "\\") | ||||||
|  |   return string.sub(path, string.len(path) - slashIndex + 2) | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
| --- | --- | ||||||
| -- Setting the prompt in clink means that commands which rewrite the prompt do | -- Setting the prompt in clink means that commands which rewrite the prompt do | ||||||
| -- not destroy our own prompt. It also means that started cmds (or batch files | -- not destroy our own prompt. It also means that started cmds (or batch files | ||||||
| @@ -44,17 +54,43 @@ local function set_prompt_filter() | |||||||
|     -- also check for square brackets |     -- also check for square brackets | ||||||
|     if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end |     if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end | ||||||
|  |  | ||||||
|     -- build our own prompt |     -- Much of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt | ||||||
|     -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m |     -- Symbol displayed for the home dir in the prompt. | ||||||
|     -- color codes: "\x1b[1;37;40m" |     if not prompt_homeSymbol then | ||||||
|     local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m" |       prompt_homeSymbol = "~" | ||||||
|     local lambda = "λ" |     end | ||||||
|     cmder_prompt = string.gsub(cmder_prompt, "{cwd}", verbatim(cwd)) |  | ||||||
|  |     -- Symbol displayed in the new line below the prompt. | ||||||
|  |     if not prompt_lambSymbol then | ||||||
|  |       prompt_lambSymbol = "λ" | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     if prompt_type == 'folder' then | ||||||
|  |         cwd = get_folder_name(cwd) | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     if prompt_useHomeSymbol and string.find(cwd, clink.get_env("HOME")) then | ||||||
|  |         cwd = string.gsub(cwd, clink.get_env("HOME"), prompt_homeSymbol) | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     uah = '' | ||||||
|  |     if prompt_useUserAtHost then | ||||||
|  |         uah = clink.get_env("USERNAME") .. "@" .. clink.get_env("COMPUTERNAME") .. ' ' | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     cr = "\n" | ||||||
|  |     if prompt_singleLine then | ||||||
|  |       cr = ' ' | ||||||
|  |     end | ||||||
|  |  | ||||||
|     if env ~= nil then |     if env ~= nil then | ||||||
|         lambda = "("..env..") "..lambda |         prompt_lambSymbol = "("..env..") "..prompt_lambSymbol | ||||||
|     end |     end | ||||||
|     clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", verbatim(lambda)) |  | ||||||
|  |     prompt = uah_color .. "{uah}" .. cwd_color .. "{cwd}{git}{hg}{svn}" .. lamb_color .. cr .. "{lamb} \x1b[0m" | ||||||
|  |     uah_value = string.gsub(prompt, "{uah}", uah) | ||||||
|  |     new_value = string.gsub(uah_value, "{cwd}", cwd) | ||||||
|  |     clink.prompt.value = string.gsub(new_value, "{lamb}", prompt_lambSymbol) | ||||||
| end | end | ||||||
|  |  | ||||||
| local function percent_prompt_filter() | local function percent_prompt_filter() | ||||||
|   | |||||||
							
								
								
									
										42
									
								
								vendor/cmder_prompt_config.lua.default
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								vendor/cmder_prompt_config.lua.default
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | -- All of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt | ||||||
|  |  | ||||||
|  | --- REQUIRED. config_prompt_type is whether the displayed prompt is the full path or only the folder name | ||||||
|  |  -- Use: | ||||||
|  |  -- "full" for full path like C:\Windows\System32 | ||||||
|  |  -- "folder" for folder name only like System32 | ||||||
|  |  -- default is full | ||||||
|  | prompt_type = "full" | ||||||
|  |  | ||||||
|  | --- REQUIRED. config_prompt_useHomeSymbol is whether to show ~ instead of the full path to the user's home folder | ||||||
|  |  -- Use true or false | ||||||
|  |  -- default is false | ||||||
|  | prompt_useHomeSymbol = false | ||||||
|  |  | ||||||
|  | -- Symbols | ||||||
|  | -- REQUIRED. Prompt displayed instead of user's home folder e.g. C:\Users\username | ||||||
|  |  -- default is '~' | ||||||
|  | prompt_homeSymbol = "~" | ||||||
|  |  | ||||||
|  | -- REQUIRED. Symbol displayed in the new line below the prompt. | ||||||
|  |  -- default is 'λ' | ||||||
|  | prompt_lambSymbol = "λ" | ||||||
|  |  | ||||||
|  | -- REQUIRED. Adds [user]@[host] to the beginning of the prompt like bash | ||||||
|  |  -- default is false | ||||||
|  | prompt_useUserAtHost = false | ||||||
|  |  | ||||||
|  | -- REQUIRED. If true prompt is a single line instead of default two line prompt. | ||||||
|  |  -- default is false | ||||||
|  | prompt_singleLine = false | ||||||
|  |  | ||||||
|  | -- Prompt Attributes | ||||||
|  | -- | ||||||
|  | -- Colors | ||||||
|  | -- Green:      "\x1b[1;33;40m" | ||||||
|  | -- Yellow:     "\x1b[1;32;40m" | ||||||
|  | -- Light Grey: "\x1b[1;30;40m" | ||||||
|  |  | ||||||
|  | -- Prompt Element Colors | ||||||
|  | uah_color = "\x1b[1;33;40m" -- Green = uah = [user]@[hostname] | ||||||
|  | cwd_color = "\x1b[1;32;40m" -- Yellow cwd = Current Working Directory | ||||||
|  | lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color | ||||||
							
								
								
									
										10
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							| @@ -154,6 +154,11 @@ if "%CMDER_CLINK%" == "1" ( | |||||||
|       echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup. |       echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup. | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     if not exist "%CMDER_USER_CONFIG%\cmder_prompt_config.lua" ( | ||||||
|  |       echo Creating Cmder prompt config file: "%CMDER_USER_CONFIG%\cmder_prompt_config.lua" | ||||||
|  |       copy "%CMDER_ROOT%\vendor\cmder_prompt_config.lua.default" "%CMDER_USER_CONFIG%\cmder_prompt_config.lua" | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     REM Cleanup lagacy Clink Settings file |     REM Cleanup lagacy Clink Settings file | ||||||
|     if exist "%CMDER_USER_CONFIG%\settings" if exist "%CMDER_USER_CONFIG%\clink_settings" ( |     if exist "%CMDER_USER_CONFIG%\settings" if exist "%CMDER_USER_CONFIG%\clink_settings" ( | ||||||
|       del "%CMDER_USER_CONFIG%\settings" |       del "%CMDER_USER_CONFIG%\settings" | ||||||
| @@ -171,6 +176,11 @@ if "%CMDER_CLINK%" == "1" ( | |||||||
|       echo Additional *.lua files in "%CMDER_ROOT%\config" are loaded on startup. |       echo Additional *.lua files in "%CMDER_ROOT%\config" are loaded on startup. | ||||||
|     ) |     ) | ||||||
|      |      | ||||||
|  |     if not exist "%CMDER_ROOT%\config\cmder_prompt_config.lua" ( | ||||||
|  |       echo Creating Cmder prompt config file: "%CMDER_ROOT%\config\cmder_prompt_config.lua" | ||||||
|  |       copy "%CMDER_ROOT%\vendor\cmder_prompt_config.lua.default" "%CMDER_ROOT%\config\cmder_prompt_config.lua" | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     REM Cleanup lagacy Clink Settings file |     REM Cleanup lagacy Clink Settings file | ||||||
|     if exist "%CMDER_ROOT%\config\settings" if exist "%CMDER_ROOT%\config\clink_settings" ( |     if exist "%CMDER_ROOT%\config\settings" if exist "%CMDER_ROOT%\config\clink_settings" ( | ||||||
|       del "%CMDER_ROOT%\config\settings" |       del "%CMDER_ROOT%\config\settings" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user