commit: 590f14ac6dd5c9e2f2cf73e39659ce11646077c0
parent 3472487833d7fe6e1501c28c0b7677d26143caab
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 17 Jan 2025 08:12:37 +0100
cmd/shuf: handle "-" argument
Diffstat:
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/cmd/cat.1 b/cmd/cat.1
@@ -18,7 +18,9 @@ reads each
in sequence and writes it on the standard output.
If no
.Ar file
-is given,
+is given or if
+.Ar file is
+.Qq - ,
.Nm
reads from the standard input.
.Sh OPTIONS
diff --git a/cmd/shuf.1 b/cmd/shuf.1
@@ -24,7 +24,9 @@ reads each
in sequence and writes it on the standard output with some shuffling applied to each line.
If no
.Ar file
-is given,
+is given or if
+.Ar file is
+.Qq - ,
.Nm
reads from the standard input.
.Sh OPTIONS
diff --git a/cmd/shuf.c b/cmd/shuf.c
@@ -175,6 +175,13 @@ main(int argc, char *argv[])
{
for(int i = 0; i < argc; i++)
{
+ if(strncmp(argv[i], "-", 2) == 0)
+ {
+ if(shuf(stdin, "<stdin>") != 0) return 1;
+
+ continue;
+ }
+
FILE *in = fopen(argv[i], "r");
if(shuf(in, argv[i]) != 0)