mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 23:11:34 +03:00
du: Add an option to print the human readable sizes in powers of 10
This commit is contained in:
parent
ae36a80a6c
commit
b1c7575769
Notes:
sideshowbarker
2024-07-17 01:39:12 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/b1c7575769 Pull-request: https://github.com/SerenityOS/serenity/pull/16944 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/supercomputer7 ✅
@ -26,6 +26,7 @@ struct DuOption {
|
||||
};
|
||||
|
||||
bool human_readable = false;
|
||||
bool human_readable_si = false;
|
||||
bool all = false;
|
||||
bool apparent_size = false;
|
||||
i64 threshold = 0;
|
||||
@ -97,6 +98,7 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<DeprecatedString>& fi
|
||||
args_parser.add_option(du_option.all, "Write counts for all files, not just directories", "all", 'a');
|
||||
args_parser.add_option(du_option.apparent_size, "Print apparent sizes, rather than disk usage", "apparent-size", 0);
|
||||
args_parser.add_option(du_option.human_readable, "Print human-readable sizes", "human-readable", 'h');
|
||||
args_parser.add_option(du_option.human_readable_si, "Print human-readable sizes in SI units", "si", 0);
|
||||
args_parser.add_option(du_option.max_depth, "Print the total for a directory or file only if it is N or fewer levels below the command line argument", "max-depth", 'd', "N");
|
||||
args_parser.add_option(summarize, "Display only a total for each argument", "summarize", 's');
|
||||
args_parser.add_option(du_option.threshold, "Exclude entries smaller than size if positive, or entries greater than size if negative", "threshold", 't', "size");
|
||||
@ -174,6 +176,8 @@ ErrorOr<u64> print_space_usage(DeprecatedString const& path, DuOption const& du_
|
||||
|
||||
if (du_option.human_readable) {
|
||||
out("{}", human_readable_size(size));
|
||||
} else if (du_option.human_readable_si) {
|
||||
out("{}", human_readable_size(size, AK::HumanReadableBasedOn::Base10));
|
||||
} else {
|
||||
out("{}", ceil_div(size, du_option.block_size));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user