Skip to content

Commit 666ea9f

Browse files
committed
Add select reference
1 parent bb272a4 commit 666ea9f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

book.org

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,23 @@
11961196
}
11971197
#+end_src
11981198

1199+
Well... after implementing this, I discovered `select`, which allows for these kinds of flows:
1200+
1201+
#+begin_src bash
1202+
mute command -v fzf ||
1203+
fzf() {
1204+
local in=$(cat)
1205+
for p in "${@}"; do
1206+
[ "$p" = "-0" ] && [ "$(echo "$in" | wc -l)" -eq 1 ] && [ "" = "$in" ] && return 1
1207+
[ "$p" = "-1" ] && [ "$(echo "$in" | wc -l)" -eq 1 ] && [ "" != "$in" ] && echo "$in" && return
1208+
done
1209+
select opt in $(echo "$in"); do
1210+
[ -n "$opt" ] && break
1211+
done >/dev/tty </dev/tty
1212+
echo $opt
1213+
}
1214+
#+end_src
1215+
11991216
** change loops for "mapping/reducing" functions
12001217
*** find
12011218
Many times we want to run the same operation or test to lots of
@@ -1641,6 +1658,9 @@ a kind of rails generators for these helpers
16411658
any eq_--help "$@" && usage
16421659
#+end_src
16431660

1661+
All these last metaprogramming tricks are not thread safe, and even
1662+
though it's mostly ok if you use them in isolation, maybe pipes or
1663+
coprocs would mess up your inline functions.
16441664

16451665
* Interactive
16461666
** Save your small scripts

0 commit comments

Comments
 (0)