1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-24 21:57:41 +00:00

fix: prompt now updates on bash and zsh (#109)

Making use of PROMPT_COMMAND in bash and precmd in zsh, the prompt is no longer being expanded and rendered when the variable is initially set.
This commit is contained in:
Matan Kushner 2019-07-23 11:49:14 -04:00 committed by GitHub
parent 0f1b71189a
commit 0fe00ecd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,12 +7,23 @@ pub fn init(shell_name: &str) {
let shell_basename = Path::new(shell_name).file_stem().and_then(OsStr::to_str); let shell_basename = Path::new(shell_name).file_stem().and_then(OsStr::to_str);
let setup_script = match shell_basename { let setup_script = match shell_basename {
// The contents of `PROMPT_COMMAND` are executed as a regular Bash command
// just before Bash displays a prompt.
Some("bash") => { Some("bash") => {
let script = "PS1=\"$(starship prompt --status=$?)\""; let script = "
PROMPT_COMMAND=starship_prompt
starship_prompt() {
PS1=\"$(starship prompt --status=$?)\"
}";
Some(script) Some(script)
} }
// `precmd` executes a command before the zsh prompt is displayed.
Some("zsh") => { Some("zsh") => {
let script = "PROMPT=\"$(starship prompt --status=$?)\""; let script = "
precmd() {
PROMPT=\"$(starship prompt --status=$?)\"
}";
Some(script) Some(script)
} }
Some("fish") => { Some("fish") => {