3 ms·
I was going to suggest that somebody try this in Oil shell, which can now run thousands of lines of bash completion scripts [1], but I can already see it won't
by chubot 8y ago
I was going to suggest that somebody try this in Oil shell, which can now run thousands of lines of bash completion scripts [1], but I can already see it won't work because of the VERSION DETECTION anti-pattern.
https://github.com/antonmedv/fx-completion/blob/master/complete.sh https://github.com/antonmedv/fx-completion/blob/master/compl...
if [[ -n "${BASH_VERSION}" ]]; then
# ...
else
echo "Unsupported shell."
exit 1
fi
The better thing to do is FEATURE DETECTION, e.g. with 'eval'.
Does anyone know of a concise resource for explaining feature vs. version detection? I don't find that many great resources on Google.
Here's a page, which is OK but leaves a lot to be desired.
https://en.wikipedia.org/wiki/Feature_detection_(web_development) https://en.wikipedia.org/wiki/Feature_detection_(web_develop...
It feels like I need to write a blog post to explain this, since this knowledge seems to be waning. I recall reading about it 10+ years ago, but not recently.
Richard Stallman understood it very well and IIRC strongly advocated for feature detection in autoconf. (Despite all the bad things about autoconf, it does actually work on tons of platforms, and it's solving a hard problem. It wouldn't "scale" if it were using version detection.)
Here's an outline of a blog post:
1. Version/browser detection is why the User-Agent string from Internet Explorer, Chrome, Safari, Edge, etc. all start with "Mozilla". Fun fact: if everyone used feature detection, we could have saved exabytes of data transfer over the last 20 years by trimming 10-50 bytes from every single HTTP request ever made.
2. jQuery switched from version detection to feature detection early in its life. I recall some threads where Resig was criticized for this, and then he saw the light.
3. Likewise, the LLVM toolchain has to pretend its GNU in some cases because applications are using version detection: https://news.ycombinator.com/item?id=15195370 https://news.ycombinator.com/item?id=15195370
4. Autoconf is based on feature detection.
5. My hand-written configure script also uses feature detection, e.g. to detect the presence of the readline library. It basically tries to compile a small program with the C compiler. There are various tricks in this domain.
6. eval is useful for feature detection in dynamic programming languages. In fact, this might be the ONLY thing eval is good for! (exaggerating a bit)
[1] http://www.oilshell.org/blog/2019/02/05.html http://www.oilshell.org/blog/2019/02/05.html
- medv 8y agoFeel free to send a PR with feature detection. =)