tangled
alpha
login
or
join now
dunkirk.sh
/
dots
3
fork
atom
Kieran's opinionated (and probably slightly dumb) nix config
3
fork
atom
overview
issues
pulls
pipelines
feat: update ghrpc to handle existing repos
dunkirk.sh
1 month ago
8dd2ae10
3c0b2393
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+69
-10
1 changed file
expand all
collapse all
unified
split
modules
home
system
shell.nix
+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
517
+
# Check if we're in an existing directory
518
518
+
IS_EXISTING_DIR=false
519
519
+
IS_GIT_REPO=false
520
520
+
HAS_COMMITS=false
521
521
+
if ${pkgs.git}/bin/git rev-parse --is-inside-work-tree &>/dev/null; then
522
522
+
IS_GIT_REPO=true
523
523
+
IS_EXISTING_DIR=true
524
524
+
if ${pkgs.git}/bin/git rev-parse HEAD &>/dev/null; then
525
525
+
HAS_COMMITS=true
526
526
+
fi
527
527
+
elif [[ -d "." ]] && [[ "$(ls -A 2>/dev/null)" ]]; then
528
528
+
IS_EXISTING_DIR=true
529
529
+
fi
530
530
+
531
531
+
# Initialize git repo if needed
532
532
+
if [[ "$IS_GIT_REPO" == false ]]; then
533
533
+
if [[ "$IS_EXISTING_DIR" == true ]] && [[ -t 0 ]]; then
534
534
+
if ${pkgs.gum}/bin/gum confirm "Directory has files but no git repo. Initialize git?"; then
535
535
+
${pkgs.git}/bin/git init -b "$BRANCH"
536
536
+
IS_GIT_REPO=true
537
537
+
${pkgs.gum}/bin/gum style --foreground 35 "✓ Initialized git repository"
538
538
+
else
539
539
+
${pkgs.gum}/bin/gum style --foreground 196 "Error: Git repository required"
540
540
+
exit 1
541
541
+
fi
542
542
+
else
543
543
+
${pkgs.git}/bin/git init -b "$BRANCH"
544
544
+
IS_GIT_REPO=true
545
545
+
fi
546
546
+
fi
547
547
+
548
548
+
# Check if remote repos already exist and offer to skip creation
549
549
+
SKIP_REMOTE_CREATION=false
550
550
+
if [[ "$HAS_COMMITS" == true ]] && [[ -t 0 ]]; then
551
551
+
${pkgs.gum}/bin/gum style --foreground 214 "Existing git repo detected with commits"
552
552
+
if ! ${pkgs.gum}/bin/gum confirm "Create new remote repositories?"; then
553
553
+
SKIP_REMOTE_CREATION=true
554
554
+
${pkgs.gum}/bin/gum style --foreground 35 "Skipping remote repo creation, will only configure remotes"
555
555
+
fi
556
556
+
fi
557
557
+
517
558
# Prompt for templates
518
559
ADD_README=false
519
560
ADD_LICENSE=false
520
561
LICENSE_TYPE=""
562
562
+
README_EXISTS=false
563
563
+
LICENSE_EXISTS=false
564
564
+
[[ -f "README.md" ]] && README_EXISTS=true
565
565
+
[[ -f "LICENSE.md" ]] && LICENSE_EXISTS=true
566
566
+
521
567
if [[ -t 0 ]]; then
522
522
-
if ${pkgs.gum}/bin/gum confirm "Add templates (README/LICENSE)?"; then
523
523
-
TEMPLATES=$(${pkgs.gum}/bin/gum choose --no-limit --header "Select templates to add" "README.md" "LICENSE.md")
524
524
-
if echo "$TEMPLATES" | grep -q "README.md"; then
525
525
-
ADD_README=true
568
568
+
# Build template options based on what exists
569
569
+
TEMPLATE_OPTIONS=""
570
570
+
if [[ "$README_EXISTS" == false ]]; then
571
571
+
TEMPLATE_OPTIONS="README.md"
572
572
+
fi
573
573
+
if [[ "$LICENSE_EXISTS" == false ]]; then
574
574
+
[[ -n "$TEMPLATE_OPTIONS" ]] && TEMPLATE_OPTIONS="$TEMPLATE_OPTIONS\nLICENSE.md" || TEMPLATE_OPTIONS="LICENSE.md"
575
575
+
fi
576
576
+
577
577
+
if [[ -n "$TEMPLATE_OPTIONS" ]]; then
578
578
+
if ${pkgs.gum}/bin/gum confirm "Add templates (README/LICENSE)?"; then
579
579
+
TEMPLATES=$(echo -e "$TEMPLATE_OPTIONS" | ${pkgs.gum}/bin/gum choose --no-limit --header "Select templates to add")
580
580
+
if echo "$TEMPLATES" | grep -q "README.md"; then
581
581
+
ADD_README=true
582
582
+
fi
583
583
+
if echo "$TEMPLATES" | grep -q "LICENSE.md"; then
584
584
+
ADD_LICENSE=true
585
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
586
+
fi
526
587
fi
527
527
-
if echo "$TEMPLATES" | grep -q "LICENSE.md"; then
528
528
-
ADD_LICENSE=true
529
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
530
-
fi
588
588
+
elif [[ "$README_EXISTS" == true ]] && [[ "$LICENSE_EXISTS" == true ]]; then
589
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
535
-
if [[ "$TANGLED" == true ]]; then
594
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
563
-
if [[ "$GITHUB" == true ]]; then
622
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