diff options
author | Matan Kushner <hello@matchai.me> | 2019-07-23 11:49:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 11:49:14 -0400 |
commit | 0fe00ecd828c72b9bbc55d8bbf2e69d4649b1eec (patch) | |
tree | d0315a103f95de859cdcefd67bb4b2be63bec2a6 | |
parent | 0f1b71189a03133e9fff3c6bcd3d72ffff397dc6 (diff) |
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.
-rw-r--r-- | src/init.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/init.rs b/src/init.rs index 4a237ac88..5db23c2b4 100644 --- a/src/init.rs +++ b/src/init.rs @@ -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 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") => { - let script = "PS1=\"$(starship prompt --status=$?)\""; + let script = " + PROMPT_COMMAND=starship_prompt + + starship_prompt() { + PS1=\"$(starship prompt --status=$?)\" + }"; Some(script) } + // `precmd` executes a command before the zsh prompt is displayed. Some("zsh") => { - let script = "PROMPT=\"$(starship prompt --status=$?)\""; + let script = " + precmd() { + PROMPT=\"$(starship prompt --status=$?)\" + }"; Some(script) } Some("fish") => { |