Commit Graph

81 Commits

Author SHA1 Message Date
Chris Antos
84ee96c64f Fix #2859; script error when cwd name contains %
The `string.gsub()` function in Lua always uses Lua patterns (which are
similar to regular expressions).  Cmder's custom prompt wants to perform
simple plain text find/replace operations on strings.  `string.gsub()`
is the right Lua function for that, but since it always uses Lua
patterns it's necessary to apply escaping to the input strings otherwise
they can get misinterpreted and cause runtime errors.

For example, if the current working directory name contains a percent
sign, such as literally "My%20Home".

This change fixes that.  It introduces a helper function `gsub_plain()`
which behaves like `string.gsub()` but applies appropriate escaping to
convert the plain text input strings into the corresponding Lua
patterns so that it can achieve plain text find/replace operations.

It also introduces separate helper functions for escaping the `find` and
`replace` parameters for `string.gsub()`, since they have different
escaping rules.
2023-07-10 18:07:53 -07:00
Chris Antos
a605ec520d Clean luacheck warnings. 2023-05-15 09:18:59 -07:00
Chris Antos
5fab87f4d6 Remove unused function.
The `get_hg_status()` function has been unused since commit
35eab7a51a in 2018.
2023-05-15 09:18:47 -07:00
Chris Antos
c9153c96bf Fix global Lua namespace pollution.
Some variables were global when the intent was to be local variables.
2023-05-15 09:17:01 -07:00
Chris Antos
74381ecd19 Fix #2846; errors when git/svn/hg not installed.
Also fixes error when HEAD is not available in a git repo, e.g. due to a
corrupt repo.
2023-05-15 09:15:36 -07:00
Chris Antos
0fdcda98cf Fix https://github.com/cmderdev/cmder/issues/2789
Holding ^C made git.exe hang while cmd.exe (Clink) updated the prompt.

The prompt script had three problems:

1.  It invoked `git config` every time a prompt was displayed, to
    figure out where to skip invoking `git status`.  But it even did
    that if the current directory wasn't part of a git repo.
2.  It invoked `git config` two times for every single prompt, to
    attempt to improve performance if the user disables `git status`
    coloring.  But two times for every single prompt is expensive, so
    it has the opposite effect in the general case, and noticeably
    degrades performance.
3.  It invoked `git config` using a blocking call, instead of using the
    async prompt support in Clink.  That significantly reduced the
    benefit of having used async prompt filtering for `git status`.

Now the `git config` invocations use async prompt filtering, which lets
the prompt display instantaneously.  It also now uses a timer to avoid
invoking `git config` repeatedly when new prompts show up in rapid
succession.

Also, the `cmderGitStatusOptIn` variable is no longer leaked into the
Lua global namespace.

These changes resolve the issue: holding ^C is very fast and no longer
causes git.exe to hang.
2022-12-05 13:52:14 -08:00
David Refoua
048692b5b5 describe color codes in order 2022-11-06 11:50:22 +03:30
David Refoua
7c309c6a7b add link to documentation in comment 2022-11-06 11:36:03 +03:30
David Refoua
96ca7cea4a enhance cmder prompt 2022-10-24 19:58:46 +03:30
David Refoua
5b46f4fec7
use default bg color instead of black for default configuration 2022-10-16 01:20:06 +03:30
David Refoua
abbab3f8b4 trim trailing spaces 2022-10-15 12:46:13 +03:30
David Refoua
a617397aea
move space from "{git}{hg}{svn}" to individual parts 2022-08-30 21:59:09 +04:30
Michael Roy
70b5822fd5
Enable asynchronous clink prompt update for svn status
If enabled in the cmder prompt config, use clink asynchronous update of the prompt for svn status (similar to git)
2022-05-25 15:34:22 +02:00
dgames
6189f4f0e6 fix prompt branch for git worktree 2022-03-17 07:57:48 -04:00
Dax T Games
0616ff0a82
Merge pull request #2660 from vsajip/fix-2659
Fix #2659: Use get_hg_branch() to get Mercurial branch information.
2022-02-03 17:48:26 -05:00
Edouard Coissy
4098265a36 Fix #2654: blank space added between {cwd} and version_control variable 2022-02-02 14:13:51 +01:00
Vinay Sajip
eab4454ac5 Fix #2659: Use get_hg_branch() to get Mercurial branch information. 2022-01-29 14:48:58 +00:00
Dax T Games
ad6979d25f
Merge pull request #2621 from chehrlic/clink_git_speedup
Speed up git status / conflict status by calling git only once.
2021-11-10 05:55:04 -05:00
Christian Ehrlicher
addcefdd47 Speed up git status / conflict status by calling git only once. 2021-11-08 17:43:46 +01:00
Abhishek Aryan
9de284123c
Fix the env not showing
Turns out the `{env}` part was missing from the prompt constructor
2021-09-25 16:32:52 +03:00
Chris Antos
e7a6e64473 Rewrote how prompt_overrideGitStatusOptIn works.
It was less clear before, and it also accidentally took effect when
the `prompt.async` Clink setting was off.
2021-06-12 18:56:37 -07:00
Chris Antos
f6c2657b23 Allow scripts to disable part of the Cmder prompt.
The Cmder prompt normally includes version control info, which involves
running some potentially expensive commands.  The cmder-powerline-prompt
project (and maybe other projects) replaces the Cmder prompt and runs
the same potentially expensive commands -- so expensive commands get run
twice!

