Open hafeoz opened 4 months ago
Functions from https://github.com/Masterminds/sprig seem nice too.
I'm not sure if https://github.com/Masterminds/sprig can meet most text processing needs. If it can, I would prefer to use the sprig
library directly to enhance template text functions.
Proposal
Name templates currently have a rather limited functionality set. Following is a list of functions I personally believed to be useful:
Truncate
, whereSTRING
longer thanLEN
will be truncated. This allows more rich, longer templates to be used without worrying OS filename character limit.SafeString
, where unsafe characters (invalid filename characters) will be removed/replaced fromSTRING
. The guide's example usingReplace
works, but is a bit too long and is prone to accidental breakage (mistype, accidental character delete, etc.).Extension
andStem
, whereSTRING
will be parsed as a filename and the extension/non-extension part of the string will be returned.Pad
, whereNUMBER
will be padded toLEN
digits (e.g.{{ Pad 1 3 }}
will return a string001
)Background
I'm using
tdl
in a script to automatically backup my chat. The core logic of the script now looks something like this:Which is fairly long and isn't very elegant. I also have to download one file at a time because the whole batch will fail even if only one file is having a long name, and I want most of the file to have a descriptive name instead of plain
DialogID_MessageID
.Workarounds
I've made a small patch to add
Truncate()
andPad()
function because I need it desperately:SafeString
function is nice-to-have, but I think people should live OK without it :)A possible solution to implement
Truncate
outsidetdl
using pure shell code is to write ajq
spaghetti code to find all media with longer-than-legal filenames. It's going to be a bit fragile and really complicated though. Please paste the code below if anyone have the dare to write it.