Closed pabgan closed 5 months ago
I'm experiencing similar issues. I'm on a Mac, I'm using zsh and I'm keeping the todo-txt configuration file in a separate folder inside Dropbox.
Inside .zshrc
I added this:
source /usr/local/Cellar/todo-txt/2.11.0/etc/bash_completion.d/todo_completion complete -F _todo t
alias t="/usr/local/bin/todo.sh -d $HOME/Dropbox/todo/todo.cfg"
I'm not even sure it's completely correct, but the auto completion works, somehow. The commands and parameters are completed correctly, while the contexts and tags are completed using a previous todo-txt installation. So it's not that it doesn't work, it doesn't work with the correct file.
Maybe your problem is similar
I was facing the same issue but found a solution.
First, the reason why @pabgan's approach does not work is that the local _todo_sh='...'
workaround is meant for the bash
autocompletion script, while zsh
ships with an entirely different todotxt autocompletion script which doesn't have this variable.
Worse even, the zsh
completion script just calls todo.sh
with no possibility to override its parameters.
A solution is to use wrapper completion functions which use aliases for todo.sh
:
# Without this, zsh would expand the t and tt aliases too early, causing
# it to use the vanilla _todo.sh completion function which reads the
# todotxt config from the default location, i.e. not what we want.
# zsh documentation: http://zsh.sourceforge.net/Doc/Release/Options.html
setopt COMPLETE_ALIASES
alias t="todo.sh -a -d $TODO_TXT/personal-todo.cfg"
_t()
{
alias todo.sh='todo.sh -d $TODO_TXT/personal-todo.cfg'
# This is needed to make aliases work in a non-interactive shell,
# see https://stackoverflow.com/questions/23258413/expand-aliases-in-non-interactive-shells
setopt ALIASES
_todo.sh "$@"
}
compdef _t t
alias tt="todo.sh -a -d $TODO_TXT/trabajo-todo.cfg"
_tt()
{
alias todo.sh='todo.sh -d $TODO_TXT/trabajo-todo.cfg'
setopt ALIASES
_todo.sh "$@"
}
compdef _tt tt
A cleaner solution could be achieved of course if the zsh
autocompletion script had a variable like the bash
one does.
My system for completeness:
Ubuntu 20.04.2 LTS
zsh 5.8 (x86_64-ubuntu-linux-gnu)
TODO.TXT Command Line Interface v2.11.0
installed via default apt
repositories
The apt version installs todotxt-cli under /usr/bin/todo-txt
, so I'm using the above solution with todo-txt
inplace of todo.sh
in all the alias
statements. Symlinking /usr/bin/todo-txt
to /usr/local/bin/todo.sh
together with the above solution worked too.At the time I could not make that work so I went for a completely different approach, linking the config needed when needed. Now, three years after, with much more knowledge I could make it work with @mbugert solution. Thank you very much.
Do you want to request a feature or report a bug? I want to request help, or feature in documentation, as you wish. Mailing list links are dead.
What is the current behavior? I cannot make autocompletion to work in ZSH with two different configurations.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. In my
.zshrc
I have:But it does not autocomplete or expand
@
nor+
. If I makeThen both aliases
t
andtt
autocomplete withpersonal-todo.cfg
What is the expected behavior? I learnt that I should use
compdef
instead ofcomplete -F
in ZSH. But I guess the problem is now in the wrapper function, that it does not work in ZSH. Does somebody know how to translate it? Can this be added to documentation?Which versions todo.sh are you using?
Which Operating System are you using?
Which version of bash are you using?