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.56k stars 713 forks source link

Back-ticks and text inside is removed from a task #371

Closed randy closed 2 years ago

randy commented 2 years ago

As a programmer, I often use back-ticks to denote code, so as I was blasting in my current todo-list, I wasn't even considering that this app would not handle back-ticks correctly. After all, it's just text! Sadly, I have quite a few todo items that make no sense because they're lacking the text contained within the back-ticks.

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

What is the current behavior? When you add a task with back-ticks (`), the back-ticks and text inside is removed from the string.

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

> task.sh add a task with `back-ticks`
> task.sh ls
1 add a task with

What is the expected behavior?

> task.sh add a task with `back-ticks`
> task.sh ls
1 a task with `back-ticks`

Which versions todo.sh are you using?

Run todo.sh -V TODO.TXT Command Line Interface v2.12.0

Which Operating System are you using? Mac OSX 10.15.7

Which version of bash are you using?

Run bash --version Bash is 5.1.4(1), but I use zsh and it's 5.7.1 (x86_94-apple-darwin19.0)

craigmaloney commented 2 years ago

You'll want to escape those backticks because your shell is going to see those and try to execute that as a shell command before adding that to your todo.

craig@kryten:~$ t add Test `date +%F` @computer
172 Test 2021-11-16 @computer
TODO: 172 added.

You'll want to do the following to add the back ticks explicitly:

craig@kryten:~$ t add Test \`date +%F\` @computer
173 Test `date +%F` @computer
TODO: 173 added.

Alternatively, you can add the task interactively:

craig@kryten:~$ t add
Add: Test `date +%F` @computer
175 Test `date +%F` @computer
TODO: 175 added.

Hope this helps!

randy commented 2 years ago

It does help... I was just going to edit the issue to say it doesn't matter if these are contained in a fully-quoted string or not. I was having issues with single-quotes, too and fully-enclosing the todo in double-quotes fixed that, but not this.

craigmaloney commented 2 years ago

I've gotten in the habit of escaping single quotes as well:

craig@lister:~$ t add This isn\'t an issue when you escape the single quotes @computer
173 This isn't an issue when you escape the single quotes @computer
TODO: 173 added.

It takes practice, but eventually it'll become second nature (or is that it\'ll. ;))

But yeah, even with double quotes bash will try to execute anything in the back-ticks.

inkarkat commented 2 years ago

As a programmer, you really should familiarize yourself with your shell's quoting rules :-) Craig already mentioned the rules (in Bash, either escape backticks with a prepended backslash, or enclose the whole text in single quotes (but then contained single quotes become a bit problematic)), or alternatively let the application query you for the task text.

This is not a bug; I use the backticks all the time to get command output into the task (e.g. todo.sh add clean up disk space @`hostname` soon).