diff options
-rw-r--r-- | bfs.1 | 16 | ||||
-rw-r--r-- | parse.c | 7 | ||||
-rw-r--r-- | printf.c | 9 | ||||
-rwxr-xr-x | tests.sh | 6 | ||||
-rw-r--r-- | tests/test_printf_w.out | 0 |
5 files changed, 37 insertions, 1 deletions
@@ -627,6 +627,22 @@ Actions: .TP .B \-nohidden Filter out hidden files and directories. +.LP +\fB\-printf \fIFORMAT\fR +.br +\fB\-fprintf \fIFORMAT FILE\fR +.RS +These additional format directives are supported: +.TP +%w +The file's birth time, in the same format as %a/%c/%t. +.TP +.RI %W k +Field +.I k +of the file's birth time, in the same format as +.RI %A k /%C k /%T k . +.RE .SH EXAMPLES .TP .B bfs @@ -2406,7 +2406,7 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) { cfprintf(cout, " %{blu}-Btime%{rs} %{bld}[-+]N%{rs}\n"); cfprintf(cout, " Find files Birthed %{bld}N%{rs} minutes/days ago\n"); cfprintf(cout, " %{blu}-Bnewer%{rs} %{bld}FILE%{rs}\n"); - cfprintf(cout, " Find files Birthed more recently than %{bld}FILEa%{rs} was modified\n"); + cfprintf(cout, " Find files Birthed more recently than %{bld}FILE%{rs} was modified\n"); cfprintf(cout, " %{blu}-depth%{rs} %{bld}[-+]N%{rs}\n"); cfprintf(cout, " Find files with depth %{bld}N%{rs}\n"); cfprintf(cout, " %{blu}-gid%{rs} %{bld}NAME%{rs}\n"); @@ -2448,6 +2448,11 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) { cfprintf(cout, " %{blu}-nohidden%{rs}\n"); cfprintf(cout, " Match hidden files, or filter them out\n\n"); + cfprintf(cout, " %{blu}-printf%{rs} %{bld}FORMAT%{rs}\n"); + cfprintf(cout, " %{blu}-fprintf%{rs} %{bld}FORMAT%{rs} %{bld}FILE%{rs}\n"); + cfprintf(cout, " The additional format directives %%w and %%W%{bld}k%{rs} for printing file birth times\n"); + cfprintf(cout, " are supported.\n\n"); + cfprintf(cout, "%s\n", BFS_HOMEPAGE); state->just_info = true; @@ -81,6 +81,7 @@ static int bfs_printf_flush(FILE *file, const struct bfs_printf_directive *direc */ static const struct timespec *get_time_field(const struct bfs_stat *statbuf, enum bfs_stat_field stat_field) { if (!(statbuf->mask & stat_field)) { + errno = ENOTSUP; return NULL; } @@ -700,6 +701,11 @@ struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline) directive->fn = bfs_printf_U; command->needs_stat = true; break; + case 'w': + directive->fn = bfs_printf_ctime; + directive->stat_field = BFS_STAT_BTIME; + command->needs_stat = true; + break; case 'y': directive->fn = bfs_printf_y; break; @@ -716,6 +722,9 @@ struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline) case 'T': directive->stat_field = BFS_STAT_MTIME; goto directive_strftime; + case 'W': + directive->stat_field = BFS_STAT_BTIME; + goto directive_strftime; directive_strftime: directive->fn = bfs_printf_strftime; @@ -394,6 +394,7 @@ bfs_tests=( test_execdir_plus test_hidden test_nohidden + test_printf_w test_path_flag_expr test_path_expr_flag test_flag_expr_path @@ -1290,6 +1291,11 @@ function test_printf_nul() { fi } +function test_printf_w() { + # Birth times may not be supported, so just check that %w/%W can be parsed + bfs_diff times -false -printf '%w %WY\n' +} + function test_fstype() { fstype="$(invoke_bfs -printf '%F\n' | head -n1)" bfs_diff basic -fstype "$fstype" diff --git a/tests/test_printf_w.out b/tests/test_printf_w.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_printf_w.out |