1
0

Compare commits

...

20 Commits

Author SHA1 Message Date
b25a30615b Clear the input buffer when asking for confirmation in the setup script 2025-10-13 11:53:35 +02:00
452ce614ef Added basic Neovim config 2025-10-13 11:25:54 +02:00
0d520f7bbf Added .local/bin to PATH 2025-10-13 11:25:18 +02:00
f560e4a942 Removed uselees .gitkeep 2025-10-13 11:12:31 +02:00
4fdd55da97 Added Neovim 2025-10-13 10:32:08 +02:00
6329e7230d Added Starship 2025-10-13 10:02:21 +02:00
8730ff086a Import .gitconfig automatically if in ~/Projects 2025-10-12 15:25:38 +02:00
2ae78ecfaf Added a confirmation dialog before running the setup script 2025-10-12 15:24:27 +02:00
9778a1bcd5 Added the libsecret helper for Git 2025-10-12 12:29:22 +02:00
c8385b97c7 Added Git 2025-10-10 16:26:32 +02:00
29be17d57d Run the shell changing task as root 2025-10-10 16:07:13 +02:00
f1bec95c3e Added distro and become password verification, Set fish shell as the default shell 2025-10-10 16:01:40 +02:00
f59e5dafab Changed the symlink to be the one in home/ 2025-10-10 13:00:17 +02:00
72849ce86d Added some useful command in the README.md 2025-10-04 12:18:21 +02:00
e28efad0c0 Added the Fish shell 2025-10-04 12:03:16 +02:00
f628303ebd Added the script to run the playbook 2025-10-04 09:33:49 +02:00
6eb4b64fb8 Added the base for the Ansible provisioning 2025-10-04 07:32:14 +02:00
fe4c76055f Moved the chezmoi root to "home/" 2025-10-04 07:24:03 +02:00
bb770401cc Updated the README.md 2025-10-03 15:43:28 +02:00
c5dbaea527 Added a .chezmoiignore 2025-09-18 11:09:59 +02:00
24 changed files with 280 additions and 1 deletions

15
.chezmoi.toml.tmpl Normal file
View 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
.chezmoiroot Normal file
View File

@@ -0,0 +1 @@
home

View File

@@ -1,2 +1,39 @@
# dotfiles
<div align="center">
# ~/.dotfiles 🏡
[![chezmoi](https://img.shields.io/badge/chezmoi-4051b5)](https://chezmoi.io/)
[![Ansible](https://img.shields.io/badge/Ansible-ee0000?logo=ansible)](https://ansible.com/)
[![MIT License](https://img.shields.io/badge/License-MIT-dark_green)](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
View File

@@ -0,0 +1 @@
../.chezmoi.toml.tmpl

12
home/.chezmoiignore.tmpl Normal file
View 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 }}

View 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

View File

View 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 }}

View File

@@ -0,0 +1,4 @@
{{- if .features.editor }}
# Set Neovim to be the default editor
set --export EDITOR nvim
{{- end }}

View File

@@ -0,0 +1,2 @@
# Add `~/.local/bin` to PATH
set fish_user_paths {{ joinPath .chezmoi.homeDir ".local/bin" }}

View File

@@ -0,0 +1,5 @@
# Disable the default Fish greeting message
set fish_greeting ""
# Initialize Starship
starship init fish | source

View 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 }}

View 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

View File

2
setup-script/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.ansible
.venv

27
setup-script/ansible.cfg Normal file
View 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

View 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

View File

@@ -0,0 +1 @@
ansible == 12.0.0

View File

@@ -0,0 +1,5 @@
- name: Install Neovim on Arch
become: true
ansible.builtin.pacman:
name: neovim
when: chezmoi.osRelease.id == "arch"

View File

@@ -0,0 +1,5 @@
- name: Install Git on Arch
become: true
ansible.builtin.pacman:
name: git
when: chezmoi.osRelease.id == "arch"

View 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 }}"