mirror of
https://github.com/nix-community/comma.git
synced 2024-10-26 05:58:05 +03:00
Override choice picker through COMMA_PICKER
Added test for the picker so it fails with a message rather than "no match".
This commit is contained in:
parent
4a62ec17e2
commit
11e5b5a519
15
,
15
,
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# usage example:
|
# usage example:
|
||||||
# $ , yarn --help
|
# $ , yarn --help
|
||||||
@ -6,6 +6,17 @@
|
|||||||
# If there are multiple candidates, the user chooses one using `fzy`.
|
# If there are multiple candidates, the user chooses one using `fzy`.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
picker=fzy
|
||||||
|
if [ -n "${COMMA_PICKER+1}" ]; then
|
||||||
|
picker="${COMMA_PICKER}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test that the picker exists
|
||||||
|
if ! [ -x "$(command -v "${picker}")" ]; then
|
||||||
|
>&2 echo "picker ${picker} is not found in PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $# -lt 1 ]]; then
|
if [[ $# -lt 1 ]]; then
|
||||||
>&2 echo "usage: , <program> [arguments]"
|
>&2 echo "usage: , <program> [arguments]"
|
||||||
exit 1
|
exit 1
|
||||||
@ -27,7 +38,7 @@ case "${argv0}" in
|
|||||||
*)
|
*)
|
||||||
attr="$(nix-locate --db "${NIX_INDEX_DB}" --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
|
attr="$(nix-locate --db "${NIX_INDEX_DB}" --top-level --minimal --at-root --whole-name "/bin/${argv0}")"
|
||||||
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then
|
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then
|
||||||
attr="$(echo "${attr}" | fzy)"
|
attr="$(echo "${attr}" | "${picker}")"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user