todotxt / todo.txt-cli

☑️ A simple and extensible shell script for managing your todo.txt file.
http://todotxt.org
GNU General Public License v3.0
5.58k stars 714 forks source link

Allow $TODOTXT_DEFAULT_ACTION to include spaces #293

Closed NicksIdeaEngine closed 4 years ago

NicksIdeaEngine commented 4 years ago

Do you want to request a feature or report a bug?

Feature, but perhaps it's also a bug?

What is the current behavior?

In config, setting export TODOTXT_DEFAULT_ACTION="view project" to use the view add-on displays the Usage: todo.sh [-fhpantvV]... message.

Setting the default action to just "view" or view without quotes gives Error: Unrecognized option "". I get the same error setting it to view project without quotes.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Still not sure if it's a bug, but installing the view add-on and trying to set the default action to view project in any form doesn't work.

I did get it somewhat working with this: alias t="todo.sh -c -d ~/.config/todo/config view project"

But that solution disrupts using t for anything other action like t add or t pri.

What is the expected behavior?

Using t to display tasks sorted the way view project sorts them, while also being able to use t for other actions as well. My current workaround is an alias tvp that has the view project action, but it'd be cool to just have that as the default without disrupting other actions.

Which versions todo.sh are you using?

Run todo.sh -V

v2.11.0

Which Operating System are you using?

Ubuntu 19.10

Which version of bash are you using?

Run bash --version

zsh 5.7.1 (x86_64-ubuntu-linux-gnu) bash version 5.0.3(1)-release (x86_64-pc-linux-gnu)

inkarkat commented 4 years ago

In todo.txt-cli lingo, action is just the subcommand itself; it does not include any arguments, so I don't see this as a bug, but an enhancement.

Such an enhancement surely could be done (I don't think that actions can include spaces, so there would be no clash or ambiguity), but I'm not convinced of the necessity. Yes, your approach with aliases has the downside that you can't use the same for the default action and custom arguments, but this can be easily achieved with a shell function:

tvp()
{
    if [ $# -eq 0 ]; then
        todo.sh view project
    else
        todo.sh "$@"
    fi
}

Alternatively, you could also solve this with a custom action, e.g. viewproject or vp. Writing custom actions is easy (especially if all they do is calling existing action(s); see here for an example); you just drop then into ~/.todo.action.d/ and can then set that action as your default one.

NicksIdeaEngine commented 4 years ago

That makes sense. I appreciate the explanation a lot, and the shell function solution sounds like it'll give me exactly what I'm looking for.

Thank you!