mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 21:37:58 +03:00
df: Add an option to print the human readable sizes in powers of 10
This commit is contained in:
parent
dd582e4ae3
commit
ae36a80a6c
Notes:
sideshowbarker
2024-07-17 01:39:16 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/ae36a80a6c Pull-request: https://github.com/SerenityOS/serenity/pull/16944 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/supercomputer7 ✅
@ -26,11 +26,13 @@ struct FileSystem {
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
bool flag_human_readable = false;
|
||||
bool flag_human_readable_si = false;
|
||||
bool flag_inode_info = false;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("Display free disk space of each partition.");
|
||||
args_parser.add_option(flag_human_readable, "Print human-readable sizes", "human-readable", 'h');
|
||||
args_parser.add_option(flag_human_readable_si, "Print human-readable sizes in SI units", "si", 'H');
|
||||
args_parser.add_option(flag_inode_info, "Show inode information as well", "inodes", 'i');
|
||||
args_parser.parse(arguments);
|
||||
|
||||
@ -80,10 +82,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
out("{:12} ", fs);
|
||||
|
||||
if (flag_human_readable) {
|
||||
out("{:>12} ", human_readable_size(total_block_count * block_size));
|
||||
out("{:>12} ", human_readable_size(used_block_count * block_size));
|
||||
out("{:>12} ", human_readable_size(free_block_count * block_size));
|
||||
bool human_readable = flag_human_readable || flag_human_readable_si;
|
||||
auto human_readable_based_on = flag_human_readable_si ? AK::HumanReadableBasedOn::Base10 : AK::HumanReadableBasedOn::Base2;
|
||||
|
||||
if (human_readable) {
|
||||
out("{:>12} ", human_readable_size(total_block_count * block_size, human_readable_based_on));
|
||||
out("{:>12} ", human_readable_size(used_block_count * block_size, human_readable_based_on));
|
||||
out("{:>12} ", human_readable_size(free_block_count * block_size, human_readable_based_on));
|
||||
out("{:>11}% ", used_percentage);
|
||||
} else {
|
||||
out("{:>12} ", (uint64_t)total_block_count);
|
||||
@ -93,10 +98,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
}
|
||||
|
||||
if (flag_inode_info) {
|
||||
if (flag_human_readable) {
|
||||
out("{:>12} ", human_readable_quantity(total_inode_count));
|
||||
out("{:>12} ", human_readable_quantity(used_inode_count));
|
||||
out("{:>12} ", human_readable_quantity(free_inode_count));
|
||||
if (human_readable) {
|
||||
out("{:>12} ", human_readable_quantity(total_inode_count, human_readable_based_on));
|
||||
out("{:>12} ", human_readable_quantity(used_inode_count, human_readable_based_on));
|
||||
out("{:>12} ", human_readable_quantity(free_inode_count, human_readable_based_on));
|
||||
out("{:>11}% ", used_inode_percentage);
|
||||
} else {
|
||||
out("{:>12} ", (uint64_t)total_inode_count);
|
||||
|
Loading…
Reference in New Issue
Block a user