Mon, 08 May 2023 02:36:32 -0500
add basic nix alternative for stubs
.lib/sh/stubexec.sh | file | annotate | diff | comparison | revisions | |
.lib/stubs/direnv | file | annotate | diff | comparison | revisions | |
.lib/stubs/fzf | file | annotate | diff | comparison | revisions | |
.lib/stubs/just | file | annotate | diff | comparison | revisions | |
.lib/stubs/stow | file | annotate | diff | comparison | revisions | |
.lib/stubs/tectonic | file | annotate | diff | comparison | revisions |
--- a/.lib/sh/stubexec.sh +++ b/.lib/sh/stubexec.sh @@ -38,11 +38,23 @@ stubexec() { if [ -x "$real_bin" ]; then exec "$real_bin" "$@" fi + try_nix_run "$@" install_it touch "$(realbin "$0")" # In case of no updates stubexec "$@" } +has() { + type "$1" >/dev/null 2>&1 +} + +try_nix_run() { + if [ "${nix_ref:-}" ] && has nix; then + # FIXME: this can be GC'd and doesn't allow running alternate commands + exec nix run "$nix_ref" -- "$@" + fi +} + bina_install() { local github_repo="$1" mkdir -p ~/.local/bin
--- a/.lib/stubs/direnv +++ b/.lib/stubs/direnv @@ -1,6 +1,8 @@ #!/bin/sh set -eu +nix_ref='nixpkgs#direnv' + install_it() { mkdir -p ~/.local/bin curl -fsSL https://direnv.net/install.sh |
--- a/.lib/stubs/fzf +++ b/.lib/stubs/fzf @@ -1,6 +1,8 @@ #!/bin/sh set -eu +nix_ref='nixpkgs#fzf' + install_it() { bina_install "junegunn/fzf" }
--- a/.lib/stubs/just +++ b/.lib/stubs/just @@ -1,6 +1,8 @@ #!/bin/sh set -eu +nix_ref='nixpkgs#just' + install_it() { bina_install "casey/just" # cargo install just