timewarrior icon indicating copy to clipboard operation
timewarrior copied to clipboard

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

Open arooni opened this issue 2 years ago • 4 comments

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

arooni avatar Nov 04 '21 19:11 arooni

@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.

tbabej avatar Nov 05 '21 02:11 tbabej

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

smemsh avatar Nov 05 '21 20:11 smemsh

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

lauft avatar Nov 06 '21 06:11 lauft

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

smemsh avatar Nov 06 '21 21:11 smemsh