diff options
author | Luca Rinaldi <lucarin@protonmail.com> | 2019-12-19 14:38:06 -0800 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-12-19 17:38:06 -0500 |
commit | 6a2b0a67b0ad8143f223f7abc6562ac839875b88 (patch) | |
tree | 4d11fe667909296448c95dcd82fe33d917d1abec /src/init | |
parent | d6094d7b9d300462d0a9de21da5d1cdbb07794a4 (diff) |
feat: cmd_duration module optionally reports milliseconds (#696)
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/starship.bash | 17 | ||||
-rw-r--r-- | src/init/starship.fish | 3 | ||||
-rw-r--r-- | src/init/starship.ps1 | 2 | ||||
-rw-r--r-- | src/init/starship.zsh | 6 |
4 files changed, 16 insertions, 12 deletions
diff --git a/src/init/starship.bash b/src/init/starship.bash index cf7b30db6..9b4886177 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -20,7 +20,7 @@ starship_preexec() { # Avoid restarting the timer for commands in the same pipeline if [ "$PREEXEC_READY" = "true" ]; then PREEXEC_READY=false - STARSHIP_START_TIME=$(date +%s) + STARSHIP_START_TIME=$(::STARSHIP:: time) fi : "$PREV_LAST_ARG" @@ -36,7 +36,7 @@ starship_precmd() { # Prepare the timer data, if needed. if [[ $STARSHIP_START_TIME ]]; then - STARSHIP_END_TIME=$(date +%s) + STARSHIP_END_TIME=$(::STARSHIP:: time) STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME)) PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$(jobs -p | wc -l)" --cmd-duration=$STARSHIP_DURATION)" unset STARSHIP_START_TIME @@ -64,11 +64,16 @@ else } trap 'starship_preexec_all "$_"' DEBUG fi - - # Finally, prepare the precmd function and set up the start time. - PROMPT_COMMAND="starship_precmd;$PROMPT_COMMAND" + + # Finally, prepare the precmd function and set up the start time. We will avoid to + # add multiple instances of the starship function and keep other user functions if any. + if [[ -z "$PROMPT_COMMAND" ]]; then + PROMPT_COMMAND="starship_precmd" + elif [[ "$PROMPT_COMMAND" != *"starship_precmd" ]]; then + PROMPT_COMMAND="$PROMPT_COMMAND;starship_precmd" + fi fi # Set up the start time and STARSHIP_SHELL, which controls shell-specific sequences -STARSHIP_START_TIME=$(date +%s) +STARSHIP_START_TIME=$(::STARSHIP:: time) export STARSHIP_SHELL="bash"
\ No newline at end of file diff --git a/src/init/starship.fish b/src/init/starship.fish index e8347108c..6daa473d4 100644 --- a/src/init/starship.fish +++ b/src/init/starship.fish @@ -7,8 +7,7 @@ function fish_prompt end set -l exit_code $status # Account for changes in variable name between v2.7 and v3.0 - set -l CMD_DURATION "$CMD_DURATION$cmd_duration" - set -l starship_duration (math --scale=0 "$CMD_DURATION / 1000") + set -l starship_duration "$CMD_DURATION$cmd_duration" ::STARSHIP:: prompt --status=$exit_code --keymap=$keymap --cmd-duration=$starship_duration --jobs=(count (jobs -p)) end diff --git a/src/init/starship.ps1 b/src/init/starship.ps1 index cab90cee5..0ae42c789 100644 --- a/src/init/starship.ps1 +++ b/src/init/starship.ps1 @@ -8,7 +8,7 @@ function global:prompt { $jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count if ($lastCmd = Get-History -Count 1) { - $duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalSeconds) + $duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds) # & ensures the path is interpreted as something to execute $out = @(&::STARSHIP:: prompt "--path=$PWD" --status=$lastexitcode --jobs=$jobs --cmd-duration=$duration) } else { diff --git a/src/init/starship.zsh b/src/init/starship.zsh index fdae70e12..c4cdccf89 100644 --- a/src/init/starship.zsh +++ b/src/init/starship.zsh @@ -19,7 +19,7 @@ starship_precmd() { NUM_JOBS=$#jobstates # Compute cmd_duration, if we have a time to consume if [[ ! -z "${STARSHIP_START_TIME+1}" ]]; then - STARSHIP_END_TIME="$(date +%s)" + STARSHIP_END_TIME=$(::STARSHIP:: time) STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME)) PROMPT="$(::STARSHIP:: prompt --status=$STATUS --cmd-duration=$STARSHIP_DURATION --jobs="$NUM_JOBS")" unset STARSHIP_START_TIME @@ -28,7 +28,7 @@ starship_precmd() { fi } starship_preexec(){ - STARSHIP_START_TIME="$(date +%s)" + STARSHIP_START_TIME=$(::STARSHIP:: time) } # If precmd/preexec arrays are not already set, set them. If we don't do this, @@ -53,6 +53,6 @@ function zle-keymap-select zle reset-prompt } -STARSHIP_START_TIME="$(date +%s)" +STARSHIP_START_TIME=$(::STARSHIP:: time) zle -N zle-keymap-select export STARSHIP_SHELL="zsh" |