---
- name: Install emacs
  community.general.pacman:
    name:
      - emacs-nativecomp
      - nodejs-lts-gallium
      - ripgrep
      - fd
      - editorconfig-core-c
      - graphviz
      - aspell
      - aspell-en
      - wkhtmltopdf
    state: present

- name: copy doom configs
  ansible.builtin.copy:
    src: user_home/.doom.d
    dest: /home/{{ username }}/
    force: False
    owner: "{{ username }}"
    group: "{{ username }}"

- name: checkout doom emacs repo
  become_user: "{{ username }}"
  ansible.builtin.git:
    repo: 'https://github.com/doomemacs/doomemacs'
    dest: /home/{{ username }}/.emacs.d
    depth: 1

- name: install doom emacs
  become_user: "{{ username }}"
  ansible.builtin.command: /home/{{ username }}/.emacs.d/bin/doom sync

- name: update env doom emacs
  become_user: "{{ username }}"
  ansible.builtin.command: /home/{{ username }}/.emacs.d/bin/doom env

- name: make sure local font directory
  become_user: "{{ username }}"
  ansible.builtin.file:
    path: /home/{{ username }}/.local/share/fonts
    state: "directory"

- name: download icon fonts
  become_user: "{{ username }}"
  ansible.builtin.get_url:
    url: "https://raw.githubusercontent.com/domtronn/all-the-icons.el/master/fonts/{{ item }}"
    dest: /home/{{ username }}/.local/share/fonts/{{ item }}
    mode: "0644"
  with_items:
    - all-the-icons.ttf
    - file-icons.ttf
    - fontawesome.ttf
    - material-design-icons.ttf
    - octicons.ttf
    - weathericons.ttf

- name: update font cache
  become_user: "{{ username }}"
  ansible.builtin.command: fc-cache -f -v
