pkgs: add comma
This commit is contained in:
parent
76148d75b8
commit
e5fdfd6c44
33
pkgs/comma/comma
Executable file
33
pkgs/comma/comma
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
print_err() {
|
||||
printf "%s\n" "$1" >&2
|
||||
}
|
||||
|
||||
usage() {
|
||||
print_err "Usage: , <program> [argument]..."
|
||||
}
|
||||
|
||||
find_program() {
|
||||
local CANDIDATE
|
||||
CANDIDATE="$(nix-locate --top-level --minimal --at-root --whole-name "/bin/$1")"
|
||||
if [ "$(printf '%s\n' "$CANDIDATE" | wc -l)" -gt 1 ]; then
|
||||
CANDIDATE="$(printf '%s' "$CANDIDATE" | fzf-tmux)"
|
||||
fi
|
||||
printf '%s' "$CANDIDATE"
|
||||
}
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROGRAM="$(find_program "$1")"
|
||||
if [ -z "$PROGRAM" ]; then
|
||||
print_err "No match found for $1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nix shell "nixpkgs#$PROGRAM" -c "$@"
|
42
pkgs/comma/default.nix
Normal file
42
pkgs/comma/default.nix
Normal file
|
@ -0,0 +1,42 @@
|
|||
{ fzf, lib, makeWrapper, nix-index, shellcheck, stdenvNoCC }:
|
||||
stdenvNoCC.mkDerivation rec {
|
||||
pname = "comma";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./. + "/comma";
|
||||
|
||||
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
|
||||
|
||||
buildInputs = [
|
||||
makeWrapper
|
||||
shellcheck
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
shellcheck $src
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $src $out/bin/${meta.mainProgram}
|
||||
chmod a+x $out/bin/${meta.mainProgram}
|
||||
'';
|
||||
|
||||
wrapperPath = lib.makeBinPath [
|
||||
fzf
|
||||
nix-index
|
||||
];
|
||||
|
||||
fixupPhase = ''
|
||||
patchShebangs $out/bin/${meta.mainProgram}
|
||||
wrapProgram $out/bin/${meta.mainProgram} --prefix PATH : "${wrapperPath}"
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
mainProgram = ",";
|
||||
description = "A simple script inspired by Shopify's comma, for modern Nix";
|
||||
homepage = "https://gitea.belanyi.fr/ambroisie/nix-config";
|
||||
license = with licenses; [ mit ];
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
{ pkgs }:
|
||||
rec {
|
||||
comma = pkgs.callPackage ./comma { };
|
||||
|
||||
diff-flake = pkgs.callPackage ./diff-flake { };
|
||||
|
||||
havm = pkgs.callPackage ./havm { };
|
||||
|
|
Loading…
Reference in a new issue