Open iMacadan opened 12 months ago
Is the pattern a regex? I notice that shell/bash regexes are different from python ones, and that sarra must use the python ones?
Having a trailing pattern is making it pretty complex to figure out what to do.
If you have something like ${var^^^h} if after the ^^ you have a regex ^h, which means only upper-case if it starts with h. ... and braces are a thing in python regexes, so now have to deal with nested braces... getting hairy.
UPDATE: above pattern is wrong... see patterns link a few posts down.
need an actual parser at this point... which is probably not a bad thing, just work.
There's details about all the substitutions supported by bash online:
https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
the tests/sarracenia/config_test.py file could contain test cases for all these, and then it would just be a matter of running:
pytest -o log_cli=true tests/sarracenia/config_test.py
so there is a good framework to build unit tests for an implementation (that would be in sarracenia/config.py .. ( variableExpansion routine.)
reading up on the references, the patterns are not regexes, but a different language akin to globbing but different again. sigh... how many pattern matching dialects to implement in a single app.
https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
I'm tempted to put in something totally idiosyncractic like... a means of embedding python in the config file. The shell stuff looks complicated to parse, not that poweful, and not that obvious wondering if having a means of embedding python in the config result will be cleaner/easier to understand in future.
so... embedding python to do this stuff is basically exactly what a DESTFNSCRIPT is for, I think. so if you don't have these substitutions, you need to implement one of those, or obviously an after_accept in a normal callback... so one can make the substitutions by other means. The request is about making that doable in a one liner, without having to write any code.
It would be good to see some sample use cases for this feature.
My original ref. was https://www.cyberciti.biz/tips/bash-shell-parameter-substitution-2.html
An example use for it would be when a product's file name that contains a lower case station id which needs to be put into an uppercase subdir at destination.
But, my bad, this example falls short...
Bash param substitution would be a nice to have feature.
Not all of them would be worth it, but, for example, it can certainly help to reduce the need of creating python renamer plugins.