Introduction
Introduction Statistics Contact Development Disclaimer Help
Add -c option to enable colors - noice - small file browser (mirror / fork from…
git clone git://git.codemadness.org/noice
Log
Files
Refs
README
LICENSE
---
commit cd633c1a0a69dcd6c96079dd922820d09d8d992b
parent e139b27c273b9542d9891e2a7f2395cfa9ff50ad
Author: sin <[email protected]>
Date: Fri, 23 Aug 2019 11:11:06 +0100
Add -c option to enable colors
Diffstat:
M Makefile | 2 +-
A arg.h | 50 +++++++++++++++++++++++++++++…
M noice.1 | 8 +++++++-
M noice.c | 22 ++++++++++++++++------
4 files changed, 74 insertions(+), 8 deletions(-)
---
diff --git a/Makefile b/Makefile
@@ -18,7 +18,7 @@ nopen: $(NOPENOBJ)
$(CC) $(CFLAGS) -o $@ $(NOPENOBJ) $(LDFLAGS) $(NOPENLDLIBS)
dprintf.o: util.h
-noice.o: noiceconf.h util.h
+noice.o: arg.h noiceconf.h util.h
nopen.o: nopenconf.h util.h
spawn.o: util.h
strlcat.o: util.h
diff --git a/arg.h b/arg.h
@@ -0,0 +1,50 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#ifndef ARG_H__
+#define ARG_H__
+
+extern char *argv0;
+
+/* use main(int argc, char *argv[]) */
+#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
+ argv[0] && argv[0][0] == '-'\
+ && argv[0][1];\
+ argc--, argv++) {\
+ char argc_;\
+ char **argv_;\
+ int brk_;\
+ if (argv[0][1] == '-' && argv[0][2] == '\0') {\
+ argv++;\
+ argc--;\
+ break;\
+ }\
+ int i_;\
+ for (i_ = 1, brk_ = 0, argv_ = argv;\
+ argv[0][i_] && !brk_;\
+ i_++) {\
+ if (argv_ != argv)\
+ break;\
+ argc_ = argv[0][i_];\
+ switch (argc_)
+
+#define ARGEND }\
+ }
+
+#define ARGC() argc_
+
+#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
+ ((x), abort(), (char *)0) :\
+ (brk_ = 1, (argv[0][i_+1] != '\0')?\
+ (&argv[0][i_+1]) :\
+ (argc--, argv++, argv[0])))
+
+#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
+ (char *)0 :\
+ (brk_ = 1, (argv[0][i_+1] != '\0')?\
+ (&argv[0][i_+1]) :\
+ (argc--, argv++, argv[0])))
+
+#endif
diff --git a/noice.1 b/noice.1
@@ -1,4 +1,4 @@
-.Dd August 22, 2019
+.Dd August 23, 2019
.Dt NOICE 1
.Os
.Sh NAME
@@ -6,6 +6,7 @@
.Nd small file browser
.Sh SYNOPSIS
.Nm
+.Op Fl c
.Op Ar dir
.Sh DESCRIPTION
.Nm
@@ -81,6 +82,11 @@ Quit.
.Pp
Backing up one directory level will set the cursor position at the
directory you came out of.
+.Sh OPTIONS
+.Bl -tag -width "-c"
+.It Fl c
+Enable colors.
+.El
.Sh CONFIGURATION
.Nm
is configured by modifying
diff --git a/noice.c b/noice.c
@@ -16,6 +16,7 @@
#include <string.h>
#include <unistd.h>
+#include "arg.h"
#include "util.h"
#define ISODD(x) ((x) & 1)
@@ -68,6 +69,7 @@ struct entry {
/* Global context */
struct entry *dents;
+char *argv0;
int ndents, cur;
int idle;
@@ -774,9 +776,9 @@ nochange:
}
void
-usage(char *argv0)
+usage(void)
{
- fprintf(stderr, "usage: %s [dir]\n", argv0);
+ fprintf(stderr, "usage: %s [-c] [dir]\n", argv0);
exit(1);
}
@@ -786,8 +788,16 @@ main(int argc, char *argv[])
char cwd[PATH_MAX], *ipath;
char *ifilter;
- if (argc > 2)
- usage(argv[0]);
+ ARGBEGIN {
+ case 'c':
+ usecolor = 1;
+ break;
+ default:
+ usage();
+ } ARGEND
+
+ if (argc > 1)
+ usage();
/* Confirm we are in a terminal */
if (!isatty(0) || !isatty(1)) {
@@ -799,8 +809,8 @@ main(int argc, char *argv[])
showhidden = 1;
initfilter(showhidden, &ifilter);
- if (argv[1] != NULL) {
- ipath = argv[1];
+ if (argv[0] != NULL) {
+ ipath = argv[0];
} else {
ipath = getcwd(cwd, sizeof(cwd));
if (ipath == NULL)
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.