Skip to content

Instantly share code, notes, and snippets.

@burke

burke/,

Created Dec 16, 2019
Embed
What would you like to do?
#!/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}" "$@"
{ 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
You can’t perform that action at this time.