Closed cdlscpmv closed 5 years ago
Let me describe the use case. I mount removable media in directories inside /media
. The names
of these directories change from one device to another. So I wanted to display them in the statusline when they are plugged and hide them when they aren't. When no divice is plugged, the /media
directory is empty which is why I didn't pass the GLOB_NOCHECK
flag.
About GLOB_NOSORT
, I thought that predictable order of displayed paths would be preferrable for a statusline.
Well, I revisit the code tomorrow. Non-existent paths must be handled, for sure.
I've been thinking about how to differentiate between a non-existent path and a failing glob pattern. And I see no easy way to do that that except for writing almost the whole spec of glob expansion rules.
I'm thinking about introducing a separate options like paths_glob
with the feature that patterns may expand to nothing. What are your thought on that?
About GLOB_NOSORT, I thought that predictable order of displayed paths would be preferrable for a statusline.
The order in which glob()
returns the results has no effect, as the results are then used as Lua table keys. The order of traversal of string keys with pairs()
, next()
, or anything else, is undefined (as Lua tables are hash tables).
which is why I didn't pass the GLOB_NOCHECK flag.
Consider adding globs
option in addition to paths
.
Consider adding globs option in addition to paths.
Will do!
I've implemented the new option. Regarding the code, I do not check for GLOB_NOMATCH
, because, according to my interpretation of POSIX, gl_pathc
will be zero in this case.
Thank you for guidance. At this point you wrote the whole code by yourself =).
Thanks for the contribution!
At this point you wrote the whole code by yourself =).
I remember how my first contribution to strace required 12+ rounds of review :)
What’s the use case? If the list of matches does not change, it can be done on the Lua side.
So, if
paths
contain non-existing (or non-accessible) paths, it will silently swallow the errors? E.g.opts = {paths = {'/', '/home', '/asdfdasfdasfsadfdssdf'}}