sbase

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

commit 2a3f82a5cd9b6712b4e8d501d4f529ec8578c62f
parent 9bd094193d6b77282cb4cf3883147b337230ecda
Author: sin <sin@2f30.org>
Date:   Wed Feb 18 16:29:46 +0000

Implement -u support for ls(1)

Diffstat:
README | 2+-
ls.1 | 7+++++--
ls.c | 15+++++++++++++--
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/README b/README @@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =* ln yes none =* logger yes none =* logname yes none -= ls no -C, -R, -u += ls no -C, -R =* md5sum non-posix none =* mkdir yes none =* mkfifo yes none diff --git a/ls.1 b/ls.1 @@ -1,4 +1,4 @@ -.Dd February 17, 2015 +.Dd February 18, 2015 .Dt LS 1 .Os sbase .Sh NAME @@ -6,7 +6,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm -.Op Fl 1acdFHhiLlqrtU +.Op Fl 1acdFHhiLlqrtUu .Op Ar file ... .Sh DESCRIPTION .Nm @@ -44,6 +44,9 @@ Reverse the sort order. Sort files by last file status/modification time instead of by name. .It Fl U Keep the list unsorted. +.It Fl u +Use file's last access time instead of last modification time for +sorting or printing. .El .Sh SEE ALSO .Xr stat 2 diff --git a/ls.c b/ls.c @@ -37,6 +37,7 @@ static int qflag = 0; static int rflag = 0; static int tflag = 0; static int Uflag = 0; +static int uflag = 0; static int first = 1; static int many; @@ -55,7 +56,12 @@ mkent(struct entry *ent, char *path, int dostat, int follow) ent->uid = st.st_uid; ent->gid = st.st_gid; ent->size = st.st_size; - ent->t = cflag ? st.st_ctime : st.st_mtime; + if (cflag) + ent->t = st.st_ctime; + else if (uflag) + ent->t = st.st_atime; + else + ent->t = st.st_mtime; ent->ino = st.st_ino; if (S_ISLNK(ent->mode)) ent->tmode = stat(path, &st) == 0 ? st.st_mode : 0; @@ -247,7 +253,7 @@ ls(const struct entry *ent) static void usage(void) { - eprintf("usage: %s [-1acdFHhiLlqrtU] [file ...]\n", argv0); + eprintf("usage: %s [-1acdFHhiLlqrtUu] [file ...]\n", argv0); } int @@ -265,6 +271,7 @@ main(int argc, char *argv[]) break; case 'c': cflag = 1; + uflag = 0; break; case 'd': dflag = 1; @@ -299,6 +306,10 @@ main(int argc, char *argv[]) case 'U': Uflag = 1; break; + case 'u': + uflag = 1; + cflag = 0; + break; default: usage(); } ARGEND;