- include_role:
    name: per_user

- name: Create directories
  file:
    name: "{{ account_homedir.stdout }}/{{ item }}"
    state: directory
    mode: 0700
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - ".config/emacs/elisp"

- name: Configure dotfiles
  when: 'emacs_flavor == "full"'
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ account_homedir.stdout }}/{{ item.dest }}"
    mode: 0600
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - src: init.el
      dest: .config/emacs/init.el
    - src: early-init.el
      dest: .config/emacs/early-init.el

- name: Configure dotfiles
  when: 'emacs_flavor == "plain"'
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ account_homedir.stdout }}/{{ item.dest }}"
    mode: 0600
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - src: plainmacs_init.el
      dest: .config/emacs/init.el

- name: Configure elisp files
  when: 'emacs_flavor == "full"'
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ account_homedir.stdout }}/{{ item.dest }}"
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - src: elisp
      dest: .config/emacs/

- name: Configure zshrc additional imports
  copy:
    src: "files/zshrc_{{ item }}"
    dest: "{{ account_homedir.stdout }}/.config/ansible_deploy/zshrc/{{ item }}.zsh"
    mode: 0600
    owner: "{{ account_name.stdout }}"
    group: "{{ group_name.stdout }}"
  loop:
    - emacs_e # Create an alias 'e' which launches emacs
    - plainmacs # Set the EDITOR to plainmacs

- import_tasks: tasks/peruser_freebsd.yaml
  when: 'os_flavor == "freebsd"'

- import_tasks: tasks/peruser_linux.yaml
  when: 'os_flavor == "linux"'
