add timewarrior prompt segment; see #295

pull/445/head
romkatv 5 years ago
parent a9715367d4
commit bfa70fa86d

@ -85,6 +85,7 @@
# ram # free RAM # ram # free RAM
# swap # used swap # swap # used swap
todo # todo items (https://github.com/todotxt/todo.txt-cli) todo # todo items (https://github.com/todotxt/todo.txt-cli)
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time # time # current time
# =========================[ Line #2 ]========================= # =========================[ Line #2 ]=========================
newline newline
@ -627,6 +628,13 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐'
###########[ timewarrior: timewarrior tracking status (https://timewarrior.net/) ]############
# Timewarrior color.
typeset -g POWERLEVEL9K_TIMEWARRIOR_FOREGROUND=110
# Custom icon.
# typeset -g POWERLEVEL9K_TIMEWARRIOR_VISUAL_IDENTIFIER_EXPANSION='⭐'
##################################[ context: user@hostname ]################################## ##################################[ context: user@hostname ]##################################
# Context color when running with privileges. # Context color when running with privileges.
typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=178 typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=178

@ -84,6 +84,7 @@
# ram # free RAM # ram # free RAM
# swap # used swap # swap # used swap
todo # todo items (https://github.com/todotxt/todo.txt-cli) todo # todo items (https://github.com/todotxt/todo.txt-cli)
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time # time # current time
# =========================[ Line #2 ]========================= # =========================[ Line #2 ]=========================
newline newline
@ -606,6 +607,13 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐'
###########[ timewarrior: timewarrior tracking status (https://timewarrior.net/) ]############
# Timewarrior color.
typeset -g POWERLEVEL9K_TIMEWARRIOR_FOREGROUND=4
# Custom icon.
# typeset -g POWERLEVEL9K_TIMEWARRIOR_VISUAL_IDENTIFIER_EXPANSION='⭐'
##################################[ context: user@hostname ]################################## ##################################[ context: user@hostname ]##################################
# Context color when running with privileges. # Context color when running with privileges.
typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=1 typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=1

@ -84,6 +84,7 @@
# ram # free RAM # ram # free RAM
# swap # used swap # swap # used swap
todo # todo items (https://github.com/todotxt/todo.txt-cli) todo # todo items (https://github.com/todotxt/todo.txt-cli)
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time # time # current time
# =========================[ Line #2 ]========================= # =========================[ Line #2 ]=========================
newline newline
@ -606,6 +607,13 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐'
###########[ timewarrior: timewarrior tracking status (https://timewarrior.net/) ]############
# Timewarrior color.
typeset -g POWERLEVEL9K_TIMEWARRIOR_FOREGROUND=110
# Custom icon.
# typeset -g POWERLEVEL9K_TIMEWARRIOR_VISUAL_IDENTIFIER_EXPANSION='⭐'
##################################[ context: user@hostname ]################################## ##################################[ context: user@hostname ]##################################
# Context color when running with privileges. # Context color when running with privileges.
typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=178 typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=178

@ -85,6 +85,7 @@
# ram # free RAM # ram # free RAM
# swap # used swap # swap # used swap
todo # todo items (https://github.com/todotxt/todo.txt-cli) todo # todo items (https://github.com/todotxt/todo.txt-cli)
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time # time # current time
# =========================[ Line #2 ]========================= # =========================[ Line #2 ]=========================
newline newline
@ -637,6 +638,14 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_TODO_VISUAL_IDENTIFIER_EXPANSION='⭐'
###########[ timewarrior: timewarrior tracking status (https://timewarrior.net/) ]############
# Timewarrior color.
# typeset -g POWERLEVEL9K_TIMEWARRIOR_FOREGROUND=255
# typeset -g POWERLEVEL9K_TIMEWARRIOR_BACKGROUND=8
# Custom icon.
# typeset -g POWERLEVEL9K_TIMEWARRIOR_VISUAL_IDENTIFIER_EXPANSION='⭐'
##################################[ context: user@hostname ]################################## ##################################[ context: user@hostname ]##################################
# Context color when running with privileges. # Context color when running with privileges.
typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=1 typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=1

