From 92c818bde3c5f3c2c89d82068809d7113f1a33a9 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 5 Oct 2024 17:45:19 -0500 Subject: [PATCH] Chezmoi config generator, micro preference, chassis/core/threads detect --- .chezmoi.toml.tmpl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .chezmoi.toml.tmpl diff --git a/.chezmoi.toml.tmpl b/.chezmoi.toml.tmpl new file mode 100644 index 0000000..a8868a7 --- /dev/null +++ b/.chezmoi.toml.tmpl @@ -0,0 +1,35 @@ +{{- $chassisType := "desktop" }} +{{- if eq .chezmoi.os "darwin" }} +{{- if contains "MacBook" (output "sysctl" "-n" "hw.model") }} +{{- $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" }} +{{- $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 }} + +{{- $cpuCores := 1 }} +{{- $cpuThreads := 1 }} +{{- if eq .chezmoi.os "darwin" }} +{{- $cpuCores = (output "sysctl" "-n" "hw.physicalcpu_max") | trim | atoi }} +{{- $cpuThreads = (output "sysctl" "-n" "hw.logicalcpu_max") | trim | atoi }} +{{- else if eq .chezmoi.os "linux" }} +{{- $cpuCores = (output "sh" "-c" "lscpu --online --parse | grep --invert-match '^#' | sort --field-separator=',' --key='2,4' --unique | wc --lines") | trim | atoi }} +{{- $cpuThreads = (output "sh" "-c" "lscpu --online --parse | grep --invert-match '^#' | wc --lines") | trim | atoi }} +{{- else if eq .chezmoi.os "windows" }} +{{- $cpuCores = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfCores") | trim | atoi }} +{{- $cpuThreads = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "(Get-CimInstance -ClassName 'Win32_Processor').NumberOfLogicalProcessors") | trim | atoi }} +{{- end -}} + +[edit] + command = "micro" + +[data] + chassis = "{{ $chassisType }}" + +[data.cpu] + cores = {{ $cpuCores }} + threads = {{ $cpuThreads }}