diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d265de..cc61977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Change Log +## [Unreleased] + +### Changes + +- Update Git for Windows to 2.31.1 + +### Adds + +- Configurable prompt for `cmd.exe` sessions. See `%cmder_root%\config\cmder_prompt_config.lua` + - Configurable colors + - Option to change `λ` to another character. + - Option to add `[user]@[host]` to the prompt + - Option to use of `~` to represent `$HOME` folder. + - Option to use folder name vs. full working directory path in prompt. + - Option to use single line prompt. + +### Fixes + +- Git prompt opt-out works better with additional changes to `clink-completions` + ## [1.3.18](https://github.com/cmderdev/cmder/tree/v1.3.18) (2021-3-26) ### Changes diff --git a/vendor/bin/vscode_init.cmd b/vendor/bin/vscode_init.cmd index bbe1ba2..79b0ea8 100644 --- a/vendor/bin/vscode_init.cmd +++ b/vendor/bin/vscode_init.cmd @@ -1,6 +1,6 @@ @echo off -:: Find root dir +rem Find root dir if not defined CMDER_ROOT ( for /f "delims=" %%i in ("%~dp0\..\..") do ( diff --git a/vendor/bin/vscode_init_args.cmd.default b/vendor/bin/vscode_init_args.cmd.default index 8ee8f89..4a17d93 100644 --- a/vendor/bin/vscode_init_args.cmd.default +++ b/vendor/bin/vscode_init_args.cmd.default @@ -1,58 +1,58 @@ @echo off -:: Below are the default Cmder session settings: -:: -:: See "%CMDER_ROOT%\README.md" for details on these settings. -:: -:: `Cmder.exe` Arguments: -:: ---------------------- -:: -:: `/c [cmder_user_cfg_root] -:: set cmder_user_bin=[cmder_user_cfg_root]\bin -:: set cmder_user_config=[cmder_user_cfg_root]\config -:: -:: `init.bat` Arguments -:: -------------------- -:: -:: `/d` -:: debug_output=0 -:: -:: `/v` -:: verbose_output=0 -:: -:: `/f` -:: fast_init=0 -:: -:: `/nix_tools` -:: nix_tools=1 -:: -:: `/t` -:: time_init=0 -:: -:: `/max_depth` -:: max_depth=1 -:: -:: `/user_aliases` -:: user_aliases= -:: -:: `/git_install_root` -:: GIT_INSTALL_ROOT= -:: -:: `/home` -:: HOME= -:: -:: `/svn_ssh` -:: SVN_SSH= +rem Below are the default Cmder session settings: +rem +rem See "%CMDER_ROOT%\README.md" for details on these settings. +rem +rem `Cmder.exe` Arguments: +rem ---------------------- +rem +rem `/c [cmder_user_cfg_root] +rem set cmder_user_bin=[cmder_user_cfg_root]\bin +rem set cmder_user_config=[cmder_user_cfg_root]\config +rem +rem `init.bat` Arguments +rem -------------------- +rem +rem `/d` +rem debug_output=0 +rem +rem `/v` +rem verbose_output=0 +rem +rem `/f` +rem fast_init=0 +rem +rem `/nix_tools` +rem nix_tools=1 +rem +rem `/t` +rem time_init=0 +rem +rem `/max_depth` +rem max_depth=1 +rem +rem `/user_aliases` +rem user_aliases= +rem +rem `/git_install_root` +rem GIT_INSTALL_ROOT= +rem +rem `/home` +rem HOME= +rem +rem `/svn_ssh` +rem SVN_SSH= echo Applying Cmder VSCode settings from '%~0'... if defined CMDER_CONFIGURED ( - :: Set Cmder settings here for when VSCode is launched inside Cmder. + rem Set Cmder settings here for when VSCode is launched inside Cmder. set verbose_output=1 ) else ( - :: Set Cmder settings here for when VSCode is launched from outside Cmder. + rem Set Cmder settings here for when VSCode is launched from outside Cmder. set verbose_output=1 ) -:: Set all required Cmder VSCode terminal environment settings above this line. +rem Set all required Cmder VSCode terminal environment settings above this line. echo Applying Cmder VSCode settings is complete! diff --git a/vendor/clink.lua b/vendor/clink.lua index 320ac76..c01d6be 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() @@ -311,9 +347,9 @@ local function git_prompt_filter() -- Colors for git status local colors = { - clean = "\x1b[1;37;40m", - dirty = "\x1b[33;3m", - conflict = "\x1b[31;1m" + clean = clean_color, + dirty = dirty_color, + conflict = conflict_color } local git_dir = get_git_dir() @@ -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 @@ -356,8 +392,8 @@ local function hg_prompt_filter() if hg_dir then -- Colors for mercurial status local colors = { - clean = "\x1b[1;37;40m", - dirty = "\x1b[31;1m", + clean = clean_color, + dirty = dirty_color, } local pipe = io.popen("hg branch 2>&1") @@ -390,8 +426,8 @@ end local function svn_prompt_filter() -- Colors for svn status local colors = { - clean = "\x1b[1;37;40m", - dirty = "\x1b[31;1m", + clean = clean_color, + dirty = dirty_color, } if get_svn_dir() then diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default new file mode 100644 index 0000000..5e59c14 --- /dev/null +++ b/vendor/cmder_prompt_config.lua.default @@ -0,0 +1,45 @@ +-- 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 +clean_color = "\x1b[1;37;40m" +dirty_color = "\x1b[33;3m" +conflict_color = "\x1b[31;1m" 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" diff --git a/vendor/sources.json b/vendor/sources.json index b970955..b552653 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -1,8 +1,8 @@ [ { "name": "git-for-windows", - "version": "v2.29.1.windows.1", - "url": "https://github.com/git-for-windows/git/releases/download/v2.29.1.windows.1/PortableGit-2.29.1-64-bit.7z.exe" + "version": "v2.31.1.windows.1", + "url": "https://github.com/git-for-windows/git/releases/download/v2.31.1.windows.1/PortableGit-2.31.1-64-bit.7z.exe" }, { "name": "clink",