Skip to content

Commit 5f363a5

Browse files
authored
Simplify fallback example
1 parent 2bd3532 commit 5f363a5

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,26 +257,22 @@ the user starts navigating the selector.
257257
### Using `bkt` only if installed
258258

259259
You may want to distribute shell scripts that utilize `bkt` without requiring
260-
every user also install `bkt`. By wrapping `bkt` in a shell function your script
261-
can cleanly invoke `bkt` if available without complicating your users' workflow.
262-
Of course if they choose to install `bkt` they'll get a faster script as a
263-
result!
260+
every user also install it. By falling back to a no-op shell function when `bkt`
261+
is not available your script can take advantage of it opportunistically without
262+
complicating your users' workflow. Of course if they choose to install `bkt`
263+
they'll get a faster script as a result!
264264

265265
```shell
266266
# Cache commands using bkt if installed
267-
if command -v bkt >&/dev/null; then
268-
bkt() { command bkt "$@"; }
269-
else
267+
if ! command -v bkt >&/dev/null; then
270268
# If bkt isn't installed skip its arguments and just execute directly.
271-
# Optionally write a msg to stderr suggesting users install bkt.
272269
bkt() {
273270
while [[ "$1" == --* ]]; do shift; done
274271
"$@"
275272
}
273+
# Optionally, write a msg to stderr suggesting users install bkt.
274+
echo "Tip: install https://github.com/dimo414/bkt for faster performance" >&2
276275
fi
277-
278-
# Now you can call bkt (the function) just like you'd call bkt (the binary):
279-
bkt --ttl=1m -- expensive_cmd ...
280276
```
281277

282278
### Decorating commands with `bkt` in shell scripts

0 commit comments

Comments
 (0)