GothenburgBitFactory / timewarrior

Timewarrior - Commandline Time Tracking and Reporting
https://timewarrior.net
MIT License
1.24k stars 93 forks source link

Allow for relative path names for import statements, for instance, themes #460

Open arooni opened 2 years ago

arooni commented 2 years ago

Currently all import statements appear to be limited to absolute paths.

I use timewarrior/taskwarrior on Ubuntu linux, but also on my Mac. The home directories are slightly different so it'd be nice to allow for one config file to be used on both for ease of use and consistency. However, I seem to have to create a separate absolute path entry for my Mac then for my Ubuntu machine

Currently required:
# import /home/arooni/.timewarrior/dark.theme
#import /Users/arooni/.timewarrior/dark.theme

I have to comment out one entry depending on which platform. Relative path support would solve this

tbabej commented 2 years ago

@arooni I think you should be able to use ~ in place of /home/arooni/, i.e.

import ~/.timewarrior/dark.theme

should work on both platforms.

smemsh commented 2 years ago

maybe a different issue, but it also doesn't work if the path specified is outside $TIMEWARRIORDB (mine is ~/.task), looks like somehow it's splitting it up two different ways... I added some prints in Rules::parse() at firstWord == "import" and, if the path is inside the dir:

# import /home/scott/.task/foo.bar
IMPORT tokens.size: 2
IMPORT tokens: import, /home/scott/.task/foo.bar, 

but if it's outside the dir:

# import /home/scott/foo.bar
IMPORT tokens.size: 7
IMPORT tokens: import, /, home, /, scott, /, foo.bar, 

latter case fails tokens.size() == 2 test, so it's never considered a candidate for import routines

lauft commented 2 years ago

It seems ~ is only expanded for paths. When loading the rules file, this is done for the given filename. However, for imports the token after import has to have been recognized as type 'path' by the Lexer.

In the Lexer I found the rule that a token is only recognized as type 'path' if it starts with a / and also contains more than 3 of them.

The latter explains why @smemsh file was not imported if it was "outside the dir".

This might be an (ugly) workaround:

# import /home/scott/../scott/foo.bar
smemsh commented 2 years ago

Ah ok, so it's not being inside $TIMEWARRIORDB at all but just that it has enough slashes? nice. Indeed, import /tmp/test/foo/testfile works