1
0

Compare commits

..

3 Commits

Author SHA1 Message Date
0e86305585 Updated the README.md 2025-09-22 20:24:10 +02:00
0bd8ffd297 Added the dotfiles for the Fish shell 2025-09-22 20:24:02 +02:00
eace0f1c2d Updated the README.md 2025-09-18 13:35:20 +02:00
24 changed files with 38 additions and 263 deletions

View File

@@ -1,15 +0,0 @@
{{- $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 }}

2
.chezmoiignore Normal file
View File

@@ -0,0 +1,2 @@
LICENSE
README.md

View File

@@ -1 +1 @@
home
/home

View File

@@ -3,37 +3,17 @@
# ~/.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/)
> My dotfiles, managed with [chezmoi](https://chezmoi.io/)
## 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
```

View File

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

View File

@@ -1,12 +0,0 @@
{{- 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

@@ -1,68 +0,0 @@
#!/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

@@ -1,7 +0,0 @@
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

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

View File

@@ -0,0 +1,2 @@
# Don't greet the user every time they open the shell
set fish_greeting

View File

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

View File

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

View File

@@ -1,30 +0,0 @@
[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

@@ -1,6 +0,0 @@
-- Enable relative line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Highlight the current line
vim.opt.cursorline = true

View File

@@ -0,0 +1,32 @@
#!/bin/bash
{{ if false -}}
echo "This script must be run in Arch Linux"
exit 1
{{ end -}}
set -eu
{{ if ne .chezmoi.osRelease.id "arch" -}}
echo "You're not running Arch Linux. Skipping..."
exit 0
{{ end -}}
while true; do
read -p "Do you want to run the Arch Linux configuration script? [Y/n] " REPLY
# Treat an empty response as the default "Y"
REPLY=${REPLY:-Y}
case "$REPLY" in
y|Y) break ;;
n|N) exit 0 ;;
*) echo "Unrecognized option. Please answer Y or n." ;;
esac
done
set -x
# Install the Fish shell
sudo pacman --noconfirm -S fish
sudo chsh -s "$(which fish)" $USER

View File

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

View File

@@ -1,27 +0,0 @@
[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

@@ -1,31 +0,0 @@
- 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

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

View File

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

View File

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

View File

@@ -1,20 +0,0 @@
- 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 }}"