4 ms·
Ohmyksh: A Framework for OpenBSD's Ksh
- t-3 3y agoNice! I used to use a similar script for generating completions for man and doas, but I ended up writing a simple C program to make the list, which is fast enough that no cache is needed.
- mattl 3y agoIs your script available somewhere?
- t-3 3y ago#include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <dirent.h> #include <string.h> void list(char* dir) { DIR* d; struct dirent* dp; if (!(d = opendir(dir))) return; while ((dp = readdir(d)) != NULL) { int namelen = strlen(dp->d_name); if (dp->d_type == DT_DIR) { if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..") == 0)) continue; char p[1024]; snprintf(p, sizeof(p), "%s/%s", dir, dp->d_name); list(p); } else if (((dp->d_name[namelen-1] == '1') || (dp->d_name[namelen-1] == '2') || (dp->d_name[namelen-1] == '3') || (dp->d_name[namelen-1] == '4') || (dp->d_name[namelen-1] == '5') || (dp->d_name[namelen-1] == '6') || (dp->d_name[namelen-1] == '7') || (dp->d_name[namelen-1] == '8') || (dp->d_name[namelen-1] == '9')) && (dp->d_name[namelen-2] == '.')) { write(1, dp->d_name, namelen-2); write(1, "\n", 1); } } closedir(d); } int main() { char* path = getenv("MANPATH"); char* dir; for (dir = strsep(&path, ":"); dir != NULL; dir = strsep(&path, ":")) { list(dir); } return 0; } To use it, just compile and place in your path (I have it as lsm): set -A complete_man -- $(lsm | sort | uniq) I wrote it by just copying and slightly modifying the example in the opendir/readdir man page, it can probably be improved.
- tedunangst 3y agoConsider using isdigit.
- sgt 3y agoMandatory link whenever Korn Shell is mentioned: http://www.kornshell.com/fun/band.gif http://www.kornshell.com/fun/band.gif
- therealfiona 3y agoDown with KSH!!! I worked for a place that used it heavily. When Suse removed the old KSH from their OS, it broke a lot of scripts. This taught me the importance of portable scripts. I do my best to write my shell scripts in POSIX compliant Sh these days. Sometimes I need Bash...
- rvense 3y ago"It's easier to port a shell than it is to port a shell script" (Larry Wall)
- pjmlp 3y agoOn the other hand, a couple of years ago, I ported an ETL infrastructure written in a mix of ksh and utility programs, originally written for Aix, into Java because whoever was taking ownership of the system lacked UNIX experience, and for whatever reason they decided porting them into Java was a great idea. Not surprisingly, the whole ETL/SFTP workflow got a tad bit slower.
- steve1977 3y agoI mean KornShell is POSIX compliant (and some systems go as far to actually call it the POSIX shell).
- GrumpySloth 3y agoHonestly I blame Ohmyzsh for zsh's reputation of having inscrutable configuration and being bloated or sometimes slow. Those configuration frameworks make people helpless when they need to debug their config or make it do something new that doesn’t have a ready-made stackoverflow answer or a plugin. And for comparatively little benefit.
- bbkane 3y agoI also blame the bad zsh docs. I'm trying to write a zsh completion script for a CLI I wrote and I'm intimidated by the lack of examples in the official docs. I'm forced to turn to 3rd party examples and they have differences between them
- deleted 3y ago[deleted]
- inkyoto 3y agoksh does not get enough love it deserves as it is the living ancestor of both, bash and zsh, shells that have inherited, improved upon and extended many features. It has also been a life saver on proprietory UNIX platforms where the default sh was usually the plain sh, with ksh always being available and having the command line editing available («set -o emacs» or «set -o vi») and GNU readline being unavailable. The POSIX shell is effectively ksh.