[HN Gopher] Ohmyksh: A Framework for OpenBSD's Ksh
___________________________________________________________________
Ohmyksh: A Framework for OpenBSD's Ksh
Author : ecliptik
Score : 56 points
Date : 2024-04-06 09:51 UTC (13 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| t-3 wrote:
| Nice! 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 wrote:
| Is your script available somewhere?
| t-3 wrote:
| #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 wrote:
| Consider using isdigit.
| sgt wrote:
| Mandatory link whenever Korn Shell is mentioned:
|
| http://www.kornshell.com/fun/band.gif
| therealfiona wrote:
| Down 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 wrote:
| "It's easier to port a shell than it is to port a shell script"
|
| (Larry Wall)
| pjmlp wrote:
| On 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.
| GrumpySloth wrote:
| Honestly 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 wrote:
| I 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
___________________________________________________________________
(page generated 2024-04-06 23:01 UTC)