From: Samir Benmendil Date: Sun, 2 Mar 2025 21:15:35 +0000 (+0000) Subject: zsh: only print task prompt if task is installed X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/b0876bc435231da3f114277d8f88a2237d0b49e8 zsh: only print task prompt if task is installed --- diff --git a/zsh/lib/50-taskwarrior.zsh b/zsh/lib/50-taskwarrior.zsh new file mode 100644 index 0000000..ce423cf --- /dev/null +++ b/zsh/lib/50-taskwarrior.zsh @@ -0,0 +1,29 @@ +if (( ! $+commands[task] )); then + return 1 +fi + +alias t="noglob task" +alias tt="task today" +alias tlatest="t +LATEST" +alias in="noglob task add +in" +alias inn="in rc.context=none" +alias tw="task context wfh" +alias th="task context home" + +autoload -Uz task-quote-magic +zle -N self-insert task-quote-magic + +function tparent() { + # TODO: check args + task _get $1.rparent +} + +function task_today_list() { + local task_cmd=(task rc.verbose:nothing) + local task_count=$($task_cmd $($task_cmd _get rc.report.today.filter) count) + + local task_status="" + task_status+="%{$fg_bold[red]%} $task_count " + task_status+="%{$reset_color%}" + echo $task_status +} diff --git a/zsh/lib/prompt.zsh b/zsh/lib/99-prompt.zsh similarity index 93% rename from zsh/lib/prompt.zsh rename to zsh/lib/99-prompt.zsh index 3ca62a4..f5ea7ed 100644 --- a/zsh/lib/prompt.zsh +++ b/zsh/lib/99-prompt.zsh @@ -5,6 +5,10 @@ autoload colors; colors; hostcolor=cyan [[ $(hostname) == "tardis" ]] && hostcolor=red +if (( ! $+functions[task_today_list] )) then + function task_today_list {} +fi + precmd() { PROMPT=$'%T $(task_today_list)%n@%{$fg[$hostcolor]%}%m$(jobs_prompt)%-0>..>$(git_prompt_status)%>>\n' PROMPT+=$'$(virtualenv_prompt)%(?..%{$fg_bold[white]%}%?)%{$reset_color%}$(vi_prompt_info)%{%(!.$fg[red]❰.$fg[green]❱)%1G%} ' @@ -135,13 +139,3 @@ function print_if_fits() { length=${#${(S%%)1//$~zero/}} echo "%-$length(l.$1.)" } - -function task_today_list() { - local task_cmd=(task rc.verbose:nothing) - local task_count=$($task_cmd $($task_cmd _get rc.report.today.filter) count) - - local task_status="" - task_status+="%{$fg_bold[red]%} $task_count " - task_status+="%{$reset_color%}" - echo $task_status -} diff --git a/zsh/lib/taskwarrior.zsh b/zsh/lib/taskwarrior.zsh deleted file mode 100644 index f1ae1ce..0000000 --- a/zsh/lib/taskwarrior.zsh +++ /dev/null @@ -1,15 +0,0 @@ -alias t="noglob task" -alias tt="task today" -alias tlatest="t +LATEST" -alias in="noglob task add +in" -alias inn="in rc.context=none" -alias tw="task context wfh" -alias th="task context home" - -autoload -Uz task-quote-magic -zle -N self-insert task-quote-magic - -function tparent() { - # TODO: check args - task _get $1.rparent -}