summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRashil Gandhi <rashil2000@gmail.com>2021-12-06 19:40:39 +0530
committerRashil Gandhi <rashil2000@gmail.com>2021-12-06 19:40:39 +0530
commit914057952508e81e20086fcb707ba2a0be85fdd3 (patch)
tree2dc833755397a9118d076d3943e8fbe082f22caf
parentf68e8f118fc7c161bafda580ac5ffd712f8d2aec (diff)
add support for transient_prompt and transient_rprompt
-rw-r--r--docs/advanced-config/README.md40
-rw-r--r--src/init/starship.lua12
2 files changed, 52 insertions, 0 deletions
diff --git a/docs/advanced-config/README.md b/docs/advanced-config/README.md
index c1303290a..53cac63bc 100644
--- a/docs/advanced-config/README.md
+++ b/docs/advanced-config/README.md
@@ -10,6 +10,46 @@ The configurations in this section are subject to change in future releases of S
:::
+## TransientPrompt and TransientRightPrompt in Cmd
+
+Clink allows you to replace the previous-printed prompt with custom strings. This
+is useful in cases where all the prompt information is not always needed. To enable
+this, run `clink set prompt.transient <value>` where \<value\> can be one of:
+- `always`: always replace the previous prompt
+- `same_dir`: replace the previous prompt only if the working directory is same
+- `off`: do not replace the prompt (i.e. turn off transience)
+
+You need to do this only once. Make the following changes to your `starship.lua`
+to customize what gets displayed on the left and on the right:
+
+- By default, the left side of input gets replaced with `>`. To customize this,
+ define a new function called `starship_transient_prompt_func`. This function
+ receives the current prompt as a string that you can utilize. For example, to
+ display Starship's `character` module here, you would do
+
+```lua
+function starship_transient_prompt_func(prompt)
+ return io.popen("starship module character"
+ .." --keymap="..rl.getvariable('keymap')
+ ):read("*a")
+end
+
+load(io.popen('starship init cmd'):read("*a"))()
+```
+
+- By default, the right side of input is empty. To customize this, define a new
+ function called `starship_transient_rprompt_func`. This function receives the
+ current prompt as a string that you can utilize. For example, to display
+ the time at which the last command was started here, you would do
+
+```lua
+function starship_transient_rprompt_func(prompt)
+ return io.popen("starship module time"):read("*a")
+end
+
+load(io.popen('starship init cmd'):read("*a"))()
+```
+
## Custom pre-prompt and pre-execution Commands in Cmd
Clink provides extremely flexible APIs to run pre-prompt and pre-exec commands
diff --git a/src/init/starship.lua b/src/init/starship.lua
index accbc976a..229962982 100644
--- a/src/init/starship.lua
+++ b/src/init/starship.lua
@@ -49,6 +49,18 @@ function starship_prompt:rightfilter(prompt)
):read("*a")
end
+if starship_transient_prompt_func ~= nil then
+ function starship_prompt:transientfilter(prompt)
+ return starship_transient_prompt_func(prompt)
+ end
+end
+
+if starship_transient_rprompt_func ~= nil then
+ function starship_prompt:transientrightfilter(prompt)
+ return starship_transient_rprompt_func(prompt)
+ end
+end
+
local characterset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
local randomkey = ""
math.randomseed(os.time())