mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-29 04:00:42 +00:00
POSIX compliance, shellcheck
This commit is contained in:
parent
d843e90462
commit
826cef4e6e
5 changed files with 114 additions and 96 deletions
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env zsh
|
||||
# shellcheck disable=SC2155
|
||||
|
||||
# Configuration variables:
|
||||
|
||||
|
@ -75,7 +76,7 @@ working_directory() {
|
|||
|
||||
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
|
||||
echo -n " $BLUE$~"
|
||||
elif [ $TERM = "linux" ]; then
|
||||
elif [ "$TERM" = "linux" ]; then
|
||||
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
|
||||
else
|
||||
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
|
||||
|
@ -96,7 +97,7 @@ exec_time_preexec_hook() {
|
|||
exec_time_precmd_hook() {
|
||||
[[ $SHOW_CMD_TIME == 0 ]] && return
|
||||
[[ -z $PROMPT_EXEC_TIME_START ]] && return
|
||||
local PROMPT_EXEC_TIME_STOP=$(date +%s.%N)
|
||||
local PROMPT_EXEC_TIME_STOP="$(date +%s.%N)"
|
||||
PROMPT_EXEC_TIME_DURATION=$(echo "($PROMPT_EXEC_TIME_STOP - $PROMPT_EXEC_TIME_START) * 1000" | bc -l)
|
||||
unset PROMPT_EXEC_TIME_START
|
||||
}
|
||||
|
@ -104,24 +105,24 @@ format_time() {
|
|||
# Do some formatting to get nice time (e.g. 2m 12s) from miliseconds
|
||||
# $1 is the milisecond amount (int or float)
|
||||
# $2 is the precision (ms/s/m/h/d)
|
||||
local T=$1
|
||||
local D=$(echo "scale=0;$T/1000/60/60/24" | bc -l)
|
||||
local H=$(echo "scale=0;$T/1000/60/60%24" | bc -l)
|
||||
local M=$(echo "scale=0;$T/1000/60%60" | bc -l)
|
||||
local S=$(echo "scale=0;$T/1000%60" | bc -l)
|
||||
local MS=$(echo "scale=0;$T%1000" | bc -l)
|
||||
local T="$1"
|
||||
local D="$(echo "scale=0;$T/1000/60/60/24" | bc -l)"
|
||||
local H="$(echo "scale=0;$T/1000/60/60%24" | bc -l)"
|
||||
local M="$(echo "scale=0;$T/1000/60%60" | bc -l)"
|
||||
local S="$(echo "scale=0;$T/1000%60" | bc -l)"
|
||||
local MS="$(echo "scale=0;$T%1000" | bc -l)"
|
||||
|
||||
local precision=$2
|
||||
local out=""
|
||||
case "$precision" in
|
||||
"ms") [[ $MS > 0 ]] && out="$(printf "%dms" $MS) ${out}"; precision="s" ;&
|
||||
"s") [[ $S > 0 ]] && out="$(printf "%ds" $S) ${out}"; precision="m" ;&
|
||||
"m") [[ $M > 0 ]] && out="$(printf "%dm" $M) ${out}"; precision="h" ;&
|
||||
"h") [[ $H > 0 ]] && out="$(printf "%dh" $H) ${out}"; precision="d" ;&
|
||||
"d") [[ $D > 0 ]] && out="$(printf "%dd" $D) ${out}" ;;
|
||||
"ms") [[ "$MS" -gt 0 ]] && out="$(printf "%dms" "$MS") ${out}"; precision="s" ;&
|
||||
"s") [[ "$S" -gt 0 ]] && out="$(printf "%ds" "$S") ${out}"; precision="m" ;&
|
||||
"m") [[ "$M" -gt 0 ]] && out="$(printf "%dm" "$M") ${out}"; precision="h" ;&
|
||||
"h") [[ "$H" -gt 0 ]] && out="$(printf "%dh" "$H") ${out}"; precision="d" ;&
|
||||
"d") [[ "$D" -gt 0 ]] && out="$(printf "%dd" "$D") ${out}" ;;
|
||||
*) out="$T" ;; # Return $1 ($T) if precision wasn't specified/valid
|
||||
esac
|
||||
printf "$out"
|
||||
printf "%s" "$out"
|
||||
}
|
||||
display_cmd_time() {
|
||||
[[ $CMD_TIME_SHOW == 0 ]] && return
|
||||
|
@ -134,7 +135,7 @@ display_cmd_time() {
|
|||
# this happens when all fields (seconds/minutes/...) are 0,
|
||||
# if we use milisecond precision, this will likely never happen
|
||||
# but with other precisions, it could
|
||||
[[ "$(expr length "$time_took")" == 0 ]] && return
|
||||
[ ${#time_took} -eq 0 ] && return
|
||||
echo -n " ${LBLUE}took ${time_took}"
|
||||
}
|
||||
|
||||
|
@ -158,7 +159,7 @@ PS2="$RED\ $RESET"
|
|||
|
||||
# Right side prompt
|
||||
RPS1=""
|
||||
if [ $TERM = "linux" ]; then
|
||||
if [ "$TERM" = "linux" ]; then
|
||||
# Displaying cmd time here works, but often causes issues when we
|
||||
# resize the terminal, since right prompts can be annoying to deal
|
||||
# with when resizing. This would run relatively often so it makes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue