---
- name: Ensure bat package is installed
  tags: [packages]
  ansible.builtin.package:
    name: bat
    state: present

- name: Ensure XDG user directories exist
  tags: [dotfiles, dotfiles:common]
  ansible.builtin.file:
    path: "{{ user_home }}/{{ item }}"
    state: directory
    owner: "{{ username }}"
    group: "{{ user_group }}"
    mode: "0755"
  loop: "{{ xdg_user_directories | default([]) }}"

- name: Copy common dotfiles
  tags: [dotfiles, dotfiles:common]
  ansible.builtin.copy:
    src: "{{ playbook_dir }}/../dotfiles/common/{{ item.src }}"
    dest: "{{ user_home }}/{{ item.dest }}"
    owner: "{{ username }}"
    group: "{{ user_group }}"
    mode: "{{ item.mode }}"
  loop: "{{ common_dotfiles | default([]) }}"
  loop_control:
    label: "{{ item.dest }}"

- name: Refresh bat cache
  tags: [dotfiles, dotfiles:common]
  ansible.builtin.command:
    cmd: "{{ 'batcat' if ansible_facts.os_family == 'Debian' else 'bat' }} cache --build"
  become_user: "{{ username }}"
  environment:
    HOME: "{{ user_home }}"
  changed_when: false
