Skip to content

feat: add numfmt builtin #908

@chaliy

Description

@chaliy

Problem

bashkit has no numfmt command. GNU numfmt converts numbers to/from human-readable format and is used in scripts for formatting disk sizes, byte counts, and other numeric output.

Expected behavior

numfmt --to=iec 1048576
# 1.0M

numfmt --from=iec 1K
# 1024

echo 1048576 | numfmt --to=si
# 1.1M

numfmt --to=iec --suffix=B 1048576
# 1.0MB

Key features to implement

  • --to=si / --to=iec / --to=iec-i (output formatting)
  • --from=si / --from=iec / --from=auto (input parsing)
  • --suffix=SUFFIX (append suffix)
  • --padding=N (pad to width)
  • --round=up|down|from-zero|towards-zero|nearest (rounding mode)
  • --format=FORMAT (printf-style format)
  • --field=N (convert only field N from input)
  • --delimiter=D (field delimiter)

Suggested approach

This is entirely pure logic — number parsing and formatting with no filesystem interaction. uutils/coreutils (MIT) has a complete implementation that could be adapted. It would live in a new numfmt.rs file in crates/bashkit/src/builtins/.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions