sleek icon indicating copy to clipboard operation
sleek copied to clipboard

Sort the todo.txt file when saving it

Open hdrz opened this issue 3 years ago • 7 comments

I think it would be better to sort the file on disk, this way opening the file with any other editor or viewer makes interaction easier. Also, this is the original intent for this file (see todotxt.org).

Or, maybe add an option to save it sorted?

hdrz avatar Aug 31 '21 13:08 hdrz

Can you be more specific where it is specified that todo.txt applications should sort the file on disk? I doubt that this is written somewhere in the official documentation, since the official CLI tool never sorts the file on disk. When printing the tasks with t ls, the output is sorted and the original line numbers are printed before in order to identify the task when marking it as done etc.

I would further argue that sorting the file goes against the todo.txt principle since it makes handling the file as plain text a lot harder (diffs and merging would be impossible, for example). Sorting the file on disk might still be a nice option for some use cases, though.

dlaidig avatar Sep 01 '21 09:09 dlaidig

It is implied that the highest priority task is always on top, or should be there with the help of sort in your text editor. This way it is clear what is your next task. See here. Even the example file on the main page is sorted.

Let me give a hypothetical use case: I use sleek on my win10 computer at work to manage dotos, and I sync the text file to github. At home or while commuting I would like to use my phone to access that same file on github. Now imagine this file is few monthes old with let's say 100 lines, and I'm interested in the 3 most relevant ones. If the file is sorted by priority+due, it takes me a second to be on top of things, but if not, good luck with that...

It's not mandatory, that's why the tools where created in the first place, but it's logical to sort the file and to me it makes sense.

hdrz avatar Sep 01 '21 10:09 hdrz

I may not fully understand what you are proposing, however you can view the list of todos by priority by setting the sort order in the configuration options. Then when you open a todo file, the A priority items are shown at the top of the list.

You can also press f to position the cursor in the find dialog box then type pri=A to view A priority todos.

Hope this works for you.

velardevines avatar Sep 03 '21 14:09 velardevines

I would agree that an option to enable sorting for entries in todo.txt (on exit or upon adding new element) would be useful.

If you are accessing todo.txt only via clients which supports sorting then it doesn't matter in which order your entries are. But if you are also edit todo.txt using text editors or other application that can't sort entries then it may be a problem.

E.g. I'm also edit todo.txt on my machine with vim and syncing it to Android to open with Markor (that can't sort todo's on the fly, only when simultaneously rewriting file).

anlar avatar Sep 05 '21 06:09 anlar

Please do not sort the actual file - this should remain strictly in entry order. Sorting makes it impossible to do version control with usual text tools - e.g what was added, how can I debug this file conflict etc (part of the whole point of using text based data). It also creates chaos when using the same todo.txt file in different apps - if each sorts them this causes muddlement, overhead and potential data loss

aubreyz avatar Oct 28 '21 19:10 aubreyz

I understand the reasons for not sorting the actual file. It means that I must use a tool of somekind to view the file. And if that’s the case why do I need todo.txt file? I can equally use any database to hold my list (for example sqlite). For me the whole reason to use a text file is to be able to see and understand it immediately.

hdrz avatar Oct 29 '21 06:10 hdrz

Strongly agree with @aubreyz that sorting on disk should not happen. todo.txt should act like sourcecode and work with diff/patch/git.

gdevenyi avatar Nov 19 '21 19:11 gdevenyi