From e05c4f8d229445c74bab960351e8162a8535764d Mon Sep 17 00:00:00 2001 From: Ruthenic Date: Thu, 12 Aug 2021 16:40:37 -0400 Subject: [PATCH] `ls`: add proper short option handling. Now a command such as `ls -caC` is valid, and will be interpreted the same as `ls --color --all --columns` --- src/ls.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ls.c b/src/ls.c index a2ab207..b34bad1 100644 --- a/src/ls.c +++ b/src/ls.c @@ -94,9 +94,9 @@ int main(int argc, char **argv) { return 0; } else if (!strcmp(arg, "--color") || !strcmp(arg, "--colour")) { colour = true; - } else if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) { + } else if (!strcmp(arg, "--all")) { showdot = true; - } else if (!strcmp(arg, "-C") || !strcmp(arg, "--columns")) { + } else if (!strcmp(arg, "--columns")) { maxLen = 0; } else if (startsWithStr("--width", arg)) { char widthstr[100]; // if someone has a longer width than this, then owo @@ -107,6 +107,16 @@ int main(int argc, char **argv) { n++; } maxLen = atoi(widthstr); + } else if (arg[0] == '-') { + for (int i = 1; (size_t)i < strlen(arg); i++) { + if (arg[i] == 'c') { + colour = true; + } else if (arg[i] == 'C') { + maxLen = 0; + } else if (arg[i] == 'a') { + showdot = true; + } + } } else { // TODO: interpret absolute *and* relative paths. can't be that hard, // right?