mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-16 03:32:25 +00:00
fix: handle variable bash $SHLVL behavior with explicit option (#4912)
* Accept shlvl as --shlvl option * For bash only, pass --shlvl explicitly * fmt * Apply suggestion Co-authored-by: David Knaack <davidkna@users.noreply.github.com> * Apply suggestion Co-authored-by: David Knaack <davidkna@users.noreply.github.com> * parse_jobs -> parse_i64 --------- Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
parent
9b6d394e01
commit
7ead2b55eb
@ -868,8 +868,11 @@ pub struct Properties {
|
|||||||
#[clap(short = 'k', long, default_value = "viins")]
|
#[clap(short = 'k', long, default_value = "viins")]
|
||||||
pub keymap: String,
|
pub keymap: String,
|
||||||
/// The number of currently running jobs
|
/// The number of currently running jobs
|
||||||
#[clap(short, long, default_value_t, value_parser=parse_jobs)]
|
#[clap(short, long, default_value_t, value_parser=parse_i64)]
|
||||||
pub jobs: i64,
|
pub jobs: i64,
|
||||||
|
/// The current value of SHLVL, for shells that mis-handle it in $()
|
||||||
|
#[clap(long, value_parser=parse_i64)]
|
||||||
|
pub shlvl: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Properties {
|
impl Default for Properties {
|
||||||
@ -883,6 +886,7 @@ impl Default for Properties {
|
|||||||
cmd_duration: None,
|
cmd_duration: None,
|
||||||
keymap: "viins".to_string(),
|
keymap: "viins".to_string(),
|
||||||
jobs: 0,
|
jobs: 0,
|
||||||
|
shlvl: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -896,8 +900,8 @@ fn parse_trim<F: FromStr>(value: &str) -> Option<Result<F, F::Err>> {
|
|||||||
Some(F::from_str(value))
|
Some(F::from_str(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_jobs(jobs: &str) -> Result<i64, ParseIntError> {
|
fn parse_i64(value: &str) -> Result<i64, ParseIntError> {
|
||||||
parse_trim(jobs).unwrap_or(Ok(0))
|
parse_trim(value).unwrap_or(Ok(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_width() -> usize {
|
fn default_width() -> usize {
|
||||||
|
@ -69,7 +69,7 @@ starship_precmd() {
|
|||||||
eval "$STARSHIP_PROMPT_COMMAND"
|
eval "$STARSHIP_PROMPT_COMMAND"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a ARGS=(--terminal-width="${COLUMNS}" --status="${STARSHIP_CMD_STATUS}" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="${NUM_JOBS}")
|
local -a ARGS=(--terminal-width="${COLUMNS}" --status="${STARSHIP_CMD_STATUS}" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="${NUM_JOBS}" --shlvl="${SHLVL}")
|
||||||
# Prepare the timer data, if needed.
|
# Prepare the timer data, if needed.
|
||||||
if [[ -n "${STARSHIP_START_TIME-}" ]]; then
|
if [[ -n "${STARSHIP_START_TIME-}" ]]; then
|
||||||
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
||||||
|
@ -9,7 +9,10 @@ use std::convert::TryInto;
|
|||||||
const SHLVL_ENV_VAR: &str = "SHLVL";
|
const SHLVL_ENV_VAR: &str = "SHLVL";
|
||||||
|
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
let shlvl = context.get_env(SHLVL_ENV_VAR)?.parse::<i64>().ok()?;
|
let props = &context.properties;
|
||||||
|
let shlvl = props
|
||||||
|
.shlvl
|
||||||
|
.or_else(|| context.get_env(SHLVL_ENV_VAR)?.parse::<i64>().ok())?;
|
||||||
|
|
||||||
let mut module = context.new_module("shlvl");
|
let mut module = context.new_module("shlvl");
|
||||||
let config: ShLvlConfig = ShLvlConfig::try_load(module.config);
|
let config: ShLvlConfig = ShLvlConfig::try_load(module.config);
|
||||||
|
Loading…
Reference in New Issue
Block a user