aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-05-22 10:59:52 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-05-22 10:59:52 +0300
commit743b7c658406c92b6d2bf4767478be5e93dd71ca (patch)
treef24046d52d8c0752fd081aad4d6d27922cc2c6a7 /powerlevel9k.zsh-theme
parent0b8a9bded5ef7ba71f2b2a329b8916cd92f2f08c (diff)
speed up todo prompt
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme34
1 files changed, 29 insertions, 5 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 853576d6..6f9d4e86 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -1139,7 +1139,7 @@ function _p9k_cached_cmd_stdout() {
shift
local -H stat
zstat -H stat -- $cmd 2>/dev/null || return
- if ! _p9k_cache_get "$0" "$stat[inode]" "$stat[mtime]" "$stat[size]" "$cmd" "$@"; then
+ if ! _p9k_cache_get $0 $stat[inode] $stat[mtime] $stat[size] $stat[mode] $cmd "$@"; then
local out
out=$($cmd "$@" 2>/dev/null)
_p9k_cache_set $(( ! $? )) "$out"
@@ -1581,12 +1581,36 @@ prompt_date() {
################################################################
# todo.sh: shows the number of tasks in your todo.sh file
prompt_todo() {
- if $(hash todo.sh 2>&-); then
- count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }')
- if [[ "$count" = <-> ]]; then
- "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" 'TODO_ICON' 0 '' "${count//\%/%%}"
+ #emulate -L zsh && setopt xtrace
+ local todo=$commands[todo.sh]
+ [[ -n $todo ]] || return
+ if (( ! $+_P9K_TODO_FILE )); then
+ # There is a bug in todo.sh where it uses $0 instead of ${BASH_SOURCE[0]}. We work around
+ # it by overriding `dirname`, to which $0 is passed as an argument.
+ local script="
+ function dirname() {
+ local f=\$1
+ [[ \"\$f\" == bash ]] && f=${(Q)commands[todo.sh]}
+ command dirname \"\$f\"
+ }
+ source todo.sh shorthelp &>/dev/null
+ echo \"\$TODO_FILE\""
+ typeset -g _P9K_TODO_FILE=$(bash -c $script)
+ fi
+ [[ -r $_P9K_TODO_FILE ]] || return
+ local -H stat
+ zstat -H stat -- $_P9K_TODO_FILE 2>/dev/null || return
+ if ! _p9k_cache_get $0 $stat[inode] $stat[mtime] $stat[size]; then
+ local count=$($todo -p ls | command tail -1)
+ emulate -L zsh && setopt extendedglob
+ if [[ $count == (#b)'TODO: '[[:digit:]]##' of '([[:digit:]]##)' '* ]]; then
+ _p9k_cache_set 1 $match[1]
+ else
+ _p9k_cache_set 0 0
fi
fi
+ (( $_P9K_CACHE_VAL[1] )) || return
+ "$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" 'TODO_ICON' 0 '' "${_P9K_CACHE_VAL[2]}"
}
################################################################