From eff714d784a73c00644fe40702b86340356a952a Mon Sep 17 00:00:00 2001 From: oblivikun Date: Tue, 13 Aug 2024 01:38:06 -0400 Subject: [PATCH] stuff --- src/init/mod.rs | 9 ++++++++- src/init/starship.mksh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/init/starship.mksh diff --git a/src/init/mod.rs b/src/init/mod.rs index a6639546d..228407439 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -174,6 +174,11 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { r#"eval `({} init tcsh --print-full-init)`"#, starship.sprint_posix()? ), + "mksh" => print!( + r#"eval "$({} init mksh --print-full-init)""#, + starship.sprint_posix()? + ), + "nu" => print_script(NU_INIT, &StarshipPath::init()?.sprint()?), "xonsh" => print!( r#"execx($({} init xonsh --print-full-init))"#, @@ -194,6 +199,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { * nu\n\ * xonsh\n\ * cmd\n\ + * mksh\n\ \n\ Please open an issue in the starship repo if you would like to \ see support for {shell_basename}:\n\ @@ -211,6 +217,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> { match shell_name { "bash" => print_script(BASH_INIT, &starship_path.sprint_posix()?), + "mksh" => print_script(MKSH_INIT, &starship_path.sprint_posix()?), "zsh" => print_script(ZSH_INIT, &starship_path.sprint_posix()?), "fish" => print_script(FISH_INIT, &starship_path.sprint_posix()?), "powershell" => print_script(PWSH_INIT, &starship_path.sprint_pwsh()?), @@ -250,7 +257,7 @@ starship binary. */ const BASH_INIT: &str = include_str!("starship.bash"); - +const MKSH_INIT: &str = include_str!("starship.mksh"); const ZSH_INIT: &str = include_str!("starship.zsh"); const FISH_INIT: &str = include_str!("starship.fish"); diff --git a/src/init/starship.mksh b/src/init/starship.mksh new file mode 100644 index 000000000..1f5fb4a4b --- /dev/null +++ b/src/init/starship.mksh @@ -0,0 +1,39 @@ + +# Define a function to capture time in milliseconds +__starship_get_time() { + STARSHIP_CAPTURED_TIME=$(date +%s%3N) # Using date command for compatibility +} + +# Function to calculate command duration and manage prompt variables +prompt_starship_precmd() { + STARSHIP_CMD_STATUS=$? # Save last command status + + # Calculate duration if STARSHIP_START_TIME is set + if [ -n "$STARSHIP_START_TIME" ]; then + __starship_get_time + STARSHIP_DURATION=$((STARSHIP_CAPTURED_TIME - STARSHIP_START_TIME)) + unset STARSHIP_START_TIME + else + unset STARSHIP_DURATION STARSHIP_CMD_STATUS + fi + + # MKSH does not support jobstates array directly, simplifying jobs count + STARSHIP_JOBS_COUNT=$(jobs | wc -l) +} + +# Function to set start time before executing a command +prompt_starship_preexec() { + __starship_get_time && STARSHIP_START_TIME=$STARSHIP_CAPTURED_TIME +} + +# Setup prompt + PS1='$(::STARSHIP:: prompt --terminal-width="$COLUMNS" --status="$STARSHIP_CMD_STATUS" --cmd-duration="${STARSHIP_DURATION:-}") ' + +# Export necessary variables +export STARSHIP_SHELL="mksh" + +# Simplified session key generation +STARSHIP_SESSION_KEY=$(od -vAn -N4 -tu4 < /dev/urandom); export STARSHIP_SESSION_KEY=${STARSHIP_SESSION_KEY:0:16}; + +VIRTUAL_ENV_DISABLE_PROMPT=1 +