---
- name: Create directories
  file:
    path: '{{ item }}'
    state: directory
    mode: '755'
  loop:
    - '{{ xdg_dir.bin_home }}'
    - '{{ xdg_dir.libexec_dir }}'

- name: Synchronize bin
  copy:
    src: bin/
    dest: '{{ xdg_dir.bin_home }}/'
    mode: '755'

- name: Synchronize libexec
  ansible.posix.synchronize:
    src: libexec/
    dest: '{{ xdg_dir.libexec_dir }}/'
    recursive: true
    delete: false

- name: Copy script templates
  template:
    src: '{{ item.name }}.j2'
    dest: '{{ item.dest }}'
    mode: '755'
  loop:
    - name: preview
      dest: '{{ xdg_dir.bin_home }}/preview.sh'
    - name: bukumenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/bukumenu'
    - name: calcmenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/calcmenu'
    - name: clipboard
      dest: '{{ xdg_dir.libexec_dir }}/wayland/clipboard'
    - name: dismiss_notify
      dest: '{{ xdg_dir.libexec_dir }}/wayland/dismiss_notify'
    - name: launch_wallpaper
      dest: '{{ xdg_dir.libexec_dir }}/wayland/launch_wallpaper'
    - name: mangamenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/mangamenu'
    - name: musicmenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/musicmenu'
    - name: notifymenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/notifymenu'
    - name: screenshot
      dest: '{{ xdg_dir.libexec_dir }}/wayland/screenshot'
    - name: searchmenu
      dest: '{{ xdg_dir.libexec_dir }}/wayland/searchmenu'
    - name: sway_window
      dest: '{{ xdg_dir.libexec_dir }}/wayland/sway_window'

- name: Install external scripts with curl
  import_tasks: curl.yml
  tags: curl

- name: Symlink jq executable to {{ jq_binary }}
  file:
    src: '{{ jq_binary }}'
    dest: '{{ xdg_dir.bin_home }}/jq'
    state: link
    force: true
