sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 9c30fbf0187015cda63620d9043655915f7872f9
parent 6abce61877f79a3cfcb25c9a9d4ddbf4e211f8c7
Author: sin <sin@2f30.org>
Date:   Sat, 21 Feb 2015 09:30:08 +0000

Add ls -A implementation

Thanks joshua@cubesolving.com!

Diffstat:
MREADME | 2+-
Mls.1 | 6++++--
Mls.c | 11+++++++++--
3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/README b/README @@ -41,7 +41,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =* ln yes none =* logger yes none =* logname yes none -= ls no -A, (-C), -R, -S, -f, -m, -n, -s, -x += ls no (-C), -R, -S, -f, -m, -n, -s, -x =* md5sum non-posix none =* mkdir yes none =* mkfifo yes none diff --git a/ls.1 b/ls.1 @@ -1,4 +1,4 @@ -.Dd February 18, 2015 +.Dd February 21, 2015 .Dt LS 1 .Os sbase .Sh NAME @@ -6,7 +6,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm -.Op Fl 1acdFHhiLlqrtUu +.Op Fl 1AacdFHhiLlqrtUu .Op Ar file ... .Sh DESCRIPTION .Nm @@ -14,6 +14,8 @@ lists each given file, and the contents of each given directory. If no files are given the current directory is listed. .Sh OPTIONS .Bl -tag -width Ds +.It Fl A +List all entries except for '.' and '..'. .It Fl a Show hidden files (those beginning with '.'). .It Fl c diff --git a/ls.c b/ls.c @@ -24,6 +24,7 @@ struct entry { ino_t ino; }; +static int Aflag = 0; static int aflag = 0; static int cflag = 0; static int dflag = 0; @@ -204,8 +205,11 @@ lsdir(const char *path) } while ((d = readdir(dp))) { - if (d->d_name[0] == '.' && !aflag) + if (d->d_name[0] == '.' && !aflag && !Aflag) continue; + else if (Aflag) + if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) + continue; if (Uflag){ mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag); output(&ent); @@ -256,7 +260,7 @@ ls(const struct entry *ent) static void usage(void) { - eprintf("usage: %s [-1acdFHhiLlqrtUu] [file ...]\n", argv0); + eprintf("usage: %s [-1AacdFHhiLlqrtUu] [file ...]\n", argv0); } int @@ -269,6 +273,9 @@ main(int argc, char *argv[]) case '1': /* ignore */ break; + case 'A': + Aflag = 1; + break; case 'a': aflag = 1; break;