mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +00:00
feat(fish): Enable left and right transience (#4204)
* feat(fish): Enable left and right transience * Update README.md * Mention limitation
This commit is contained in:
parent
fd5539796f
commit
06281c268d
@ -71,6 +71,41 @@ end
|
||||
load(io.popen('starship init cmd'):read("*a"))()
|
||||
```
|
||||
|
||||
## TransientPrompt and TransientRightPrompt in Fish
|
||||
|
||||
It is possible to replace the previous-printed prompt with a custom string. This
|
||||
is useful in cases where all the prompt information is not always needed. To enable
|
||||
this, run `enable_transience` in the shell session. To make it permanent, put
|
||||
this statement in your `~/.config/fish/config.fish`. Transience can be disabled on-the-fly with
|
||||
`disable_transience`.
|
||||
|
||||
Note that in case of Fish, the transient prompt is only printed if the commandline is non-empty,
|
||||
and syntactically correct.
|
||||
|
||||
- By default, the left side of input gets replaced with a bold-green `❯`. To customize this,
|
||||
define a new function called `starship_transient_prompt_func`. For example, to
|
||||
display Starship's `character` module here, you would do
|
||||
|
||||
```fish
|
||||
function starship_transient_prompt_func
|
||||
starship module character
|
||||
end
|
||||
starship init fish | source
|
||||
enable_transience
|
||||
```
|
||||
|
||||
- By default, the right side of input is empty. To customize this, define a new
|
||||
function called `starship_transient_rprompt_func`. For example, to display
|
||||
the time at which the last command was started here, you would do
|
||||
|
||||
```fish
|
||||
function starship_transient_rprompt_func
|
||||
starship module time
|
||||
end
|
||||
starship init fish | source
|
||||
enable_transience
|
||||
```
|
||||
|
||||
## Custom pre-prompt and pre-execution Commands in Cmd
|
||||
|
||||
Clink provides extremely flexible APIs to run pre-prompt and pre-exec commands
|
||||
|
@ -10,8 +10,19 @@ function fish_prompt
|
||||
# Account for changes in variable name between v2.7 and v3.0
|
||||
set STARSHIP_DURATION "$CMD_DURATION$cmd_duration"
|
||||
set STARSHIP_JOBS (count (jobs -p))
|
||||
if test "$TRANSIENT" = "1"
|
||||
# Clear from cursor to end of screen as `commandline -f repaint` does not do this
|
||||
# See https://github.com/fish-shell/fish-shell/issues/8418
|
||||
printf \e\[0J
|
||||
if type -q starship_transient_prompt_func
|
||||
starship_transient_prompt_func
|
||||
else
|
||||
printf "\e[1;32m❯\e[0m "
|
||||
end
|
||||
else
|
||||
::STARSHIP:: prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="$STARSHIP_CMD_PIPESTATUS" --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
||||
end
|
||||
end
|
||||
|
||||
function fish_right_prompt
|
||||
switch "$fish_key_bindings"
|
||||
@ -25,8 +36,16 @@ function fish_right_prompt
|
||||
# Account for changes in variable name between v2.7 and v3.0
|
||||
set STARSHIP_DURATION "$CMD_DURATION$cmd_duration"
|
||||
set STARSHIP_JOBS (count (jobs -p))
|
||||
if test "$TRANSIENT" = "1"
|
||||
if type -q starship_transient_rprompt_func
|
||||
starship_transient_rprompt_func
|
||||
else
|
||||
printf ""
|
||||
end
|
||||
else
|
||||
::STARSHIP:: prompt --right --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="$STARSHIP_CMD_PIPESTATUS" --keymap=$STARSHIP_KEYMAP --cmd-duration=$STARSHIP_DURATION --jobs=$STARSHIP_JOBS
|
||||
end
|
||||
end
|
||||
|
||||
# Disable virtualenv prompt, it breaks starship
|
||||
set -g VIRTUAL_ENV_DISABLE_PROMPT 1
|
||||
@ -36,6 +55,29 @@ builtin functions -e fish_mode_prompt
|
||||
|
||||
set -gx STARSHIP_SHELL "fish"
|
||||
|
||||
# Transience related functions
|
||||
function reset-transient --on-event fish_postexec
|
||||
set -g TRANSIENT 0
|
||||
end
|
||||
|
||||
function transient_execute
|
||||
if commandline --is-valid
|
||||
set -g TRANSIENT 1
|
||||
commandline -f repaint
|
||||
else
|
||||
set -g TRANSIENT 0
|
||||
end
|
||||
commandline -f execute
|
||||
end
|
||||
|
||||
function enable_transience
|
||||
bind \r transient_execute
|
||||
end
|
||||
|
||||
function disable_transience
|
||||
bind \r execute
|
||||
end
|
||||
|
||||
# Set up the session key that will be used to store logs
|
||||
# We don't use `random [min] [max]` because it is unavailable in older versions of fish shell
|
||||
set -gx STARSHIP_SESSION_KEY (string sub -s1 -l16 (random)(random)(random)(random)(random)0000000000000000)
|
||||
|
Loading…
Reference in New Issue
Block a user