taskwarrior icon indicating copy to clipboard operation
taskwarrior copied to clipboard

Search for tasks with descriptions containing a hyphen

Open heiderich opened this issue 5 years ago • 11 comments

To report a bug...

  • What command(s) did you run?
task add foo-bar
task foo-bar
  • What did you expect to happen?
  1. The first command adds a new task with description "foo-bar" (this happens).
  2. The second command finds this added task and displays it.
  • What actually happened?
$ task add foo-bar
Created task 303.
$ task list | grep foo-bar
303        1s                                                                    foo-bar  
$ task foo-bar
[task next ( foo-bar )]
Cannot subtract strings
  • Paste the output of the task diag command.
$ task diag

task 2.5.1
   Platform: Linux

Compiler
    Version: 7.2.0
       Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
 Compliance: C++11

Build Features
      CMake: 3.9.5
    libuuid: libuuid + uuid_unparse_lower
  libgnutls: 3.5.16
 Build type: None

Configuration
       File: /home/user/.taskrc (found), 2894 bytes, mode 100644
       Data: /home/user/.task (found), dir, mode 40755
    Locking: Enabled
         GC: Enabled
    $EDITOR: vim
     Server: servername:53589
         CA: /home/user/.task/ca.cert.pem, readable, XXX bytes
      Trust: strict
Certificate: /home/user/.task/client.cert.pem, readable, YYY bytes
        Key: /home/user/.task/client.key.pem, readable, ZZZ bytes
    Ciphers: NORMAL
      Creds: AAA/user/************************************

Hooks
     System: Enabled
   Location: /home/user/.task/hooks
     Active: [...]

Tests
      $TERM: xterm-256color (276x56)
       Dups: Scanned NNN tasks for duplicate UUIDs:
             Found duplicate [...]
 Broken ref: Scanned NNN tasks for broken references:
             No broken references found

Note that there were several issues related to hyphens:

#1307 (about adding tasks including hyphens, which seems to work now) #289 (about numbers in combination with hyphens) #1657 (a similar issue as the one I am reporting here, but for project names instead; according to my tests this seems to be resolved)

heiderich avatar Mar 02 '19 10:03 heiderich

The term foo-bar looks like an expression. Use task /foo-bar/.

pbeckingham avatar May 27 '19 16:05 pbeckingham

I guess you mean an expression in the sense of https://taskwarrior.org/docs/terminology.html#expression. What exactly is treated as an expression? The documentation does not mention the hyphen. It says

An algebraic expression is a mathematical expression comprised of constants, operators and symbols.

What are the valid constants, operators and symbols?

heiderich avatar May 27 '19 17:05 heiderich

Any r-value is treated as a possible expression, if it contains operators.

pbeckingham avatar Aug 11 '19 22:08 pbeckingham

How do I prevent this interpretation of arbitrary tags as expressions?

# task +foo-bar list
Cannot subtract from a Boolean value

I tried all kinds of magic, like task +foo\\-bar list and task +foo\\\\-bar list (output the same error) and task +'"Freiheit-Ulmo-Iteration102"' list (lists not the stories I would expect), but nothing works.

fdcds avatar Feb 07 '20 09:02 fdcds

Filtering for descriptions containing a hyphen is now supported on 2.6.0.

To be exact, the following syntax needs to be used:

task desc:one-two

tbabej avatar Jan 31 '21 03:01 tbabej

I noticed that searching for a task also fails when enumarting with a comma without space between.

$ task exec
$ task exec,
[task next ( exec, )]

ID Age Tag  Description                                                                                  Urg
42 3h  bash when and how to use exec, xargs, tee, sh -c, bash groups, subshells and process substitution  0.8

1 task

heinrichat avatar Jun 10 '21 23:06 heinrichat

@heiderich This is not a failed search, but in fact a very accidental use of task execute command:

       task execute <external command>
              Executes the specified command.  Not useful by itself, but
              when used in conjunction with aliases and  extensions  can
              provide seamless integration.

Perhaps task should error out instead of being silent when execute is ran with no parameters. I'll spin it out into a separate issue.

tbabej avatar Jun 10 '21 23:06 tbabej

The task one-two search still fails, or rather, matches all the tasks.

The desc:one-two or /one-two/ filters work as expected and can be used as a workaround. Keeping this open until all cases are resolved.

tbabej avatar Aug 14 '21 22:08 tbabej

Just an additional case:

A forward slash in the search term seems unsearchable, which makes searching for URLs impossible.

task add visit example.com/foo/bar

task example.com/foo/bar shows all tasks task desc:example.com/foo/bar shows No matches task desc:example.com\/foo\/bar shows No matches

Tried various other escapings, and all either list all tasks or nothing.

v2.6.1

bruderstein avatar Jan 07 '22 22:01 bruderstein

Update for anyone else finding this:

After going through the source and the debug output (add rc.debug.parser:3 to the command line), it became clear that the lexer spots a url and also a path (which is something that seems to have more than one / in it), but then doesn't make that a description filter - that's only done for a plain string.

The desc: also only works for plain strings, and regexes with paths separators don't work.

But there is a workaround that works :tada:

task "desc~https://example.com/foo/bar/baz"

Note that this is a regex search, so needs to be treated as such.

bruderstein avatar Feb 04 '22 08:02 bruderstein

Now I wonder why can't TaskWarrior do just a plain string search by default?

sskras avatar May 16 '23 15:05 sskras