Add days and years to prompt, fix unchecked math error

This commit is contained in:
The Cobra 2022-03-01 23:05:19 -05:00
parent 1a94266776
commit d1b02ed2d2
1 changed files with 10 additions and 5 deletions

15
.prompt
View File

@ -15,15 +15,19 @@ trap '__debug_trap' DEBUG
__get_cmd_time() {
# Set hours minutes seconds and remove preceding zeros
local YEAR=$(($((10#$(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970))
local DAYS=$((10#$(TZ=UTC printf '%(%j)T' $CMD_TIME)))
local HOUR=$((10#$(TZ=UTC printf '%(%H)T' $CMD_TIME)))
local MINS=$((10#$(TZ=UTC printf '%(%M)T' $CMD_TIME)))
local SECS=$((10#$(TZ=UTC printf '%(%S)T' $CMD_TIME))) #wtf sex???
# Choose whether or not to print hours minutes and seconds
[ $CMD_TIME -ge 3600 ] && TZ=UTC printf '%sh ' ${HOUR:-0}
[ $CMD_TIME -ge 60 ] && TZ=UTC printf '%sm ' ${MINS:-0}
[ $CMD_TIME -ge 1 ] && TZ=UTC printf '%ss ' ${SECS:-0}
TZ=UTC printf '%sμs ' ${CMD_US:-0}
[ $CMD_TIME -ge 31536000 ] && TZ=UTC printf '%sd ' ${YEAR:-0}
[ $CMD_TIME -ge 86400 ] && TZ=UTC printf '%sd ' ${DAYS:-0}
[ $CMD_TIME -ge 3600 ] && TZ=UTC printf '%sh ' ${HOUR:-0}
[ $CMD_TIME -ge 60 ] && TZ=UTC printf '%sm ' ${MINS:-0}
[ $CMD_TIME -ge 1 ] && TZ=UTC printf '%ss ' ${SECS:-0}
TZ=UTC printf '%sμs ' ${CMD_US:-0}
}
__sig() {
@ -79,7 +83,8 @@ __prompt() {
# Get relative times
CMD_TIME="$((PROMPT_EPOCH-LAST_EPOCH))"
CMD_US="$((1${PROMPT_REALTIME: -6}-$((10#${LAST_REALTIME: -6}))))"
local LAST_US="$((10#${LAST_REALTIME: -6}))"
CMD_US="$((1${PROMPT_REALTIME: -6}-${LAST_US:-0}))"
CMD_US="$((10#${CMD_US: -6}))"
# Set the prompt