diff --git a/.github/workflows/pr_chezmoi_init.yaml b/.github/workflows/pr_chezmoi_init.yaml index e742e93e..546ad36c 100644 --- a/.github/workflows/pr_chezmoi_init.yaml +++ b/.github/workflows/pr_chezmoi_init.yaml @@ -27,7 +27,7 @@ jobs: with: # https://github.com/scottames/boxes image: ghcr.io/scottames/fedora-toolbox:latest - options: -v ${{ github.workspace }}:/home/container/src/scottames/dots + options: -v ${{ github.workspace }}:/home/container/src/github.com/scottames/dots/main run: | - /home/container/src/scottames/dots/scripts/init.sh \ + /home/container/src/github.com/scottames/dots/main/scripts/init.sh \ --no-tty --branch "${{ steps.extract_branch.outputs.branch }}" diff --git a/home/.chezmoi.toml.tmpl b/home/.chezmoi.toml.tmpl index f9234c17..c18fed7a 100644 --- a/home/.chezmoi.toml.tmpl +++ b/home/.chezmoi.toml.tmpl @@ -9,10 +9,17 @@ {{- $hourLight := 24 -}} {{- $osVariant := "" -}} {{- $ublueImageInfo := "" -}} +{{- $dots := "dots" -}} + {{- $loginSession := 0 -}} {{- $loginSessionType := "" -}} +{{- $useGitWorktrees := true -}} +{{- if $useGitWorktrees -}} +{{- $dots = "dots/main" -}} +{{- end -}} + {{- if eq .chezmoi.os "linux" -}} {{- $gpu = output "sh" "-c" "lspci | grep VGA | cut -d ':' -f3 | awk '{print $1}'" | trim | lower -}} {{- if or (lstat "/.dockerenv") (lstat "/run/.containerenv") -}} @@ -40,7 +47,7 @@ {{- end -}} {{- end -}} -sourceDir = "{{ .chezmoi.homeDir }}/src/{{ $githubUser }}/dots/home" +sourceDir = "{{ .chezmoi.homeDir }}/src/github.com/{{ $githubUser }}/{{ $dots }}/home" progress = true {{ if lookPath "delta" -}} @@ -52,9 +59,9 @@ progress = true {{ end -}} [data] - chezmoi_home = "{{ .chezmoi.homeDir }}/src/{{ $githubUser }}/dots/home" + chezmoi_home = "{{ .chezmoi.homeDir }}/src/github.com/{{ $githubUser }}/{{ $dots }}/home" desktop_session = "{{ $desktopSession }}" - dots = "{{ .chezmoi.homeDir }}/src/{{ $githubUser }}/dots" + dots = "{{ .chezmoi.homeDir }}/src/github.com/{{ $githubUser }}/{{ $dots }}" hour_dark = {{ $hourDark }} hour_light = {{ $hourLight }} login_session = {{ $loginSession }} diff --git a/home/.chezmoiexternal.toml.tmpl b/home/.chezmoiexternal.toml.tmpl index 7af5a2f2..34900ce1 100644 --- a/home/.chezmoiexternal.toml.tmpl +++ b/home/.chezmoiexternal.toml.tmpl @@ -139,7 +139,7 @@ refreshPeriod = "168h" {{ if not (eq "container" .me.user) -}} -["src/pub/magefile/mage"] +["src/github.com/magefile/mage"] type = "git-repo" url = "https://github.com/magefile/mage" refreshPeriod = "168h" @@ -150,40 +150,55 @@ # │ git-repo │ # │ | personal │ # ╰──────────────────────────────────────────────────────────╯ -["src/scottames/boxes"] + +["src/github.com/scottames/boxes/.bare"] type = "git-repo" url = "git@github.com:scottames/boxes.git" refreshPeriod = "0" + ["src/github.com/scottames/boxes/.bare".clone] + args = ["--bare"] -["src/scottames/cmder"] +["src/github.com/scottames/cmder/.bare"] type = "git-repo" url = "git@github.com:scottames/cmder.git" refreshPeriod = "0" + ["src/github.com/scottames/cmder/.bare".clone] + args = ["--bare"] -["src/scottames/cv"] +["src/github.com/scottames/containers/.bare"] type = "git-repo" - url = "git@github.com:scottames/cv.git" + url = "git@github.com:scottames/containers.git" refreshPeriod = "0" + ["src/github.com/scottames/containers/.bare".clone] + args = ["--bare"] -["src/scottames/misc"] +["src/github.com/scottames/cv/.bare"] type = "git-repo" - url = "git@github.com:scottames/misc.git" + url = "git@github.com:scottames/cv.git" refreshPeriod = "0" + ["src/github.com/scottames/cv/.bare".clone] + args = ["--bare"] -["src/scottames/pm"] +["src/github.com/scottames/misc/.bare"] type = "git-repo" - url = "git@github.com:scottames/pm.git" + url = "git@github.com:scottames/misc.git" refreshPeriod = "0" + ["src/github.com/scottames/misc/.bare".clone] + args = ["--bare"] -["src/scottames/walls"] +["src/github.com/scottames/ublue/.bare"] type = "git-repo" - url = "git@github.com:scottames/walls.git" + url = "git@github.com:scottames/ublue.git" refreshPeriod = "0" + ["src/github.com/scottames/ublue/.bare".clone] + args = ["--bare"] -["src/scottames/ublue"] +["src/github.com/scottames/walls/.bare"] type = "git-repo" - url = "git@github.com:scottames/ublue.git" + url = "git@github.com:scottames/walls.git" refreshPeriod = "0" + ["src/github.com/scottames/walls/.bare".clone] + args = ["--bare"] {{ end -}} {{ end -}} diff --git a/home/.chezmoiignore b/home/.chezmoiignore index 441eae3e..d6975a12 100644 --- a/home/.chezmoiignore +++ b/home/.chezmoiignore @@ -18,7 +18,7 @@ # PaperWM .config/paperwm* -src/pub/paperwm* +src/github.com/paperwm* # Gnome Wallpaper Config .local/share/gnome-background-properties/* @@ -27,7 +27,7 @@ src/pub/paperwm* {{- end}} # Gnome Wallpaper Config -{{ if not (stat (joinPath .chezmoi.homeDir "src/scottames/walls")) }} +{{ if not (stat (joinPath .chezmoi.homeDir "src/github.com/scottames/walls")) }} .local/share/gnome-background-properties/* {{ end }} diff --git a/home/dot_local/share/gnome-background-properties/Gaussian_purple.xml.tmpl b/home/dot_local/share/gnome-background-properties/Gaussian_purple.xml.tmpl index b8fcf36d..890971f6 100644 --- a/home/dot_local/share/gnome-background-properties/Gaussian_purple.xml.tmpl +++ b/home/dot_local/share/gnome-background-properties/Gaussian_purple.xml.tmpl @@ -3,8 +3,8 @@ Default Background - {{ .chezmoi.homeDir }}/src/scottames/walls/4k/06-Blue_Purple_LM-4k_catppuccin-latte_8_GaussianRBF_96_16.png - {{ .chezmoi.homeDir }}/src/scottames/walls/4k/05-Blue_Green_DM-4K.png + {{ .chezmoi.homeDir }}/src/github.com/scottames/walls/4k/06-Blue_Purple_LM-4k_catppuccin-latte_8_GaussianRBF_96_16.png + {{ .chezmoi.homeDir }}/src/github.com/scottames/walls/4k/05-Blue_Green_DM-4K.png zoom solid #3071AE diff --git a/home/dot_setenv b/home/dot_setenv index b88f7f11..779b2bd9 100644 --- a/home/dot_setenv +++ b/home/dot_setenv @@ -1,8 +1,12 @@ # vi: ft=fish autoformat=false setenv SRC_DIR "$HOME/src" -setenv MY_SRC_DIR "$SRC_DIR/scottames" -setenv DOTS "$MY_SRC_DIR/dots" +setenv MY_SRC_DIR "$SRC_DIR/github.com/scottames" +[ -d "$MY_SRC_DIR/dots" ] \ + && setenv DOTS "$MY_SRC_DIR/dots" +[ -d "$MY_SRC_DIR/dots/main" ] \ + && setenv DOTS "$MY_SRC_DIR/dots/main" + setenv DOTFILES "$DOTS" setenv VAR_HOME "/var$HOME" diff --git a/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees.fish b/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees.fish index a0a4f322..55fbee70 100644 --- a/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees.fish +++ b/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees.fish @@ -29,10 +29,15 @@ function git_clone_for_worktrees \ # new-awesome-feature # hotfix-bug-12 # ... - printf_info "Cloning to bare\n" + printf_info "Cloning to .bare in $name\n" pushd $name - git clone --bare $url .bare + if not test -d .bare + git clone --bare $url .bare + else + printf_warn ".bare directory exists, skipping clone\n" + end + echo "gitdir: ./.bare" >.git printf_info "Setting up origin\n" @@ -40,18 +45,22 @@ function git_clone_for_worktrees \ git fetch origin # fetch all branches from origin set -l _git_main_branch (git remote show origin | sed -n '/HEAD branch/s/.*: //p') - printf_info "Creating initial worktree for main branch: $_git_main_branch\n" - git worktree add $_git_main_branch $_git_main_branch - - if not test -d $_git_main_branch - printf_err "Unable to create initial worktree for '$_git_main_branch'\n" - return 1 + printf_info "Creating initial worktree for main branch: $_git_main_branch\n" + git worktree add $_git_main_branch $_git_main_branch + + if not test -d $_git_main_branch + printf_err "Unable to create initial worktree for '$_git_main_branch'\n" + return 1 + end + cd $_git_main_branch + git branch --set-upstream-to=origin/$_git_main_branch $_git_main_branch + else + printf_warn "Directory for branch '$_git_main_branch' exists, skipping initial worktree creation\n" end - cd $_git_main_branch - git branch --set-upstream-to=origin/$_git_main_branch $_git_main_branch popd - # source: https://morgan.cugerone.com/blog/workarounds-to-git-worktree-using-bare-repository-and-cannot-fetch-remote-branches/ + # source inspiration: + # https://morgan.cugerone.com/blog/workarounds-to-git-worktree-using-bare-repository-and-cannot-fetch-remote-branches/ end diff --git a/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees_from_ls.fish b/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees_from_ls.fish new file mode 100644 index 00000000..85bc77aa --- /dev/null +++ b/home/private_dot_config/fish/custom_functions.d/git_clone_for_worktrees_from_ls.fish @@ -0,0 +1,24 @@ +#!/bin/env fish + +function git_clone_for_worktrees_from_ls \ + --description "Calls git_clone_for_worktrees on all directories in pwd. Needs " + # Examples: + # git_clone_for_worktrees_from_ls scottames + # => sets up subdirectories repos for org 'scottames' + + _arg_req_gt_one $argv || return 1 + + set -l org $argv[1] + set -l remote $argv[2] + + if set -q argv[2] + set remote $argv[2] + else + set remote "github.com" + end + + echo "remote: $remote" + for dir in (ls -D) + git_clone_for_worktrees "git@$remote/$org/$dir.git" + end +end diff --git a/magefiles/test.go b/magefiles/test.go index 140ee948..0430ec03 100644 --- a/magefiles/test.go +++ b/magefiles/test.go @@ -26,7 +26,7 @@ func dockerRunTest() error { return fmt.Errorf("getting git project info: %w", err) } - chezmoiSource := "/home/container/src/" + gp.Org + fs + gp.Name + chezmoiSource := "/home/container/src/github.com/" + gp.Org + fs + gp.Name vol := gp.Root + ":" + chezmoiSource args := []string{"-v", vol} cmd := chezmoiSource + "/scripts/init.sh" diff --git a/scripts/init.sh b/scripts/init.sh index 02bb73cf..fc8f2542 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -17,7 +17,7 @@ if [ -x "$(command -v distrobox)" ]; then err "distrobox found. init from distrobox instead. distrobox create --image registry.fedoraproject.org/fedora-toolbox:38 --name fd - + alternatively, arch: (may cause oddities with python install, etc. on fedora system) distrobox create --image ghcr.io/scottames/arch-toolbox:latest --name at @@ -49,8 +49,14 @@ else _chezmoi=chezmoi fi +GIT_WORKTREES="${GIT_WORKTREES:-true}" + _CHEZMOI_SOURCE="scottames/dots" -_CHEZMOI_SOURCE_DIR="${HOME}/src/${_CHEZMOI_SOURCE}" +if [ "${GIT_WORKTREES}" = true ]; then + _CHEZMOI_SOURCE_DIR="${HOME}/src/github.com/${_CHEZMOI_SOURCE}/main" +else + _CHEZMOI_SOURCE_DIR="${HOME}/src/github.com/${_CHEZMOI_SOURCE}" +fi printf "\n${yellow}⚡ ${magenta}init chezmoi from ${clear}%s${magenta} to ${clear}%s\n ${magenta}with args:${clear} " \ "${_CHEZMOI_SOURCE}" "${_CHEZMOI_SOURCE_DIR}"