Skip to content

bug fixes, speed improvements, improve shell support#68

Merged
ThatOneCalculator merged 5 commits into
ThatOneCalculator:mainfrom
rrotter:misc_fixes
Jun 7, 2025
Merged

bug fixes, speed improvements, improve shell support#68
ThatOneCalculator merged 5 commits into
ThatOneCalculator:mainfrom
rrotter:misc_fixes

Conversation

@rrotter
Copy link
Copy Markdown
Contributor

@rrotter rrotter commented Jun 7, 2025

This is a bit of a catch-all. I kept each commit discrete by topic, but there are several topics covered in this PR. Each commit should apply cleanly in any order, so if you don't like all of them, feel free to mix and match. Or, if you prefer, I could resubmit them as more than one PR.

faster

hyperfine results:

macos before after percent
dash 42.0 ms ± 1.1 ms 35.1 ms ± 0.6 ms 16%
bash 44.3 ms ± 0.5 ms 36.9 ms ± 0.5 ms 16%
zsh 45.9 ms ± 1.0 ms 38.7 ms ± 0.8 ms 16%
debian 12 before after percent
dash 6.4 ms ± 0.9 ms 4.2 ms ± 0.6 ms 34%
bash 8.2 ms ± 1.0 ms 5.2 ms ± 0.7 ms 36%
zsh 8.6 ms ± 1.0 ms 5.6 ms ± 0.8 ms 35%

fixed compatibility with zsh, osh, mksh

before:

NerdFetch % zsh nerdfetch
expr: not a decimal number: '53562.25'
expr: syntax error

      ___     rrotter@mond
     (.. \      macOS 15.5
     (<> |      24.5.0
    //  \ \   󰍛  53562.25/65536 MiB (%)
   ( |  | /|  󰏔  104 (brew)
  _/\ __)/_)  󰅶  10 days, 6 hours, 53 mins
  \/-____\/     ██████████████████
NerdFetch % osh nerdfetch
getprop: not found
  283583.
        ^
./nerdfetch:1: Unexpected token while parsing arithmetic: '.'
  283583.
        ^
./nerdfetch:1: fatal: Parse error in recursive arithmetic
NerdFetch % mksh nerdfetch
expr: division by zero
expr: syntax error

      ___     rrotter@mond
     (.. \      macOS 15.5
     (<> |      24.5.0
    //  \ \   󰍛  367/0 MiB (%)
   ( |  | /|  󰏔  104 (brew)
  _/\ __)/_)  󰅶  10 days, 6 hours, 53 mins
  \/-____\/     ██████████████████

after:

NerdFetch % zsh nerdfetch; osh nerdfetch; mksh nerdfetch

      ___     rrotter@mond
     (.. \      macOS 15.5
     (<> |      24.5.0
    //  \ \   󰍛  53832/65536 MiB (82)%
   ( |  | /|  󰏔  104 (brew)
  _/\ __)/_)  󰅶  10 days, 7 hours, 33 mins
  \/-____\/     ██████████████████

      ___     rrotter@mond
     (.. \      macOS 15.5
     (<> |      24.5.0
    //  \ \   󰍛  53847/65536 MiB (82)%
   ( |  | /|  󰏔  104 (brew)
  _/\ __)/_)  󰅶  10 days, 7 hours, 33 mins
  \/-____\/     ██████████████████

      ___     rrotter@mond
     (.. \      macOS 15.5
     (<> |      24.5.0
    //  \ \   󰍛  53832/65536 MiB (82)%
   ( |  | /|  󰏔  104 (brew)
  _/\ __)/_)  󰅶  10 days, 7 hours, 33 mins
  \/-____\/     ██████████████████

rrotter added 3 commits June 6, 2025 19:54
`command -v` is supposted to fail silently, but on osh it prints to
stderr upon failure. Redirect stderr to /dev/null so this isn't
displayed. Won't affect other shells.
Add a third parameter to `read` when parsing vm_stat output. Without
this `zsh` and `osh` both fail to remove the trailing `.`. This change
has no affect on other shells.
- use parameter expansion rather than sed to trim "-query"
- don't bother trimming "*/usr/", not needed since f2c15fa
Comment thread nerdfetch Outdated
rrotter added 2 commits June 7, 2025 17:36
- replace use of sed, basename, cut with parameter expansion
- remove $shell variable that was unused (if it's needed it should be
  outside of the Linux section)
- replace expr with $((..))
- remove redundant echo and resulting subshell
mksh is limited to 32-bit integers, which causes it to overflow when
calculating memory on macos and bsd. This same limitation should affect
any shell running on a 32-bit system with >=4GB of memory. In order to
fix this:

- change order of mutliply and divide when calculating memory in use,
  this should work for up to 4TiB of memory (rather than 4GiB previously)
- for total memory there isn't so easy a solution, so fall back to expr
  if we calculate we have 0 MiB of total memory
@ThatOneCalculator
Copy link
Copy Markdown
Owner

Thank you so much! Because there are a lot of individual changes, I will take the time to test this manually on my own machines with different configurations just to ensure that everything works as expected, so I may hold off on merging this until tomorrow or Monday – but when I do, this will likely mark 8.4.0.

@ThatOneCalculator
Copy link
Copy Markdown
Owner

Reviewed in multiple setups, hitting this with a good ol' LGTM!

@ThatOneCalculator ThatOneCalculator merged commit 17b5aff into ThatOneCalculator:main Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants