Compare commits
19 Commits
f0511c8362
...
main
Author | SHA1 | Date | |
---|---|---|---|
b25a30615b | |||
452ce614ef | |||
0d520f7bbf | |||
f560e4a942 | |||
4fdd55da97 | |||
6329e7230d | |||
8730ff086a | |||
2ae78ecfaf | |||
9778a1bcd5 | |||
c8385b97c7 | |||
29be17d57d | |||
f1bec95c3e | |||
f59e5dafab | |||
72849ce86d | |||
e28efad0c0 | |||
f628303ebd | |||
6eb4b64fb8 | |||
fe4c76055f | |||
bb770401cc |
15
.chezmoi.toml.tmpl
Normal file
15
.chezmoi.toml.tmpl
Normal file
@@ -0,0 +1,15 @@
|
||||
{{- $email := promptStringOnce . "email" "What's your email" }}
|
||||
{{- $git_name := promptStringOnce . "git_name" "What's your Git name" }}
|
||||
|
||||
{{- $shell := promptBoolOnce . "features.shell" "Do you want to install the Fish shell" true }}
|
||||
{{- $git := promptBoolOnce . "features.git" "Do you want to install Git" true }}
|
||||
{{- $editor := promptBoolOnce . "features.editor" "Do you want to install Neovim" true }}
|
||||
|
||||
[data]
|
||||
email = {{ $email | quote }}
|
||||
git_name = {{ $git_name | quote }}
|
||||
|
||||
[data.features]
|
||||
shell = {{ $shell }}
|
||||
git = {{ $git }}
|
||||
editor = {{ $editor }}
|
@@ -1,2 +0,0 @@
|
||||
LICENSE
|
||||
README.md
|
1
.chezmoiroot
Normal file
1
.chezmoiroot
Normal file
@@ -0,0 +1 @@
|
||||
home
|
39
README.md
39
README.md
@@ -1,2 +1,39 @@
|
||||
# dotfiles
|
||||
<div align="center">
|
||||
|
||||
# ~/.dotfiles 🏡
|
||||
|
||||
[](https://chezmoi.io/)
|
||||
[](https://ansible.com/)
|
||||
[](https://choosealicense.com/licenses/mit/)
|
||||
|
||||
</div><br>
|
||||
|
||||
> My dotfiles, managed with [chezmoi](https://chezmoi.io/) and
|
||||
> [Ansible](https://ansible.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
Install [chezmoi](https://chezmoi.io/install/), then run:
|
||||
|
||||
```sh
|
||||
# Initialize the repository
|
||||
chezmoi init git.nicolabelluti.me/nicolabelluti
|
||||
# You can also just use
|
||||
# `chezmoi init nicolabelluti`
|
||||
# if you want to use the GitHub mirror
|
||||
|
||||
# Apply the dotfiles
|
||||
chezmoi apply
|
||||
```
|
||||
|
||||
If you want to update the dotfiles:
|
||||
|
||||
```sh
|
||||
chezmoi update --init
|
||||
```
|
||||
|
||||
To give a new answer to the prompts:
|
||||
|
||||
```sh
|
||||
chezmoi init --prompt
|
||||
```
|
||||
|
1
home/.chezmoi.toml.tmpl
Symbolic link
1
home/.chezmoi.toml.tmpl
Symbolic link
@@ -0,0 +1 @@
|
||||
../.chezmoi.toml.tmpl
|
12
home/.chezmoiignore.tmpl
Normal file
12
home/.chezmoiignore.tmpl
Normal file
@@ -0,0 +1,12 @@
|
||||
{{- if not .features.shell }}
|
||||
.config/fish
|
||||
.config/starship.toml
|
||||
{{- end }}
|
||||
|
||||
{{- if not .features.git }}
|
||||
.config/git
|
||||
{{- end }}
|
||||
|
||||
{{- if not .features.editor }}
|
||||
.config/nvim
|
||||
{{- end }}
|
68
home/.chezmoiscripts/run_before_archlinux.sh.tmpl
Executable file
68
home/.chezmoiscripts/run_before_archlinux.sh.tmpl
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Check is the script is being run using chezmoi
|
||||
{{- if false }}
|
||||
echo "This script must be run using chezmoi! Aborting..."
|
||||
exit 1
|
||||
{{- end }}
|
||||
|
||||
# Run this script only on Arch Linux
|
||||
{{- if ne .chezmoi.osRelease.id "arch" }}
|
||||
exit 0
|
||||
{{- end }}
|
||||
|
||||
# Make the script stop if something goes wrong:
|
||||
# -e: any command fails
|
||||
# -u: unset variable is used
|
||||
# -o pipefail: a pipeline fails if any command fails
|
||||
set -euo pipefail
|
||||
|
||||
# Show a clear error before exiting
|
||||
SCRIPT_PATH="{{ trimPrefix "/" (trimPrefix .chezmoi.workingTree (joinPath .chezmoi.sourceDir .chezmoi.sourceFile)) }}"
|
||||
trap 'echo -e "\n\033[1;31mError: Script \"$SCRIPT_PATH\" failed at line $LINENO\033[0m\n" >&2; exit 1' ERR
|
||||
|
||||
# </init>
|
||||
# <core>
|
||||
|
||||
# Ask for confirmation before running the script
|
||||
while true; do
|
||||
read -p "Do you want to run the setup script? [Y/n]: " -n 1 -r REPLY
|
||||
|
||||
# Clear the input buffer and add a newline
|
||||
while read -t 0.001 TMP; do continue; done
|
||||
echo
|
||||
|
||||
# Convert to lowercase and default to 'y' if empty
|
||||
REPLY=${REPLY:-y}
|
||||
|
||||
case $REPLY in
|
||||
Y|y|1) break ;;
|
||||
N|n|0) exit 0 ;;
|
||||
*) echo "Invalid input. Please enter y or n." ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if python3 and python3-venv are installed
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
echo -e "\e[1;34mpython3 not found. Installing it...\e[0m"
|
||||
sudo pacman --noconfirm -Sy python
|
||||
fi
|
||||
|
||||
ANSIBLE_ROOT="{{ .chezmoi.workingTree }}/setup-script"
|
||||
|
||||
# Check if there is a venv in "setup-script/"
|
||||
if [ ! -d "$ANSIBLE_ROOT/.venv" ]; then
|
||||
echo -e "\e[1;34mNo venv found in "$ANSIBLE_ROOT". Creating one...\e[0m"
|
||||
python3 -m venv "$ANSIBLE_ROOT/.venv"
|
||||
|
||||
echo -e "\e[1;34mInstalling the dependencies...\e[0m"
|
||||
"$ANSIBLE_ROOT/.venv/bin/pip3" install -r "$ANSIBLE_ROOT/requirements.txt"
|
||||
fi
|
||||
|
||||
# Run the playbook
|
||||
echo -e "\e[1;34mRunning the playbook...\e[0m"
|
||||
ANSIBLE_CONFIG="$ANSIBLE_ROOT/ansible.cfg" \
|
||||
"$ANSIBLE_ROOT/.venv/bin/ansible-playbook" \
|
||||
"$ANSIBLE_ROOT/playbook.yaml" \
|
||||
--extra-vars "$(chezmoi data --format=json)" \
|
||||
--ask-become-pass
|
0
home/dot_local/bin/.gitkeep
Normal file
0
home/dot_local/bin/.gitkeep
Normal file
0
home/private_dot_config/fish/completions/.gitkeep
Normal file
0
home/private_dot_config/fish/completions/.gitkeep
Normal file
7
home/private_dot_config/fish/conf.d/aliases.fish.tmpl
Normal file
7
home/private_dot_config/fish/conf.d/aliases.fish.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
abbr --add --position command l ls -lAh
|
||||
|
||||
{{- if .features.editor }}
|
||||
# Alias `vi` and `vim` to Neovim
|
||||
abbr --add --position command vim nvim
|
||||
abbr --add --position command vi nvim
|
||||
{{- end }}
|
@@ -0,0 +1,4 @@
|
||||
{{- if .features.editor }}
|
||||
# Set Neovim to be the default editor
|
||||
set --export EDITOR nvim
|
||||
{{- end }}
|
2
home/private_dot_config/fish/conf.d/path.fish.tmpl
Normal file
2
home/private_dot_config/fish/conf.d/path.fish.tmpl
Normal file
@@ -0,0 +1,2 @@
|
||||
# Add `~/.local/bin` to PATH
|
||||
set fish_user_paths {{ joinPath .chezmoi.homeDir ".local/bin" }}
|
5
home/private_dot_config/fish/conf.d/staship.fish
Normal file
5
home/private_dot_config/fish/conf.d/staship.fish
Normal file
@@ -0,0 +1,5 @@
|
||||
# Disable the default Fish greeting message
|
||||
set fish_greeting ""
|
||||
|
||||
# Initialize Starship
|
||||
starship init fish | source
|
0
home/private_dot_config/fish/functions/.gitkeep
Normal file
0
home/private_dot_config/fish/functions/.gitkeep
Normal file
0
home/private_dot_config/fish/remove_config.fish
Normal file
0
home/private_dot_config/fish/remove_config.fish
Normal file
30
home/private_dot_config/git/config.tmpl
Normal file
30
home/private_dot_config/git/config.tmpl
Normal file
@@ -0,0 +1,30 @@
|
||||
[user]
|
||||
email = {{ .email }}
|
||||
name = {{ .git_name }}
|
||||
|
||||
[init]
|
||||
defaultBranch = main
|
||||
|
||||
[merge]
|
||||
ff = true
|
||||
|
||||
{{- $credentialHelperPath := "" }}
|
||||
{{- if eq .chezmoi.osRelease.id "arch" }}
|
||||
{{- $credentialHelperPath = "/usr/lib/git-core/git-credential-libsecret" }}
|
||||
{{- end }}
|
||||
|
||||
{{- if $credentialHelperPath }}
|
||||
[credential]
|
||||
helper = {{ $credentialHelperPath }}
|
||||
{{- end }}
|
||||
|
||||
{{- $projectsDir := joinPath .chezmoi.homeDir "Projects" }}
|
||||
{{- if stat $projectsDir }}
|
||||
{{- $projects := output "find" $projectsDir "-type" "f" "-mindepth" "2" "-maxdepth" "2" "-name" ".gitconfig" | trim | splitList "\n" }}
|
||||
{{- range $projects }}
|
||||
{{- if . }}
|
||||
[includeIf "gitdir:{{ . | dir }}/**/"]
|
||||
path = {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
6
home/private_dot_config/nvim/init.lua
Normal file
6
home/private_dot_config/nvim/init.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- Enable relative line numbers
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
|
||||
-- Highlight the current line
|
||||
vim.opt.cursorline = true
|
0
home/private_dot_config/starship.toml
Normal file
0
home/private_dot_config/starship.toml
Normal file
2
setup-script/.gitignore
vendored
Normal file
2
setup-script/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.ansible
|
||||
.venv
|
27
setup-script/ansible.cfg
Normal file
27
setup-script/ansible.cfg
Normal file
@@ -0,0 +1,27 @@
|
||||
[defaults]
|
||||
# (path) The default root path for Ansible config files on the controller.
|
||||
home=./.ansible
|
||||
|
||||
# (boolean) If you have cowsay installed but want to avoid the 'cows' (why????), use this.
|
||||
nocows = true
|
||||
|
||||
# (pathspec) Colon separated paths in which Ansible will search for Roles.
|
||||
roles_path = ./roles
|
||||
|
||||
# (boolean) By default, Ansible will issue a warning when there are no hosts in the inventory.
|
||||
# These warnings can be silenced by adjusting this setting to False.
|
||||
localhost_warning = false
|
||||
|
||||
# (str) Define the task result format used in the callback output.
|
||||
# These formats do not cause the callback to emit valid JSON or YAML formats.
|
||||
# The output contains these formats interspersed with other non-machine parsable data.
|
||||
callback_result_format = yaml
|
||||
|
||||
[diff]
|
||||
# (bool) Configuration toggle to tell modules to show differences when in 'changed' status, equivalent to ``--diff``.
|
||||
always = true
|
||||
|
||||
[inventory]
|
||||
# (boolean) By default, Ansible will issue a warning when no inventory was loaded and notes that it will use an implicit localhost-only inventory.
|
||||
# These warnings can be silenced by adjusting this setting to False.
|
||||
inventory_unparsed_warning = false
|
31
setup-script/playbook.yaml
Normal file
31
setup-script/playbook.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
- name: Prepare the base environment
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
|
||||
pre_tasks:
|
||||
- name: Ensure the "chezmoi" variable is set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- chezmoi is not undefined
|
||||
- chezmoi is mapping
|
||||
fail_msg: 'Pass with: --extra-vars "$(chezmoi data --format=json)"'
|
||||
|
||||
- name: Verify the become password is correct
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: "true"
|
||||
changed_when: false
|
||||
|
||||
- name: Verify the distro
|
||||
ansible.builtin.debug:
|
||||
msg: "The setup script for now supports only Arch Linux!"
|
||||
when: chezmoi.osRelease.id != "arch"
|
||||
|
||||
roles:
|
||||
- role: shell
|
||||
when: features.shell == true
|
||||
- role: git
|
||||
when: features.git == true
|
||||
- role: editor
|
||||
when: features.editor == true
|
1
setup-script/requirements.txt
Normal file
1
setup-script/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
ansible == 12.0.0
|
5
setup-script/roles/editor/tasks/main.yaml
Normal file
5
setup-script/roles/editor/tasks/main.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Install Neovim on Arch
|
||||
become: true
|
||||
ansible.builtin.pacman:
|
||||
name: neovim
|
||||
when: chezmoi.osRelease.id == "arch"
|
5
setup-script/roles/git/tasks/main.yaml
Normal file
5
setup-script/roles/git/tasks/main.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Install Git on Arch
|
||||
become: true
|
||||
ansible.builtin.pacman:
|
||||
name: git
|
||||
when: chezmoi.osRelease.id == "arch"
|
20
setup-script/roles/shell/tasks/main.yaml
Normal file
20
setup-script/roles/shell/tasks/main.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
- name: Install Fish shell and Starship on Arch
|
||||
become: true
|
||||
ansible.builtin.pacman:
|
||||
name:
|
||||
- fish
|
||||
- starship
|
||||
- ttf-nerd-fonts-symbols # Required for Starship
|
||||
when: chezmoi.osRelease.id == "arch"
|
||||
|
||||
- name: Find Fish shell binary
|
||||
command: which fish
|
||||
register: fish_path
|
||||
changed_when: false
|
||||
failed_when: fish_path.rc != 0
|
||||
|
||||
- name: Set the user's shell
|
||||
become: true
|
||||
ansible.builtin.user:
|
||||
name: "{{ chezmoi.username }}"
|
||||
shell: "{{ fish_path.stdout }}"
|
Reference in New Issue
Block a user