diff --git a/.chezmoi.toml.tmpl b/.chezmoi.toml.tmpl new file mode 100644 index 0000000..741056f --- /dev/null +++ b/.chezmoi.toml.tmpl @@ -0,0 +1,24 @@ +# This .chezmoi.toml file is used once only +# It collects information about the system in order to determine +# which of the _home.* dirs will be set as the .chezmoiroot +# +{{- $chassisType := "desktop" }} +{{- $sysType := "posix" }} +{{- if eq .chezmoi.os "darwin" }} +{{- $sysType = "macos" }} +{{- if contains "BatteryData" (output "ioreg" "-c" "AppleSmartBattery") }} +{{- $chassisType = "laptop" }} +{{- else }} +{{- $chassisType = "desktop" }} +{{- end }} +{{- else if eq .chezmoi.os "linux" }} +{{- $chassisType = (output "hostnamectl" "--json=short" | mustFromJson).Chassis }} +{{- else if eq .chezmoi.os "windows" }} +{{- $sysType = "windows" }} +{{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }} +{{- end }} + +[scriptEnv] + CZ_CHASSIS="{{- $chassisType }}" + CZ_SYS="{{- $sysType }}" + CZ_OS="{{- .chezmoi.os }}" diff --git a/.chezmoiignore b/.chezmoiignore new file mode 100644 index 0000000..a43e2b3 --- /dev/null +++ b/.chezmoiignore @@ -0,0 +1,7 @@ +# The content at the root of the repo is for initial detection only. +# Thus, only .chezmoitscripts is required, because it will setup the +# correct .chezmoiroot, where the rest of the content resides. +# +* +! .chezmoiscripts/ +! .chezmoiscripts/** diff --git a/.chezmoiscripts/run_init.sh.tmpl b/.chezmoiscripts/run_init.sh.tmpl new file mode 100755 index 0000000..8b93ddc --- /dev/null +++ b/.chezmoiscripts/run_init.sh.tmpl @@ -0,0 +1,22 @@ +#! /usr/bin/env bash + +set -e + +#env | grep -E 'chezmoi|^CZ' +cd "$CHEZMOI_SOURCE_DIR" +CZ_MODEL="$(ioreg -l | grep "product-name" | sed -Ee 's/^.*\<"(.*)\"\>.*$/\1/')" +set | grep '^CZ_' +printf 'System detected as %s/%s, setting up .chezmoiroot and initializing...\n' "$CZ_SYS" "$CZ_CHASSIS" +if [ -r "base.chezmoiroot.$CZ_SYS.$CZ_CHASSIS" ]; then + ln -s "base.chezmoiroot.$CZ_SYS.$CZ_CHASSIS" .chezmoiroot +elif [ -r "base.chezmoiroot.$CZ_SYS" ]; then + ln -s "base.chezmoiroot.$CZ_SYS" .chezmoiroot +elif [ -r "base.chezmoiroot.$CZ_CHASSIS" ]; then + ln -s "base.chezmoiroot.$CZ_CHASSIS" .chezmoiroot +else + printf 'Failed to find a matching .chezmoiroot. Aborting!\n' + false +fi + +# Brute force remove chezmoistate lock and restart init --apply +exec sh -c 'rm ~/.config/chezmoi/chezmoistate.boltdb && chezmoi init --apply' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f4bb5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# .chezmoiroot is generated by .chezmoiscripts/run_onchage_init.sh.tmpl +# during chezmoi init --apply +.chezmoiroot diff --git a/.init.me.sh b/.init.me.sh new file mode 100755 index 0000000..fc85021 --- /dev/null +++ b/.init.me.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash + +set -ex + +rm -fR ~/.config/chezmoi ~/.local/share/chezmoi/.chezmoiroot +chezmoi init --apply diff --git a/_home.macos/.chezmoi.toml.tmpl b/_home.macos/.chezmoi.toml.tmpl new file mode 100644 index 0000000..87d7e54 --- /dev/null +++ b/_home.macos/.chezmoi.toml.tmpl @@ -0,0 +1,3 @@ +[Data] + one="One" + diff --git a/_home.macos/.chezmoiscripts/run_once_init.sh.tmpl b/_home.macos/.chezmoiscripts/run_once_init.sh.tmpl new file mode 100755 index 0000000..8f13a6a --- /dev/null +++ b/_home.macos/.chezmoiscripts/run_once_init.sh.tmpl @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +printf '_home.macos init\n' diff --git a/_home.macos/dot_zshrc b/_home.macos/dot_zshrc new file mode 120000 index 0000000..1a0fdd6 --- /dev/null +++ b/_home.macos/dot_zshrc @@ -0,0 +1 @@ +../_home/dot_zshrc \ No newline at end of file diff --git a/_home.macos/private_dot_config/sz.env b/_home.macos/private_dot_config/sz.env new file mode 120000 index 0000000..c77a44f --- /dev/null +++ b/_home.macos/private_dot_config/sz.env @@ -0,0 +1 @@ +../../_home/private_dot_config/sz.env \ No newline at end of file diff --git a/_home/.chezmoiscripts/.keep b/_home/.chezmoiscripts/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/_home/.chezmoiscripts/run_once_init.sh.tmpl b/_home/.chezmoiscripts/run_once_init.sh.tmpl new file mode 100755 index 0000000..92cc9ab --- /dev/null +++ b/_home/.chezmoiscripts/run_once_init.sh.tmpl @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +printf '_home init\s' diff --git a/base.chezmoiroot.linux b/base.chezmoiroot.linux new file mode 120000 index 0000000..1bb9fa1 --- /dev/null +++ b/base.chezmoiroot.linux @@ -0,0 +1 @@ +base.chezmoiroot.posix \ No newline at end of file diff --git a/base.chezmoiroot.macos b/base.chezmoiroot.macos new file mode 100644 index 0000000..b42b5ea --- /dev/null +++ b/base.chezmoiroot.macos @@ -0,0 +1 @@ +_home.macos diff --git a/base.chezmoiroot.macos.laptop b/base.chezmoiroot.macos.laptop new file mode 120000 index 0000000..9db2158 --- /dev/null +++ b/base.chezmoiroot.macos.laptop @@ -0,0 +1 @@ +base.chezmoiroot.macos \ No newline at end of file diff --git a/.chezmoiroot b/base.chezmoiroot.posix similarity index 100% rename from .chezmoiroot rename to base.chezmoiroot.posix