Skip to content

Commit d5b64dd

Browse files
committed
feat(chezmoi): add install script
1 parent 20e1c66 commit d5b64dd

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

home/.chezmoi.toml.tmpl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
{{- $users := list "kutsan" "reyhan" -}}
2-
{{- $user := promptChoiceOnce . "user" "Select main user" $users -}}
1+
{{- $interactive := stdinIsATTY -}}
32

4-
{{- $profiles := list "personal" "work" -}}
5-
{{- $profile := promptChoiceOnce . "profile" "Select environment profile" $profiles -}}
3+
{{- $user := "kutsan" -}}
4+
{{- if hasKey . "user" -}}
5+
{{- $user = .user -}}
6+
{{- else if $interactive -}}
7+
{{- $user = promptChoice "Select main user" (list "kutsan" "reyhan") -}}
8+
{{- end -}}
9+
10+
{{- $profile := "personal" -}}
11+
{{- if hasKey . "profile" -}}
12+
{{- $profile = .profile -}}
13+
{{- else if $interactive -}}
14+
{{- $profile = promptChoice "Select environment profile" (list "personal" "work") -}}
15+
{{- end -}}
616

717
[data]
818
profile = {{ $profile | quote }}

install.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
# -e: exit on error.
4+
# -u: exit on unset variables.
5+
set -eu
6+
7+
if ! chezmoi="$(command -v chezmoi)"; then
8+
bin_dir="${HOME}/.local/bin"
9+
chezmoi="${bin_dir}/chezmoi"
10+
11+
echo "Installing chezmoi to '${chezmoi}'" >&2
12+
13+
if command -v curl >/dev/null; then
14+
chezmoi_install_script="$(curl -fsSL get.chezmoi.io)"
15+
else
16+
echo "To install chezmoi, you must have curl installed." >&2
17+
exit 1
18+
fi
19+
20+
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}"
21+
unset chezmoi_install_script bin_dir
22+
fi
23+
24+
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
25+
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
26+
27+
set -- init --apply --source="${script_dir}"
28+
29+
echo "Running 'chezmoi $*'" >&2
30+
# exec: replace current process with chezmoi
31+
exec "$chezmoi" "$@"

0 commit comments

Comments
 (0)