commit 095f21d71bc5990fabbaab82848d477a53e4cdc9
parent a389a2f3dbee8f5e11fb9d6d28e691dda54e448a
Author: Alex Balgavy <alex@balgavy.eu>
Date: Sun, 31 Jan 2021 11:42:58 +0100
p10k: add bitwarden session expiration indicator
Diffstat:
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/shell/p10k-dark.zsh b/shell/p10k-dark.zsh
@@ -49,6 +49,7 @@
# automatically hidden when the input line reaches it. Right prompt above the
# last prompt line gets hidden if it would overlap with left prompt.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
+ bitwarden_session_timer # how much longer until Bitwarden locks
command_execution_time # duration of the last command
background_jobs # presence of background jobs
# direnv # direnv status (https://direnv.net/)
@@ -1134,6 +1135,26 @@
p10k segment -f 208 -i '⭐' -t 'hello, %n'
}
+ function hms {
+ local T=$1
+ local D=$((T/60/60/24))
+ local H=$((T/60/60%24))
+ local M=$((T/60%60))
+ local S=$((T%60))
+ (( $D > 0 )) && printf '%d:' $D
+ (( $H > 0 )) && printf '%d:' $H
+ (( $M > 0 )) && printf '%d' $M
+ (( $D > 0 || $H > 0 || $M > 0 )) && printf ':'
+ printf '%d' $S
+ }
+ function prompt_bitwarden_session_timer() {
+ if [ -z "$BW_SESHFILE" ] || ! [ -f "$BW_SESHFILE" ]; then
+ return
+ else
+ p10k segment -f 2 -t "[🔓 -$(hms $(($(stat -c '%Y' $BW_SESHFILE)+(30*60)-$(date +%s))))]"
+ fi
+ }
+
# shell nest level
function prompt_nest_level() {
# _my_lvl := $TMUX == "" ? $SHLVL : $((SHLVL-1))
diff --git a/shell/p10k-light.zsh b/shell/p10k-light.zsh
@@ -48,6 +48,7 @@
# automatically hidden when the input line reaches it. Right prompt above the
# last prompt line gets hidden if it would overlap with left prompt.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
+ bitwarden_session_timer # how much longer until Bitwarden locks
command_execution_time # duration of the last command
background_jobs # presence of background jobs
direnv # direnv status (https://direnv.net/)
@@ -1270,6 +1271,26 @@
p10k segment -f 2 -i '⭐' -t 'hello, %n'
}
+ function hms {
+ local T=$1
+ local D=$((T/60/60/24))
+ local H=$((T/60/60%24))
+ local M=$((T/60%60))
+ local S=$((T%60))
+ (( $D > 0 )) && printf '%d:' $D
+ (( $H > 0 )) && printf '%d:' $H
+ (( $M > 0 )) && printf '%d' $M
+ (( $D > 0 || $H > 0 || $M > 0 )) && printf ':'
+ printf '%02d' $S
+ }
+ function prompt_bitwarden_session_timer() {
+ if [ -z "$BW_SESHFILE" ] || ! [ -f "$BW_SESHFILE" ]; then
+ return
+ else
+ p10k segment -f 2 -t "[🔓 -$(hms $(($(stat -c '%Y' $BW_SESHFILE)+(30*60)-$(date +%s))))]"
+ fi
+ }
+
# shell nest level
function prompt_nest_level() {
# _my_lvl := $TMUX == "" ? $SHLVL : $((SHLVL-1))