Kieran's opinionated (and probably slightly dumb) nix config

feat: update ghrpc to handle existing repos

dunkirk.sh 8dd2ae10 3c0b2393

verified
+69 -10
+69 -10
modules/home/system/shell.nix
··· 514 514 515 515 ${pkgs.gum}/bin/gum style --foreground 212 --bold "Creating repository: $NAME" 516 516 517 + # Check if we're in an existing directory 518 + IS_EXISTING_DIR=false 519 + IS_GIT_REPO=false 520 + HAS_COMMITS=false 521 + if ${pkgs.git}/bin/git rev-parse --is-inside-work-tree &>/dev/null; then 522 + IS_GIT_REPO=true 523 + IS_EXISTING_DIR=true 524 + if ${pkgs.git}/bin/git rev-parse HEAD &>/dev/null; then 525 + HAS_COMMITS=true 526 + fi 527 + elif [[ -d "." ]] && [[ "$(ls -A 2>/dev/null)" ]]; then 528 + IS_EXISTING_DIR=true 529 + fi 530 + 531 + # Initialize git repo if needed 532 + if [[ "$IS_GIT_REPO" == false ]]; then 533 + if [[ "$IS_EXISTING_DIR" == true ]] && [[ -t 0 ]]; then 534 + if ${pkgs.gum}/bin/gum confirm "Directory has files but no git repo. Initialize git?"; then 535 + ${pkgs.git}/bin/git init -b "$BRANCH" 536 + IS_GIT_REPO=true 537 + ${pkgs.gum}/bin/gum style --foreground 35 "✓ Initialized git repository" 538 + else 539 + ${pkgs.gum}/bin/gum style --foreground 196 "Error: Git repository required" 540 + exit 1 541 + fi 542 + else 543 + ${pkgs.git}/bin/git init -b "$BRANCH" 544 + IS_GIT_REPO=true 545 + fi 546 + fi 547 + 548 + # Check if remote repos already exist and offer to skip creation 549 + SKIP_REMOTE_CREATION=false 550 + if [[ "$HAS_COMMITS" == true ]] && [[ -t 0 ]]; then 551 + ${pkgs.gum}/bin/gum style --foreground 214 "Existing git repo detected with commits" 552 + if ! ${pkgs.gum}/bin/gum confirm "Create new remote repositories?"; then 553 + SKIP_REMOTE_CREATION=true 554 + ${pkgs.gum}/bin/gum style --foreground 35 "Skipping remote repo creation, will only configure remotes" 555 + fi 556 + fi 557 + 517 558 # Prompt for templates 518 559 ADD_README=false 519 560 ADD_LICENSE=false 520 561 LICENSE_TYPE="" 562 + README_EXISTS=false 563 + LICENSE_EXISTS=false 564 + [[ -f "README.md" ]] && README_EXISTS=true 565 + [[ -f "LICENSE.md" ]] && LICENSE_EXISTS=true 566 + 521 567 if [[ -t 0 ]]; then 522 - if ${pkgs.gum}/bin/gum confirm "Add templates (README/LICENSE)?"; then 523 - TEMPLATES=$(${pkgs.gum}/bin/gum choose --no-limit --header "Select templates to add" "README.md" "LICENSE.md") 524 - if echo "$TEMPLATES" | grep -q "README.md"; then 525 - ADD_README=true 568 + # Build template options based on what exists 569 + TEMPLATE_OPTIONS="" 570 + if [[ "$README_EXISTS" == false ]]; then 571 + TEMPLATE_OPTIONS="README.md" 572 + fi 573 + if [[ "$LICENSE_EXISTS" == false ]]; then 574 + [[ -n "$TEMPLATE_OPTIONS" ]] && TEMPLATE_OPTIONS="$TEMPLATE_OPTIONS\nLICENSE.md" || TEMPLATE_OPTIONS="LICENSE.md" 575 + fi 576 + 577 + if [[ -n "$TEMPLATE_OPTIONS" ]]; then 578 + if ${pkgs.gum}/bin/gum confirm "Add templates (README/LICENSE)?"; then 579 + TEMPLATES=$(echo -e "$TEMPLATE_OPTIONS" | ${pkgs.gum}/bin/gum choose --no-limit --header "Select templates to add") 580 + if echo "$TEMPLATES" | grep -q "README.md"; then 581 + ADD_README=true 582 + fi 583 + if echo "$TEMPLATES" | grep -q "LICENSE.md"; then 584 + ADD_LICENSE=true 585 + LICENSE_TYPE=$(${pkgs.gum}/bin/gum choose --header "Select license" "MIT" "Apache-2.0" "GPL-3.0" "BSD-3-Clause" "ISC" "O'Saasy" "Unlicense") 586 + fi 526 587 fi 527 - if echo "$TEMPLATES" | grep -q "LICENSE.md"; then 528 - ADD_LICENSE=true 529 - LICENSE_TYPE=$(${pkgs.gum}/bin/gum choose --header "Select license" "MIT" "Apache-2.0" "GPL-3.0" "BSD-3-Clause" "ISC" "O'Saasy" "Unlicense") 530 - fi 588 + elif [[ "$README_EXISTS" == true ]] && [[ "$LICENSE_EXISTS" == true ]]; then 589 + ${pkgs.gum}/bin/gum style --foreground 214 "README.md and LICENSE.md already exist, skipping templates" 531 590 fi 532 591 fi 533 592 534 593 # Create on Tangled 535 - if [[ "$TANGLED" == true ]]; then 594 + if [[ "$TANGLED" == true ]] && [[ "$SKIP_REMOTE_CREATION" == false ]]; then 536 595 tangled_cookie="" 537 596 if [[ -f "/run/agenix/tangled-session" ]]; then 538 597 tangled_cookie=$(cat /run/agenix/tangled-session) ··· 560 619 fi 561 620 562 621 # Create on GitHub 563 - if [[ "$GITHUB" == true ]]; then 622 + if [[ "$GITHUB" == true ]] && [[ "$SKIP_REMOTE_CREATION" == false ]]; then 564 623 gh_flags="--$VISIBILITY" 565 624 [[ -n "$DESCRIPTION" ]] && gh_flags="$gh_flags --description \"$DESCRIPTION\"" 566 625