mirror of
https://github.com/nix-community/comma.git
synced 2024-10-26 05:58:05 +03:00
45 lines
882 B
Bash
Executable File
45 lines
882 B
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# usage example:
|
|
# $ , yarn --help
|
|
# This finds a derivation providing a bin/yarn, and runs it with `nix run`.
|
|
# If there are multiple candidates, the user chooses one using `fzy`.
|
|
set -euo pipefail
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
>&2 echo "usage: , <program> [arguments]"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$1" == "--install" ]] || [[ "$1" == "-i" ]]; then
|
|
install=1
|
|
shift
|
|
else
|
|
install=""
|
|
fi
|
|
|
|
argv0=$1; shift
|
|
|
|
case "${argv0}" in
|
|
@OVERLAY_PACKAGES@)
|
|
attr="${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
|
|
attr="$(echo "${attr}" | fzy)"
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
if [[ -z $attr ]]; then
|
|
>&2 echo "no match"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n $install ]]; then
|
|
nix-env -iA "nixpkgs.${attr%%.*}"
|
|
else
|
|
nix run "nixpkgs.${attr}" -c "${argv0}" "$@"
|
|
fi
|