]> git.rmz.io Git - dotfiles.git/commitdiff
zsh: only print task prompt if task is installed
authorSamir Benmendil <me@rmz.io>
Sun, 2 Mar 2025 21:15:35 +0000 (21:15 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 2 Mar 2025 21:15:35 +0000 (21:15 +0000)
zsh/lib/50-taskwarrior.zsh [new file with mode: 0644]
zsh/lib/99-prompt.zsh [moved from zsh/lib/prompt.zsh with 93% similarity]
zsh/lib/taskwarrior.zsh [deleted file]

diff --git a/zsh/lib/50-taskwarrior.zsh b/zsh/lib/50-taskwarrior.zsh
new file mode 100644 (file)
index 0000000..ce423cf
--- /dev/null
@@ -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
+}
similarity index 93%
rename from zsh/lib/prompt.zsh
rename to zsh/lib/99-prompt.zsh
index 3ca62a41b4dd5b02c118e7720b64e9fc497eb7e5..f5ea7ed90483331ccc91a9099d21963cd738948c 100644 (file)
@@ -5,6 +5,10 @@ autoload colors; colors;
 hostcolor=cyan
 [[ $(hostname) == "tardis" ]]  && hostcolor=red
 
 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%} '
 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.)"
 }
   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 (file)
index f1ae1ce..0000000
+++ /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
-}