shdown / luastatus

universal status bar content generator
GNU General Public License v3.0
295 stars 12 forks source link

fs: Add the 'globs' option #50

Closed cdlscpmv closed 5 years ago

shdown commented 5 years ago
  1. What’s the use case? If the list of matches does not change, it can be done on the Lua side.

  2. So, if paths contain non-existing (or non-accessible) paths, it will silently swallow the errors? E.g. opts = {paths = {'/', '/home', '/asdfdasfdasfsadfdssdf'}}

cdlscpmv commented 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.

cdlscpmv commented 5 years ago

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?

shdown commented 5 years ago

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.

cdlscpmv commented 5 years ago

Consider adding globs option in addition to paths.

Will do!

cdlscpmv commented 5 years ago

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.

cdlscpmv commented 5 years ago

Thank you for guidance. At this point you wrote the whole code by yourself =).

shdown commented 5 years ago

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 :)