-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chezmoi): add dotfiles-apply-rootmoi and initialize-zsh commands
- Loading branch information
1 parent
10d4173
commit 968192d
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
chezmoi/.chezmoiscripts/run_once_after_20-apply-rootmoi.sh.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# {{- if and (eq .chezmoi.os "linux") (.system.apply_rootmoi) (.system.is_sudoer) }} | ||
# shellcheck source=/dev/null | ||
source "${HOME}/.config/shrc/00-dotfiles-export" | ||
# dotfiles-apply-rootmoi hash: {{ include "dot_local/bin/executable_dotfiles-apply-rootmoi.tmpl" | sha256sum }} | ||
dotfiles-apply-rootmoi | ||
# {{- end }} |
55 changes: 55 additions & 0 deletions
55
chezmoi/dot_local/bin/executable_dotfiles-apply-rootmoi.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
# {{ if and (eq .chezmoi.os "linux") (.system.is_sudoer) -}} | ||
# {{ template "scripts-library" }} | ||
log_task "Installing dotfiles for system user with rootmoi" | ||
|
||
# shellcheck disable=all | ||
original_args=({{ range (rest .chezmoi.args) }} {{ . | quote }}{{ end }}) | ||
args=(apply) | ||
diff_args=(diff) | ||
|
||
# Filter incompatible args | ||
skip_one_more=false | ||
remove_apply=false | ||
for i in "${!original_args[@]}"; do | ||
if [[ "${skip_one_more}" == true ]]; then | ||
skip_one_more=false | ||
continue | ||
fi | ||
|
||
if [[ "${original_args[i]}" == "-S" || "${original_args[i]}" == "--source" ]]; then | ||
skip_one_more=true | ||
continue | ||
fi | ||
|
||
if [[ "${original_args[i]}" == "-S="* || "${original_args[i]}" == "--source="* ]]; then | ||
continue | ||
fi | ||
|
||
# We will always apply, so we don't need any --apply flags | ||
if [[ "${original_args[i]}" == "-a" || "${original_args[i]}" == "-a="* || "${original_args[i]}" == "--apply" || "${original_args[i]}" == "--apply="* ]]; then | ||
continue | ||
fi | ||
|
||
# --init never makes sense, because rootmoi's configuration is handled by chezmoi earlier | ||
if [[ "${original_args[i]}" == "--init" ]]; then | ||
continue | ||
fi | ||
|
||
# Remove any positional args, as we will always use apply | ||
if [[ "${original_args[i]}" != "-"* ]]; then | ||
continue | ||
fi | ||
|
||
args+=("${original_args[i]}") | ||
diff_args+=("${original_args[i]}") | ||
done | ||
|
||
# .config/rootmoi/.rootmoiversion hash: {{ include "dot_config/rootmoi/dot_rootmoiversion" | sha256sum }} | ||
ROOTMOI_VERSION=$(cat "${HOME}/.config/rootmoi/.rootmoiversion") | ||
ROOTMOI='{{ joinPath .chezmoi.homeDir ".local/bin/rootmoi" }}' | ||
log_task "Applying root dotfiles with rootmoi (version ${ROOTMOI_VERSION})" | ||
log_c "rootmoi" "${args[@]}" | ||
exec "${ROOTMOI}" "${args[@]}" | ||
|
||
# {{ end -}} |
29 changes: 29 additions & 0 deletions
29
chezmoi/dot_local/bin/executable_dotfiles-initialize-zsh.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# {{- template "scripts-library" }} | ||
log_task "Initializing ZSH" | ||
|
||
# {{- if and (eq .chezmoi.os "linux") }} | ||
|
||
zsh_path="/bin/zsh" | ||
|
||
if ! getent passwd '{{ .chezmoi.username }}' | cut -d : -f 7- | grep -q "^${zsh_path}$"; then | ||
log_task "Configuring ZSH as default shell" | ||
|
||
# {{ if .system.is_sudoer }} | ||
c sudo usermod --shell "${zsh_path}" '{{ .chezmoi.username }}' | ||
# {{ else }} | ||
c chsh --shell "${zsh_path}" | ||
# {{ end }} | ||
fi | ||
|
||
# {{- else if eq .chezmoi.os "darwin" }} | ||
|
||
if [ "$SHELL" != "$(which zsh)" ]; then | ||
log_task "Configuring ZSH as default shell" | ||
|
||
# c sudo dscl . -create "/Users/{{ .chezmoi.username }}" UserShell "$(which zsh)" | ||
c sudo sh -c "echo $(which zsh) >> /etc/shells" | ||
c sudo chsh -s "$(which zsh)" "{{ .chezmoi.username }}" | ||
fi | ||
|
||
# {{- end }} |