feat(cli): add mandible-pick helper script for interactive tool selection

This commit is contained in:
Prad Nukala committed 2026-10-08 13:24:00 -04:00
1 parent b1654495a1
commit 015aa83439
1 file changed
+22
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# mandible-pick — pick a tool for mandible (it requires one), then open it.
# fzf over the executables installed on PATH (no shell builtins, keywords or
# aliases). A query with a space, such as "git remote add", or one that
# matches nothing is used as typed (tool + subcommand path).
# Used by the tmux-palette "mandible" item (alias: man).
list() { # portable: no GNU find -printf (macOS)
local d f
IFS=: read -ra dirs <<<"$PATH"
for d in "${dirs[@]}"; do
for f in "$d"/*; do [[ -x $f && ! -d $f ]] && printf '%s\n' "${f##*/}"; done
done
}
# enter: a query with a space ("git remote add") is a tool + subcommand path,
# taken as typed; otherwise the highlighted command, or the query if none.
q=$(list | sort -u | fzf --prompt 'mandible> ' --height 100% --reverse \
--with-shell 'bash -c' \
--bind 'enter:transform:[[ {q} == *" "* ]] && echo print-query || echo accept-or-print-query') || exit 0
[ -n "$q" ] || exit 0
# shellcheck disable=SC2086 # split "git remote" into tool + subcommands
exec mandible $q