aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-05-22 01:50:46 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-05-22 01:50:46 -0700
commit3a2438dc081e624570a000e2e3c5617837ba0892 (patch)
treefe228675386196853b663764ab3281dd1454d34b
parentf9eabe730dfadedf2a029dc584ea2f36b3339e60 (diff)
Better arg parsing and updated docs
-rw-r--r--bb.17
-rw-r--r--bb.c26
2 files changed, 25 insertions, 8 deletions
diff --git a/bb.1 b/bb.1
index 10d09af..bbcef27 100644
--- a/bb.1
+++ b/bb.1
@@ -7,6 +7,7 @@ bb \- A bitty browser for command line file management
.B bb
[\fI-d\fR]
[\fI-s\fR]
+[\fI-0\fR]
[\fIdirectory\fR]
.SH DESCRIPTION
\fBbb\fR is a tiny TUI console application for browsing and managing files.
@@ -17,6 +18,10 @@ Print the current directory on exit.
.B \-s
Print the selected files on exit.
+.B \-s
+If printing the selected files on exit, use NULL-terminated strings instead of
+newline-separated.
+
.B directory
Open to this directory.
@@ -48,7 +53,7 @@ Begin browsing in /usr/local/
.TP
.B
-bb -s | xargs zip archive.zip
+bb -s -0 | xargs -0 zip archive.zip
Select some files to add to a zip archive.
.TP
diff --git a/bb.c b/bb.c
index 633cc3a..4a95186 100644
--- a/bb.c
+++ b/bb.c
@@ -952,13 +952,25 @@ int main(int argc, char *argv[])
char sep = '\n';
int print_dir = 0, print_selection = 0;
for (int i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-d") == 0) {
- print_dir = 1;
- } else if (strcmp(argv[i], "-0") == 0) {
- sep = '\0';
- } else if (strcmp(argv[i], "-s") == 0) {
- print_selection = 1;
- } else if (path[0]) {
+ if (argv[i][0] == '-' && argv[i][1] == '-')
+ continue;
+ if (argv[i][0] == '-') {
+ for (char *c = &argv[i][1]; *c; c++) {
+ switch (*c) {
+ case 'd':
+ print_dir = 1;
+ break;
+ case '0':
+ sep = '\0';
+ break;
+ case 's':
+ print_selection = 1;
+ break;
+ }
+ }
+ continue;
+ }
+ if (argv[i][0]) {
path = argv[i];
break;
}