This change makes it possible for the user and/or other scripts to
disable the version control part of the built-in Cmder prompt.

https://github.com/chrisant996/cmder-powerline-prompt
2021-06-11 01:01:35 -07:00
Chris Antos
91aabe75af Add prompt config variable for async git prompt.
Setting `prompt_overrideGitStatusOptIn = true` will override the
`cmder.status` and `cmder.cmdstatus` git config settings and run the git
prompt status commands in the background.  But it only takes effect when
using Clink v1.2.10, since that's required in order to run prompt update
commands in the background.
2021-06-10 18:49:39 -07:00
Chris Antos
5305ebd4a6 Use Clink async prompt filtering for git.
`git status` and `git diff` can be slow in large repos.  Clink v1.2.10
and higher support using Lua coroutines to do expensive parts of prompt
filtering in the background.  When the expensive parts complete, the
prompt gets refreshed.

This means even large repos can have fast prompts PLUS git status all
the time!

This change should be backward/forward compatible with both older and
newer versions of Clink (of course only newer versions will gain the
benefit).
2021-05-31 21:29:19 -07:00
dgames
56b04fc9ce fix unknown color and code dedup 2021-05-31 10:53:18 -04:00
dgames
aebe37bd28 fix default unknown color 2021-05-30 08:56:05 -04:00
dgames
a41fad80d5 Merge branch 'status-branchonly' into status-branchonly-dax 2021-05-30 07:56:01 -04:00
dgames
c9acb13d0b Fix cmder no status prompt 2021-05-30 07:50:48 -04:00
dgames
03d0f913ea fixing branch only 2021-05-30 07:27:16 -04:00
Ian Craig
9df8f1a92a Revert to boolean, keep branch name when status=false 2021-05-25 17:53:41 -07:00
Ian Craig
c262934822 Add branchonly option to cmdstatus 2021-05-20 17:53:05 -07:00
Abhishek Aryan
f1665ddd7d
Fix no env in the prompt string
Yeah, I was surprised too..
2021-05-10 18:47:17 +03:00
Dax T. Games
6d79ed5eb2 Merge branch 'master' of https://github.com/cmderdev/cmder into fix_configurable_prompt 2021-05-02 21:04:23 -04:00
Dax T. Games
11fb1b3a50 do not rely on config\cmder_prompt_config.lua 2021-05-02 20:56:02 -04:00
Abhishek Aryan
e8df3ef247
Refactor the env substution logic
And some prompt cleanup
2021-05-02 21:53:22 +03:00
Dax T. Games
e0cb86d738 parametrized status colors 2021-04-11 18:42:43 -04:00
Dax T. Games
0ef76ee2d3 add configurable prompt 2021-04-11 18:28:43 -04:00
Dax T. Games
6027ac31c4 set global cmderGitStatusOptIn var for use in clink-completions 2021-04-07 22:30:53 -04:00
dgames
0fd2d9c8a8 CHANGELOG.md 2021-03-25 19:14:18 -04:00
Michael Roy
1071221468
Fix an issue with clink.find_files() return order not always consistent, leading to .init.lua not being run first lua path being broken (#2278) 2020-03-14 13:01:06 +00:00
Dax T. Games
0cf1c5e2eb fix 2019-11-23 18:13:03 -05:00
Dax T. Games
2428e8529f dd per shell git opt out 2019-11-23 11:54:53 -05:00
Dax T. Games
44a8bf5802 add ability to disable git 2019-11-03 11:00:27 -05:00
Dax T. Games
3a44bc809d add ~ match to vendor/clink.lua/ 2019-09-27 18:17:24 -04:00
Joshua Webb
52eea5fe9f Close file handles in clink.lua 2019-04-19 16:16:45 +10:00
b0bh00d
89499f2a60 Replaced the 'hg -id' command with the 'hg branch' and 'hg status' pair for improved response times. 2019-01-20 21:02:31 -07:00
b0bh00d
5a48e568a8 Updated the HG prompt code to use the '-ib' option to 'hg id' to always have the branch name available. 2019-01-01 11:17:53 -07:00
Martin Böhm
51e75d4bb5 add percent escaping for string.gsub (#1991)
In `string.gsub()`, the `%` character has special meaning and must be escaped to be treated verbatim, otherwise the "invalid use of '%' in replacement string" warning will show up.

This adds a verbatim() function for that purpose. It fixes this warning for situations where `'%` characters are in the current path (cwd), version control branch names, or in the previous `PROMPT` set by the user.
2018-12-19 21:17:45 +01:00
Dax T. Games
749ce17dbe git prompt yellow 2018-09-16 15:53:49 -05:00
Dax T. Games
1d36ba4ed4 fix user lua and git detection 2018-09-16 10:18:10 -05:00