colindean / hejmo

My home directory and package management stuff, inelegant as it may be
17 stars 1 forks source link

Speed up cacheable commands with bkt #25

Open colindean opened 2 years ago

colindean commented 2 years ago

https://github.com/dimo414/bkt

Def. use the "decorator" method for it:

# Cache commands using bkt if installed
if command -v bkt >&/dev/null; then
  bkt() { command bkt "$@"; }
else
  # If bkt isn't installed skip its arguments and just execute directly.
  # Optionally write a msg to stderr suggesting users install bkt.
  bkt() {
    while [[ "$1" == --* ]]; do shift; done
    "$@"
  }
fi

# Now you can call bkt (the function) just like you'd call bkt (the binary):
bkt -- expensive_cmd ...