Created
July 5, 2025 20:12
-
-
Save marcelarie/d1ad106663ce49ed5888aef1a99df047 to your computer and use it in GitHub Desktop.
Start nix dev shells without local flake.nix
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| REPO="${DEV_TEMPLATES:-$HOME/clones/own/dev-templates}" | |
| edit=false | |
| remote="" | |
| lang="" | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| -e | --edit) | |
| edit=true | |
| shift | |
| ;; | |
| -r | --remote) | |
| remote="$2" | |
| shift 2 | |
| ;; | |
| *) | |
| lang="$1" | |
| shift | |
| ;; | |
| esac | |
| done | |
| if [[ -n "$remote" ]]; then | |
| if [[ -z "$lang" ]]; then | |
| if [[ $remote =~ ^github: ]]; then | |
| gh="${remote#github:}" | |
| owner="${gh%%/*}" | |
| repo="${gh#*/}" | |
| api="https://api.github.com/repos/${owner}/${repo}/contents" | |
| lang=$(curl -fsSL "$api" | jq -r '.[] | select(.type=="dir") | .name' | grep -v '^\.github$' | fzf) | |
| else | |
| echo "fzf selection only supported for github: remotes" >&2 | |
| exit 1 | |
| fi | |
| fi | |
| [[ -z "$lang" ]] && exit 0 | |
| $edit && echo "--edit ignored with --remote" >&2 | |
| exec nix develop "${remote}?dir=${lang}" | |
| fi | |
| if [[ -z "$lang" ]]; then | |
| lang=$(git -C "$REPO" ls-tree -d --name-only HEAD | grep -v '^\.github$' | fzf) | |
| fi | |
| [[ -z "$lang" ]] && exit 0 | |
| flake="$REPO/$lang/flake.nix" | |
| if $edit; then | |
| "${EDITOR:-vi}" "$flake" | |
| fi | |
| exec nix develop "$REPO/$lang" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Available commands
Open fzf to select a language from the local repository (first we need to specify the path on the script):
Open a specific language from the local repo:
Open a specific language from the local repo but edit it before running the dev shell:
Open fzf to select a language from a remote repository:
Open a specific language from a remote repository: