From 84e3c9d89a46edc6611a1fa97a0cf34b833ca636 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 4 Mar 2023 18:35:16 +0800 Subject: [PATCH] update --- home/.chezmoi.toml.tmpl | 16 ++++++++-------- home/.chezmoiignore.tmpl | 5 +++++ install.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 home/.chezmoiignore.tmpl create mode 100755 install.sh diff --git a/home/.chezmoi.toml.tmpl b/home/.chezmoi.toml.tmpl index e9eb1a7..e88a29d 100644 --- a/home/.chezmoi.toml.tmpl +++ b/home/.chezmoi.toml.tmpl @@ -2,30 +2,30 @@ {{- if hasKey . "email" -}} {{- $email = .email -}} {{- else -}} -{{- $email = promptString "email" -}} +{{- $email = promptStringOnce . "email" "email address" -}} {{ end }} {{- $gitUser := "" -}} {{- if hasKey . "gitUser" -}} {{- $gitUser = .gitUser -}} {{- else -}} -{{- $gitUser = promptString "gitUser" -}} +{{- $gitUser = promptStringOnce . "gitUser" "git username" -}} {{- end -}} -{{- $jsLinter := promptString "jsLinter" "standard" -}} +{{- $jsLinter := promptStringOnce . "jsLinter" "js linter" "standard" -}} {{- if eq $jsLinter "" -}} {{- $jsLinter = "standard" -}} {{- end -}} -{{- $jsFixer := promptString "jsFixer" "standard" -}} +{{- $jsFixer := promptStringOnce . "jsFixer" "js fixer" "standard" -}} {{- if eq $jsFixer "" -}} {{- $jsFixer = "standard" -}} {{- end -}} -{{- $installGo := promptBool "installGo" true -}} -{{- $installNode := promptBool "installNode" true -}} -{{- $installRust := promptBool "installRust" true -}} -{{- $enableTmux := promptBool "enableTmux" true -}} +{{- $installGo := promptBoolOnce . "installGo" "install golang bin" true -}} +{{- $installNode := promptBoolOnce . "installNode" "install nodejs bin" true -}} +{{- $installRust := promptBoolOnce . "installRust" "install rust bin" true -}} +{{- $enableTmux := promptBoolOnce . "enableTmux" "install enable tmux autostart" true -}} [data.shell] tmux = {{ $enableTmux }} diff --git a/home/.chezmoiignore.tmpl b/home/.chezmoiignore.tmpl new file mode 100644 index 0000000..83f25c9 --- /dev/null +++ b/home/.chezmoiignore.tmpl @@ -0,0 +1,5 @@ +# ignore template + +{{- if not .shell.tmux }} +.tmix.conf +{{- end }} diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..46995f9 --- /dev/null +++ b/install.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# -e: exit on error +# -u: exit on unset variables +set -eu + +if ! chezmoi="$(command -v chezmoi)"; then + bin_dir="${HOME}/.local/bin" + chezmoi="${bin_dir}/chezmoi" + echo "Installing chezmoi to '${chezmoi}'" >&2 + if command -v curl >/dev/null; then + chezmoi_install_script="$(curl -fsSL get.chezmoi.io)" + elif command -v wget >/dev/null; then + chezmoi_install_script="$(wget -qO- get.chezmoi.io)" + else + echo "To install chezmoi, you must have curl or wget installed." >&2 + exit 1 + fi + sh -c "${chezmoi_install_script}" -- -b "${bin_dir}" + unset chezmoi_install_script bin_dir +fi + +# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188 +script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)" + +set -- init --apply --source="${script_dir}" + +echo "Running 'chezmoi $*'" >&2 +# exec: replace current process with chezmoi +exec "$chezmoi" "$@"