Update prompt

Signed-off-by: Aleksandar 'The Cobra' Widulski <thecobra@riseup.net>
This commit is contained in:
Aleksandar 'The Cobra' Widulski 2022-03-06 22:12:14 -05:00
parent 0b48a81b2a
commit 1bf51a1f8e
1 changed files with 11 additions and 16 deletions

27
.prompt
View File

@ -4,11 +4,10 @@
__debug_trap() { __debug_trap() {
# Set necessary pre-command variables (PROMPT_COMMAND is a # Set necessary pre-command variables (PROMPT_COMMAND is a
# command so its excluded here) # command so its excluded here)
if [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]]; then if [[ "$BASH_COMMAND" != "$PROMPT_COMMAND"
if [[ "$LAST_BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then && "$LAST_BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then
LAST_RT="$EPOCHREALTIME" LAST_RT="$EPOCHREALTIME"
INC_TIME=1 INC_TIME=1
fi
fi fi
LAST_BASH_COMMAND="$BASH_COMMAND" LAST_BASH_COMMAND="$BASH_COMMAND"
} }
@ -18,10 +17,10 @@ trap '__debug_trap' DEBUG
__get_cmd_time() { __get_cmd_time() {
# Set hours minutes seconds and remove preceding zeros # Set hours minutes seconds and remove preceding zeros
local YEAR=$((10#0$(($(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970)) local YEAR=$((10#0$(($(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970))
local DAYS=$((10#$(TZ=UTC printf '%(%j)T' $CMD_TIME))) local DAYS=$((10#0$(TZ=UTC printf '%(%j)T' $CMD_TIME)))
local HOUR=$((10#$(TZ=UTC printf '%(%H)T' $CMD_TIME))) local HOUR=$((10#0$(TZ=UTC printf '%(%H)T' $CMD_TIME)))
local MINS=$((10#$(TZ=UTC printf '%(%M)T' $CMD_TIME))) local MINS=$((10#0$(TZ=UTC printf '%(%M)T' $CMD_TIME)))
local SECS=$((10#$(TZ=UTC printf '%(%S)T' $CMD_TIME))) local SECS=$((10#0$(TZ=UTC printf '%(%S)T' $CMD_TIME)))
# Choose whether or not to print hours minutes and seconds # Choose whether or not to print hours minutes and seconds
[[ $CMD_TIME -ge 31536000 ]] && printf '%sy ' ${YEAR:-0} [[ $CMD_TIME -ge 31536000 ]] && printf '%sy ' ${YEAR:-0}
@ -103,24 +102,20 @@ __prompt() {
# Get relative times # Get relative times
# Remove decimal point, simulating multiplying by 1 million
local PROMPT_RT1M="${PROMPT_RT%.*}${PROMPT_RT#*.}"
local LAST_RT1M="${LAST_RT%.*}${LAST_RT#*.}"
# Subtract and divide by 1 million to get a more accurate difference # Subtract and divide by 1 million to get a more accurate difference
CMD_TIME="$(((PROMPT_RT1M-LAST_RT1M)/1000000))" CMD_TIME="$(((PROMPT_RT1M-LAST_RT1M)/1000000))"
CMD_TIME="${CMD_TIME:-0}" CMD_TIME="${CMD_TIME:-0}"
local LAST_US="$((10#${LAST_RT: -6}))" local LAST_US="$((10#0${LAST_RT: -6}))"
local LAST_US="${LAST_US:-0}" local LAST_US="${LAST_US:-0}"
local PROMPT_US="${PROMPT_RT: -6}" local PROMPT_US="${PROMPT_RT: -6}"
local PROMPT_US_CLN="$((10#$PROMPT_US))" local PROMPT_US_CLN="$((10#0$PROMPT_US))"
local PROMPT_US_CLN="${PROMPT_US_CLN:-0}" local PROMPT_US_CLN="${PROMPT_US_CLN:-0}"
[[ $PROMPT_US_CLN < $LAST_US ]] && [[ $PROMPT_US_CLN < $LAST_US ]] &&
CMD_US="$((1$PROMPT_US-$LAST_US))" || CMD_US="$((1$PROMPT_US-$LAST_US))" ||
CMD_US="$(($PROMPT_US_CLN-$LAST_US))" CMD_US="$(($PROMPT_US_CLN-$LAST_US))"
CMD_US="$((10#$CMD_US))" CMD_US="$((10#0$CMD_US))"
# Set prompt sections # Set prompt sections