-
-
Save burke/922f495d1d18ce826a47f1ab075123f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
argv0=$1; shift | |
attr="$(nix-locate --top-level --minimal --at-root --whole-name "/bin/${argv0}")" | |
if [[ "$(echo "${attr}" | wc -l)" -ne 1 ]]; then | |
attr="$(echo "${attr}" | fzy)" | |
fi | |
nix run "nixpkgs.${attr}" -c "${argv0}" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, fetchurl, nix-index, nix, fzy, makeWrapper }: | |
stdenv.mkDerivation rec { | |
name = "comma"; | |
src = ./.; | |
buildInputs = [ nix-index.out nix.out fzy.out ]; | |
nativeBuildInputs = [ makeWrapper ]; | |
installPhase = '' | |
mkdir -p $out/bin | |
cp , $out/bin/, | |
chmod +x $out/bin/, | |
wrapProgram $out/bin/, \ | |
--prefix PATH : ${nix-index.out}/bin \ | |
--prefix PATH : ${nix.out}/bin \ | |
--prefix PATH : ${fzy.out}/bin | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment