Skip to content

Commit

Permalink
Merge branch 'commandlineoptions'
Browse files Browse the repository at this point in the history
- version added
- ls-like sorting flags
- usage info
- closes #13
  • Loading branch information
Ckath committed Aug 31, 2019
2 parents 121f45c + ba7a1e9 commit cce61ca
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
48 changes: 47 additions & 1 deletion fuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,57 @@ refresh_layout()
start_preview(load_preview);
}

static void
usage()
{
fputs("usage: fuf [-aAsStTvh] [PATH]\n"
"-a\tsort alphabetical, this is default\n"
"-A\tsort alphabetical, reversed\n"
"-s\tsort by size\n"
"-S\tsort by size, reversed\n"
"-t\tsort by time\n"
"-T\tsort by time, resersed\n"
"-v\tversion info\n"
"-h\tusage info\n", stderr);
exit(1);
}

int
main(int argc, char *argv[])
{
if (argc > 1) {
chdir(argv[1]);
chdir(argv[argc-1]);
}

/* handle options */
char c;
if ((c = getopt(argc, argv, "aAsStTvh")) != -1) {
switch (c) {
case 'a':
sort = alpha_cmp;
break;
case 'A':
sort = Alpha_cmp;
break;
case 's':
sort = size_cmp;
break;
case 'S':
sort = Size_cmp;
break;
case 't':
sort = time_cmp;
break;
case 'T':
sort = Time_cmp;
break;
case 'v':
puts("fuf-"VERSION);
exit(0);
case 'h':
default:
usage();
}
}

init();
Expand Down
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NAME = fuf
VERSION = 0.1
CFLAGS =
LIBS = -lncurses -lpthread
SRC = ${NAME}.c ext/colors.c ext/sort.c ext/thr.c ext/sysext.c
Expand All @@ -8,7 +9,7 @@ CC = gcc

.c.o:
@echo CC -c ${CFLAGS} $<
@${CC} -c ${CFLAGS} $< ${LIBS} -o ${<:.c=.o}
@${CC} -c ${CFLAGS} -DVERSION=\"${VERSION}\" $< ${LIBS} -o ${<:.c=.o}

${NAME}: ${SRC} ${OBJ}
@echo CC -o $@
Expand Down

0 comments on commit cce61ca

Please sign in to comment.