mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
fix: Fix issue with jobs and extra whitespace on MacOS with BSD… (#145)
MacOS wc has a habit of leaving nasty spaces in the output, which was messing up our argparser. To fix, quote the output from the jobs command, then have Rust trim out whitespace in the jobs module before parsing.
This commit is contained in:
parent
1d6ce77a81
commit
a87c0750cc
11
src/init.rs
11
src/init.rs
@ -54,11 +54,16 @@ pub fn init(shell_name: &str) {
|
|||||||
|
|
||||||
/* Bash does not currently support command durations (see issue #124) for details
|
/* Bash does not currently support command durations (see issue #124) for details
|
||||||
https://github.com/starship/starship/issues/124
|
https://github.com/starship/starship/issues/124
|
||||||
|
|
||||||
|
We need to quote the output of `$(jobs -p | wc -l)` since MacOS `wc` leaves
|
||||||
|
giant spaces in front of the number (e.g. " 3"), which messes up the
|
||||||
|
word-splitting. Instead, quote the whole thing, then let Rust do the whitespace
|
||||||
|
trimming within the jobs module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BASH_INIT: &str = r##"
|
const BASH_INIT: &str = r##"
|
||||||
starship_precmd() {
|
starship_precmd() {
|
||||||
PS1="$(starship prompt --status=$? --jobs=$(jobs -p | wc -l))";
|
PS1="$(starship prompt --status=$? --jobs="$(jobs -p | wc -l)")";
|
||||||
};
|
};
|
||||||
PROMPT_COMMAND=starship_precmd;
|
PROMPT_COMMAND=starship_precmd;
|
||||||
"##;
|
"##;
|
||||||
@ -83,10 +88,10 @@ starship_precmd() {
|
|||||||
if [[ $STARSHIP_START_TIME ]]; then
|
if [[ $STARSHIP_START_TIME ]]; then
|
||||||
STARSHIP_END_TIME="$(date +%s)";
|
STARSHIP_END_TIME="$(date +%s)";
|
||||||
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME));
|
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME));
|
||||||
PROMPT="$(starship prompt --status=$STATUS --cmd-duration=$STARSHIP_DURATION --jobs=$(jobs | wc -l))";
|
PROMPT="$(starship prompt --status=$STATUS --cmd-duration=$STARSHIP_DURATION --jobs="$(jobs | wc -l)")";
|
||||||
unset STARSHIP_START_TIME;
|
unset STARSHIP_START_TIME;
|
||||||
else
|
else
|
||||||
PROMPT="$(starship prompt --status=$STATUS --jobs=$(jobs | wc -l))";
|
PROMPT="$(starship prompt --status=$STATUS --jobs="$(jobs | wc -l)")";
|
||||||
fi
|
fi
|
||||||
};
|
};
|
||||||
starship_preexec(){
|
starship_preexec(){
|
||||||
|
@ -17,6 +17,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
let num_of_jobs = arguments
|
let num_of_jobs = arguments
|
||||||
.value_of("jobs")
|
.value_of("jobs")
|
||||||
.unwrap_or("0")
|
.unwrap_or("0")
|
||||||
|
.trim()
|
||||||
.parse::<i64>()
|
.parse::<i64>()
|
||||||
.ok()?;
|
.ok()?;
|
||||||
if num_of_jobs == 0 {
|
if num_of_jobs == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user