summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2020-01-26 21:29:06 +0300
committerromkatv <roman.perepelitsa@gmail.com>2020-01-26 21:29:06 +0300
commitbfa70fa86de6cb7cca92336ddc75161f565e1e0c (patch)
tree0cb14f62d54cfd7987d7164ea68d5cf556053c5a /internal
parenta9715367d4547dabaa724f9907bc971078453528 (diff)
add timewarrior prompt segment; see #295
Diffstat (limited to 'internal')
-rw-r--r--internal/icons.zsh5
-rw-r--r--internal/p10k.zsh60
2 files changed, 65 insertions, 0 deletions
diff --git a/internal/icons.zsh b/internal/icons.zsh
index 63e9e2e4..a96b747c 100644
--- a/internal/icons.zsh
+++ b/internal/icons.zsh
@@ -123,6 +123,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua'
PERL_ICON 'perl'
NNN_ICON 'nnn'
+ TIMEWARRIOR_ICON 'tw'
)
;;
'awesome-fontconfig')
@@ -233,6 +234,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua'
PERL_ICON 'perl'
NNN_ICON 'nnn'
+ TIMEWARRIOR_ICON 'tw'
)
;;
'awesome-mapped-fontconfig')
@@ -347,6 +349,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua'
PERL_ICON 'perl'
NNN_ICON 'nnn'
+ TIMEWARRIOR_ICON 'tw'
)
;;
'nerdfont-complete'|'nerdfont-fontconfig')
@@ -458,6 +461,7 @@ function _p9k_init_icons() {
LUA_ICON '\uE620' # 
PERL_ICON '\uE769' # 
NNN_ICON 'nnn'
+ TIMEWARRIOR_ICON '\uF132' # 
)
;;
*)
@@ -568,6 +572,7 @@ function _p9k_init_icons() {
LUA_ICON 'lua'
PERL_ICON 'perl'
NNN_ICON 'nnn'
+ TIMEWARRIOR_ICON 'tw'
)
;;
esac
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index 7c80337d..062adf74 100644
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -4255,6 +4255,63 @@ function instant_prompt_direnv() {
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
# YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427.
_p9k_preexec1() {
@@ -5307,6 +5364,9 @@ typeset -g _p9k__param_pat
typeset -g _p9k__param_sig
_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 -g _p9k__worker_pid
typeset -g _p9k__worker_req_fd