Skip to content

Add mac support for cooldowns.sh#1

Merged
mprpic merged 7 commits intomprpic:mainfrom
pdufour:pdufour/mac-support
Apr 30, 2026
Merged

Add mac support for cooldowns.sh#1
mprpic merged 7 commits intomprpic:mainfrom
pdufour:pdufour/mac-support

Conversation

@pdufour
Copy link
Copy Markdown
Contributor

@pdufour pdufour commented Apr 24, 2026

Background
Some of the commands are not mac osx compatible + it doesn't look in places like ~/.zshrc

Specific Changes

  • Add cross-compatible sed wrapper
  • Add cross-compatible date wrapper
  • Replace grep -oP with cross-compatible version
  • Add support for searching in ~/.zshrc

Test Plan

Test on Linux (regression test):

docker run --rm \
  -v "$HOME/.local/bin/cooldowns.sh:/usr/local/bin/cooldowns.sh:ro" \
  debian:stable-slim \
  bash -c '
    for t in pip uv npm pnpm yarn bun deno cargo; do
      cooldowns.sh set "$t" 7d
    done
    . /etc/profile.d/cooldowns.sh
    echo
    cooldowns.sh check
    echo
    echo "=== /etc/profile.d/cooldowns.sh ==="
    cat /etc/profile.d/cooldowns.sh
  '

Test on Mac

(
  export HOME=$(mktemp -d)
  export SHELL=/bin/zsh
  trap 'rm -rf "$HOME"' EXIT
  for t in pip uv npm pnpm yarn bun deno cargo; do
    cooldowns.sh set "$t" 7d
  done
  . "$HOME/.zshrc"
  echo
  cooldowns.sh check
  echo
  echo "=== ~/.zshrc ==="
  cat "$HOME/.zshrc"
)

Copy link
Copy Markdown
Owner

@mprpic mprpic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for the PR! Just one minor comment to address.

Comment thread cooldowns.sh Outdated
@mprpic
Copy link
Copy Markdown
Owner

mprpic commented Apr 24, 2026

Optional if you feel like it: your test plan could be converted into a CI workflow that runs those same instructions to validate some of script's functionality.

@pdufour
Copy link
Copy Markdown
Contributor Author

pdufour commented Apr 29, 2026

Great idea, addressed comments and added the GH workflows! You can see the tests passing here - https://github.com/pdufour/cooldowns/actions/runs/25094497004/job/73527930256.

@pdufour
Copy link
Copy Markdown
Contributor Author

pdufour commented Apr 29, 2026

@mprpic

@mprpic mprpic merged commit 52458d0 into mprpic:main Apr 30, 2026
2 checks passed
@quinncomendant
Copy link
Copy Markdown

This doesn't work on macOS Sequoia 15.7.5:

date_to_epoch()   { date -j -f '%Y-%m-%d' "$1" +%s 2>/dev/null; }

Example:

❯ date -j -f %Y-%m-%d P7D +%s
Failed conversion of ``P7D'' using format ``%Y-%m-%d''
date: illegal time format
usage: date [-jnRu] [-I[date|hours|minutes|seconds|ns]] [-f input_fmt]
            [ -z output_zone ] [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

And the error is masked because of the use of 2>/dev/null. :(

@mprpic
Copy link
Copy Markdown
Owner

mprpic commented May 5, 2026

This doesn't work on macOS Sequoia 15.7.5:

date_to_epoch()   { date -j -f '%Y-%m-%d' "$1" +%s 2>/dev/null; }

Example:

❯ date -j -f %Y-%m-%d P7D +%s
Failed conversion of ``P7D'' using format ``%Y-%m-%d''
date: illegal time format
usage: date [-jnRu] [-I[date|hours|minutes|seconds|ns]] [-f input_fmt]
            [ -z output_zone ] [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

And the error is masked because of the use of 2>/dev/null. :(

Ha, that's because pip 26.1 now has the relative duration days feature: https://pip.pypa.io/en/stable/news/#v26-1

Prior versions only allowed direct timestamps (like %Y-%m-%d) so the parsing would was never expected to handle values such as P7D. I filed an issue to update the site (and script) to handle this: #3

@quinncomendant
Copy link
Copy Markdown

Ha, that's because pip 26.1 now has the relative duration days feature: https://pip.pypa.io/en/stable/news/#v26-1

Oh, of course – P7D was coming from my configuration value. 😆

Thanks for catching that!

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.

3 participants