mathiasbynens / dotfiles

:wrench: .files, including ~/.macos — sensible hacker defaults for macOS
https://mths.be/dotfiles
MIT License
30.01k stars 8.74k forks source link

Replace `wc` by `stat` in `gz` #1044

Open Rudxain opened 1 year ago

Rudxain commented 1 year ago

fixes #1042 . Only did 1 unit test, I haven't tested the whole fn

LucasLarson commented 1 year ago

Thanks to your issue (#1042), I just found out that stat -c is GNU, but that macOS/FreeBSD use stat -f. Also, their format flags don’t match (!) but these both return file size:

# GNU
stat -c '%s' file

# macOS/FreeBSD
stat -f '%z' file

But a heads up, you should add the -L argument (same on both platforms) so that even calling a symlink returns the results you want.

Rudxain commented 1 year ago

stat -c is GNU, but that macOS/FreeBSD use stat -f. Also, their format flags don’t match

Thank you for the info! I'll try to make it cross-platform

But a heads up, you should add the -L argument (same on both platforms) so that even calling a symlink returns the results you want.

That's also useful. I forgot about symlinks

Rudxain commented 1 year ago

I'm getting an error

stat -cL '%s' -- .bash_history
# prints this...
# stat: cannot statx '%s': No such file or directory

@LucasLarson what am I doing wrong?

LucasLarson commented 1 year ago

You want this:

stat -Lc '%s' -- .bash_history

because %s is an argument of the -c option.

Rudxain commented 1 year ago

because %s is an argument of the -c option.

I forgot that flag-ordering matters in rare cases.

Fixing now!

Rudxain commented 1 year ago

Wait, I just noticed targz uses both stats, without a uname -s-based condition. I'll use that "hack" (not really a hack, because it's the simplest most reliable way known)

LucasLarson commented 1 year ago

You may want to keep the -L option dropped in 72303304b8

Rudxain commented 1 year ago

You may want to keep the -L option dropped in 72303304b8

Silly me 😅. I forgot the L when copy-pasting

Rudxain commented 1 year ago

Now it's ready (for real, haha)

I've been busy, and thinking of many things yesterday. It seems my cognitive load was higher than I expected. I apologize (to everyone) for the little mistakes