diff --git a/vendor/clink.lua b/vendor/clink.lua index 320ac76..d0e1264 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -21,6 +21,16 @@ local function verbatim(s) return s 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 -- 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 if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end - -- build our own prompt - -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m - -- color codes: "\x1b[1;37;40m" - local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m" - local lambda = "λ" - cmder_prompt = string.gsub(cmder_prompt, "{cwd}", verbatim(cwd)) + -- Much of the below was 'borrowed' from https://github.com/AmrEldib/cmder-powerline-prompt + -- Symbol displayed for the home dir in the prompt. + if not prompt_homeSymbol then + prompt_homeSymbol = "~" + end + + -- 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 - lambda = "("..env..") "..lambda + prompt_lambSymbol = "("..env..") "..prompt_lambSymbol 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 local function percent_prompt_filter() @@ -335,7 +371,7 @@ local function git_prompt_filter() if gitConflict then color = colors.conflict - end + end clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") return false diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default new file mode 100644 index 0000000..9d6360d --- /dev/null +++ b/vendor/cmder_prompt_config.lua.default @@ -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 diff --git a/vendor/init.bat b/vendor/init.bat index 36f5024..3b1bf6a 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -154,6 +154,11 @@ if "%CMDER_CLINK%" == "1" ( 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 if exist "%CMDER_USER_CONFIG%\settings" if exist "%CMDER_USER_CONFIG%\clink_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. ) + 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 if exist "%CMDER_ROOT%\config\settings" if exist "%CMDER_ROOT%\config\clink_settings" ( del "%CMDER_ROOT%\config\settings"