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
This commit is contained in:
parent
a3470bf9fb
commit
cf87ce5f50
|
@ -22,7 +22,7 @@ starship_preexec() {
|
||||||
PREEXEC_READY=false
|
PREEXEC_READY=false
|
||||||
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
: "$PREV_LAST_ARG"
|
: "$PREV_LAST_ARG"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ starship_precmd() {
|
||||||
else
|
else
|
||||||
PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$(jobs -p | wc -l)")"
|
PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$(jobs -p | wc -l)")"
|
||||||
fi
|
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,
|
# 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 "$_"')
|
preexec_functions+=('starship_preexec "$_"')
|
||||||
precmd_functions+=(starship_precmd)
|
precmd_functions+=(starship_precmd)
|
||||||
else
|
else
|
||||||
# We want to avoid destroying an existing DEBUG hook. If we detect one, create
|
# 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
|
# 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.
|
# re-trap DEBUG to use this new function. This prevents a trap clobber.
|
||||||
dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
|
dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
|
||||||
if [[ -z "$dbg_trap" ]]; then
|
if [[ -z "$dbg_trap" ]]; then
|
||||||
trap 'starship_preexec "$_"' DEBUG
|
trap 'starship_preexec "$_"' DEBUG
|
||||||
elif [[ "$dbg_trap" != 'starship_preexec "$_"' && "$dbg_trap" != 'starship_preexec_all "$_"' ]]; then
|
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";
|
local PREV_LAST_ARG=$1 ; $dbg_trap; starship_preexec; : "$PREV_LAST_ARG";
|
||||||
}
|
}
|
||||||
trap 'starship_preexec_all "$_"' DEBUG
|
trap 'starship_preexec_all "$_"' DEBUG
|
||||||
fi
|
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.
|
# add multiple instances of the starship function and keep other user functions if any.
|
||||||
if [[ -z "$PROMPT_COMMAND" ]]; then
|
if [[ -z "$PROMPT_COMMAND" ]]; then
|
||||||
PROMPT_COMMAND="starship_precmd"
|
PROMPT_COMMAND="starship_precmd"
|
||||||
|
|
|
@ -16,9 +16,9 @@ starship_precmd() {
|
||||||
|
|
||||||
# Use length of jobstates array as number of jobs. Expansion fails inside
|
# 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.
|
# 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
|
# 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_END_TIME=$(::STARSHIP:: time)
|
||||||
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="$NUM_JOBS")"
|
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")"
|
PROMPT="$(::STARSHIP:: prompt --status=$STATUS --jobs="$NUM_JOBS")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
starship_preexec(){
|
starship_preexec() {
|
||||||
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,9 +47,8 @@ if [[ ${preexec_functions[(ie)starship_preexec]} -gt ${#preexec_functions} ]]; t
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set up a function to redraw the prompt if the user switches vi modes
|
# Set up a function to redraw the prompt if the user switches vi modes
|
||||||
function zle-keymap-select
|
zle-keymap-select() {
|
||||||
{
|
PROMPT=$(::STARSHIP:: prompt --keymap="$KEYMAP" --jobs="$(jobs | wc -l)")
|
||||||
PROMPT=$(::STARSHIP:: prompt --keymap=$KEYMAP --jobs="$(jobs | wc -l)")
|
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue