From cf87ce5f50dcdfd53fa596c0bf87a9c3f89a853b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Vladovi=C4=87?= Date: Thu, 28 May 2020 18:21:36 +0200 Subject: [PATCH] style(init): tidy-up init scripts (#1269) * style: fix indent & spacing * chore: use consistent function definition style * chore: remove extra semicolon * chore: flip comparison expression --- src/init/starship.bash | 16 ++++++++-------- src/init/starship.zsh | 11 +++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/init/starship.bash b/src/init/starship.bash index f1ce551e3..426063dea 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -22,7 +22,7 @@ starship_preexec() { PREEXEC_READY=false STARSHIP_START_TIME=$(::STARSHIP:: time) fi - + : "$PREV_LAST_ARG" } @@ -43,7 +43,7 @@ starship_precmd() { else PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$(jobs -p | wc -l)")" fi - PREEXEC_READY=true; # Signal that we can safely restart the timer + PREEXEC_READY=true # Signal that we can safely restart the timer } # If the user appears to be using https://github.com/rcaloras/bash-preexec, @@ -52,20 +52,20 @@ if [[ $preexec_functions ]]; then preexec_functions+=('starship_preexec "$_"') precmd_functions+=(starship_precmd) else -# We want to avoid destroying an existing DEBUG hook. If we detect one, create -# a new function that runs both the existing function AND our function, then -# re-trap DEBUG to use this new function. This prevents a trap clobber. + # We want to avoid destroying an existing DEBUG hook. If we detect one, create + # a new function that runs both the existing function AND our function, then + # re-trap DEBUG to use this new function. This prevents a trap clobber. dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')" if [[ -z "$dbg_trap" ]]; then trap 'starship_preexec "$_"' DEBUG elif [[ "$dbg_trap" != 'starship_preexec "$_"' && "$dbg_trap" != 'starship_preexec_all "$_"' ]]; then - function starship_preexec_all(){ + starship_preexec_all() { local PREV_LAST_ARG=$1 ; $dbg_trap; starship_preexec; : "$PREV_LAST_ARG"; } trap 'starship_preexec_all "$_"' DEBUG fi - - # Finally, prepare the precmd function and set up the start time. We will avoid to + + # 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" diff --git a/src/init/starship.zsh b/src/init/starship.zsh index c4cdccf89..b327e3c10 100644 --- a/src/init/starship.zsh +++ b/src/init/starship.zsh @@ -16,9 +16,9 @@ starship_precmd() { # Use length of jobstates array as number of jobs. Expansion fails inside # quotes so we set it here and then use the value later on. - NUM_JOBS=$#jobstates + NUM_JOBS=$#jobstates # Compute cmd_duration, if we have a time to consume - if [[ ! -z "${STARSHIP_START_TIME+1}" ]]; then + if [[ -n "${STARSHIP_START_TIME+1}" ]]; then 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")" @@ -27,7 +27,7 @@ starship_precmd() { PROMPT="$(::STARSHIP:: prompt --status=$STATUS --jobs="$NUM_JOBS")" fi } -starship_preexec(){ +starship_preexec() { STARSHIP_START_TIME=$(::STARSHIP:: time) } @@ -47,9 +47,8 @@ if [[ ${preexec_functions[(ie)starship_preexec]} -gt ${#preexec_functions} ]]; t fi # Set up a function to redraw the prompt if the user switches vi modes -function zle-keymap-select -{ - PROMPT=$(::STARSHIP:: prompt --keymap=$KEYMAP --jobs="$(jobs | wc -l)") +zle-keymap-select() { + PROMPT=$(::STARSHIP:: prompt --keymap="$KEYMAP" --jobs="$(jobs | wc -l)") zle reset-prompt }