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

Backup file naming when todo is on icloud drive #312

Closed bingaman closed 4 years ago

bingaman commented 4 years ago

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

What is the current behavior? After an update, todo.txt.bak is renamed todo.txt.txt if the todo directory is on an icloud drive

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. If I remove todo.txt.bak, update an items priority, the first backup is called todo.txt.bak. If I put the priority back to what it was I have 2 files, todo.txt and todo.txt.txt. I have also ended up with more files that look like todo.txt 2.txt

What is the expected behavior? The backup should just be called todo.txt.bak I would think

Which versions todo.sh are you using?

Run todo.sh -V TODO.TXT Command Line Interface v@DEV_VERSION@

Homepage: http://todotxt.org Code repository: https://github.com/todotxt/todo.txt-cli/ Contributors: https://github.com/todotxt/todo.txt-cli/graphs/contributors License: https://github.com/todotxt/todo.txt-cli/blob/master/LICENSE

Also happens on 2.11.0

Which Operating System are you using? OS X Mojave

Which version of bash are you using?

Run bash --version

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)

bingaman commented 4 years ago

On further testing it looks like the problem is with running sed -i.bak on any file that's on icloud. Ugh

inkarkat commented 4 years ago

You can define a sed function in the config file and export it (originally mentioned in #168; improved here to use command instead of which); todo.sh and any add-ons launched by it will then use that one:

sed()
{
    # Assumption: The in-place option is passed as the first argument.
    if [ "$1" = '-i.bak' ]; then
        shift

        # Assumption: Only a single file is processed, and it is passed as the
        # last argument.
        file=${!#}

        tmpFile=/tmp/todo.sh-sed.$$
        command sed "$@" > "$tmpFile" && mv "$tmpFile" "$file"
    else
        command sed "$@"
    fi
}
export -f sed
inkarkat commented 4 years ago

Closing this as it's a problem with sed and not todo.sh itself, and a workaround exists. If you obtain additional information about the original problem, please post this here as well; other people may run into the same problem and will appreciate any help.