aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@users.noreply.github.com>2021-04-10 23:36:51 -0400
committertdro <tdro@users.noreply.github.com>2021-04-11 00:14:41 -0400
commite3adbc787bf08439d25abcf692f527d62c110c80 (patch)
tree7e3cf8f2d82438ff626442d9f124697d5afdd8e4
parent084eeb10cbf9774516804067b82de8ba704dfdda (diff)
downloaddotfiles-e3adbc787bf08439d25abcf692f527d62c110c80.tar.gz
dotfiles-e3adbc787bf08439d25abcf692f527d62c110c80.tar.bz2
dotfiles-e3adbc787bf08439d25abcf692f527d62c110c80.zip
.local/bin: Add nix-locate helper script
-rwxr-xr-x.local/bin/,33
1 files changed, 33 insertions, 0 deletions
diff --git a/.local/bin/, b/.local/bin/,
new file mode 100755
index 0000000..c9e6545
--- /dev/null
+++ b/.local/bin/,
@@ -0,0 +1,33 @@
+#!/bin/sh -eu
+# Idea condensed from https://github.com/Shopify/comma
+
+program=$(basename "$0")
+requires="$(command -V nix-index nix-locate nix-shell fzf | awk '{ print $1, $3 }' | column -t)"
+
+[ "${1:-}" = "--check" ] && printf '%s\n' "$requires" && exit;
+
+{ [ "${1:-}" = "--help" ] || [ "$#" = 0 ]; } && printf \
+"
+Usage: %s [FLAGS]... [ARGUMENT]...
+
+The wrapper $program shall search all nix
+packages for a file and set up a nix shell for the
+program that contains that file. The shell prints
+all binaries in the package upon invocation.
+
+ Command List:
+
+ $program [ARGUMENT]... Search for packages using file name argument.
+ $program --help Show this help menu.
+ $program --check Check dependencies.
+" "$program" && exit;
+
+databasePath=${XDG_DATA_HOME:-~/.local/share}/nix-index
+nixLocate='nix-locate --db '"$databasePath"' --top-level --minimal --whole-name '"${1:-}"
+attributes=$($nixLocate | while read -r attribute; do
+ attributeName=${attribute%.*};
+ printf '%s\n' "$attributeName";
+done)
+
+attribute=$(printf '%s' "$attributes" | fzf)
+nix-shell --packages "$attribute" --command 'printf "$buildInputs\n"; ls $buildInputs/bin; return';