From 914057952508e81e20086fcb707ba2a0be85fdd3 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi Date: Mon, 6 Dec 2021 19:40:39 +0530 Subject: [PATCH] add support for transient_prompt and transient_rprompt --- docs/advanced-config/README.md | 40 ++++++++++++++++++++++++++++++++++ src/init/starship.lua | 12 ++++++++++ 2 files changed, 52 insertions(+) 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 ` where \ 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())