@ -123,6 +123,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua' LUA_ICON 'lua'
PERL_ICON 'perl' PERL_ICON 'perl'
NNN_ICON 'nnn' NNN_ICON 'nnn'
TIMEWARRIOR_ICON 'tw'
) )
;; ;;
'awesome-fontconfig') 'awesome-fontconfig')
@ -233,6 +234,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua' LUA_ICON 'lua'
PERL_ICON 'perl' PERL_ICON 'perl'
NNN_ICON 'nnn' NNN_ICON 'nnn'
TIMEWARRIOR_ICON 'tw'
) )
;; ;;
'awesome-mapped-fontconfig') 'awesome-mapped-fontconfig')
@ -347,6 +349,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua' LUA_ICON 'lua'
PERL_ICON 'perl' PERL_ICON 'perl'
NNN_ICON 'nnn' NNN_ICON 'nnn'
TIMEWARRIOR_ICON 'tw'
) )
;; ;;
'nerdfont-complete'|'nerdfont-fontconfig') 'nerdfont-complete'|'nerdfont-fontconfig')
@ -458,6 +461,7 @@ function _p9k_init_icons() {
LUA_ICON '\uE620' #  LUA_ICON '\uE620' # 
PERL_ICON '\uE769' #  PERL_ICON '\uE769' # 
NNN_ICON 'nnn' NNN_ICON 'nnn'
TIMEWARRIOR_ICON '\uF132' # 
) )
;; ;;
*) *)
@ -568,6 +572,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua' LUA_ICON 'lua'
PERL_ICON 'perl' PERL_ICON 'perl'
NNN_ICON 'nnn' NNN_ICON 'nnn'
TIMEWARRIOR_ICON 'tw'
) )
;; ;;
esac esac

@ -4255,6 +4255,63 @@ function instant_prompt_direnv() {
fi fi
} }
function prompt_timewarrior() {
local -a stat
if [[ -n $_p9k_timewarrior_file_name ]]; then
zstat -A stat +mtime -- ~/.timewarrior/data $_p9k_timewarrior_file_name 2>/dev/null || stat=()
if [[ $stat[1] == $_p9k_timewarrior_dir_mtime && $stat[2] == $_p9k_timewarrior_file_mtime ]]; then
if (( $+_p9k_timewarrior_tags )); then
_p9k_prompt_segment $0 grey 255 TIMEWARRIOR_ICON 0 '' "${_p9k_timewarrior_tags//\%/%%}"
fi
return
fi
fi
if [[ ! -d ~/.timewarrior/data ]]; then
_p9k_timewarrior_dir_mtime=0
_p9k_timewarrior_file_mtime=0
_p9k_timewarrior_file_name=
unset _p9k_timewarrior_tags
return
fi
if [[ $stat[1] != $_p9k_timewarrior_dir_mtime ]]; then
local -a files=(~/.timewarrior/data/<->-<->.data(.N))
if (( ! $#files )); then
if (( $#stat )) || zstat -A stat +mtime -- ~/.timewarrior/data 2>/dev/null; then
_p9k_timewarrior_dir_mtime=$stat[1]
_p9k_timewarrior_file_mtime=$stat[1]
_p9k_timewarrior_file_name=~/.timewarrior/data
else
_p9k_timewarrior_dir_mtime=0
_p9k_timewarrior_file_mtime=0
_p9k_timewarrior_file_name=
fi
unset _p9k_timewarrior_tags
return
fi
_p9k_timewarrior_file_name=${${(AO)files}[1]}
fi
if ! zstat -A stat +mtime -- ~/.timewarrior/data $_p9k_timewarrior_file_name 2>/dev/null; then
_p9k_timewarrior_dir_mtime=0
_p9k_timewarrior_file_mtime=0
_p9k_timewarrior_file_name=
unset _p9k_timewarrior_tags
return
fi
_p9k_timewarrior_dir_mtime=$stat[1]
_p9k_timewarrior_file_mtime=$stat[2]
{ local tail=${${(Af)"$(<$_p9k_timewarrior_file_name)"}[-1]} } 2>/dev/null
if [[ $tail == (#b)'inc '[^\ ]##(|\ #\#(*)) ]]; then
_p9k_timewarrior_tags=${${match[2]## #}%% #}
_p9k_prompt_segment $0 grey 255 TIMEWARRIOR_ICON 0 '' "${_p9k_timewarrior_tags//\%/%%}"
else
unset _p9k_timewarrior_tags
fi
}
function _p9k_prompt_timewarrior_init() {
typeset -g "_p9k__segment_cond_${_p9k_prompt_side}[_p9k_segment_index]"='$commands[timew]'
}
# Use two preexec hooks to survive https://github.com/MichaelAquilina/zsh-you-should-use with # Use two preexec hooks to survive https://github.com/MichaelAquilina/zsh-you-should-use with
# YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427. # YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427.
_p9k_preexec1() { _p9k_preexec1() {
@ -5307,6 +5364,9 @@ typeset -g _p9k__param_pat
typeset -g _p9k__param_sig typeset -g _p9k__param_sig
_p9k_init_vars() { _p9k_init_vars() {
typeset -gi _p9k_timewarrior_dir_mtime
typeset -gi _p9k_timewarrior_file_mtime
typeset -g _p9k_timewarrior_file_name
typeset -ga _p9k__prompt_char_saved typeset -ga _p9k__prompt_char_saved
typeset -g _p9k__worker_pid typeset -g _p9k__worker_pid
typeset -g _p9k__worker_req_fd typeset -g _p9k__worker_req_fd

Loading…
Cancel
Save