---
- name: weechat | Create config directory
  file:
    path: '{{ xdg_dir.config_home }}/weechat'
    state: directory
    mode: '755'

- name: weechat | Copy config files
  copy:
    src: weechat/
    dest: '{{ xdg_dir.config_home }}/weechat/'
    mode: '644'

# Dependencies: weechat-lua, weechat-python
- name: weechat | Create lua and python plugins' directories
  file:
    path: '{{ xdg_dir.data_home }}/weechat/{{ item }}/autoload'
    state: directory
    mode: '755'
  loop:
    - lua
    - python

- name: weechat | Install emoji lua script
  vars:
    script_location: '{{ xdg_dir.data_home }}/weechat/lua'
  tags: [weechat-extend, weechat-emoji]
  block:
    - name: weechat | Download emoji.lua script
      get_url:
        url: https://weechat.org/files/scripts/emoji.lua
        dest: '{{ script_location }}/emoji.lua'
        mode: '644'
        force: true

    - name: weechat | Symlink emoji.lua to autoload directory
      file:
        src: ../emoji.lua
        dest: '{{ script_location }}/autoload/emoji.lua'
        state: link

- name: weechat | Install autosort python script
  vars:
    script_location: '{{ xdg_dir.data_home }}/weechat/python'
  tags: [weechat-extend, weechat-autosort]
  block:
    - name: weechat | Download autosort.py script
      get_url:
        url: https://weechat.org/files/scripts/autosort.py
        dest: '{{ script_location }}/autosort.py'
        mode: '644'
        force: true

    - name: weechat | Symlink autosort.py to autoload directory
      file:
        src: ../autosort.py
        dest: '{{ script_location }}/autoload/autosort.py'
        state: link

- name: weechat | Install go python script
  vars:
    script_location: '{{ xdg_dir.data_home }}/weechat/python'
  tags: [weechat-extend, weechat-go]
  block:
    - name: weechat | Download go.py script
      get_url:
        url: https://weechat.org/files/scripts/go.py
        dest: '{{ script_location }}/go.py'
        mode: '644'
        force: true

    - name: weechat | Symlink go.py to autoload directory
      file:
        src: ../go.py
        dest: '{{ script_location }}/autoload/go.py'
        state: link

- name: weechat | Install grep python script
  vars:
    script_location: '{{ xdg_dir.data_home }}/weechat/python'
  tags: [weechat-extend, weechat-grep]
  block:
    - name: weechat | Download grep.py script
      get_url:
        url: https://weechat.org/files/scripts/grep.py
        dest: '{{ script_location }}/grep.py'
        mode: '644'
        force: true

    - name: weechat | Symlink grep.py to autoload directory
      file:
        src: ../grep.py
        dest: '{{ script_location }}/autoload/grep.py'
        state: link

- name: weechat | Install notify_send python script
  vars:
    script_location: '{{ xdg_dir.data_home }}/weechat/python'
  tags: [weechat-extend, weechat-notify-send]
  block:
    - name: weechat | Download notify_send.py script
      get_url:
        url: https://raw.githubusercontent.com/s3rvac/weechat-notify-send/master/notify_send.py
        dest: '{{ script_location }}/notify_send.py'
        mode: '644'
        force: true

    - name: weechat | Symlink notify_send.py to autoload directory
      file:
        src: ../notify_send.py
        dest: '{{ script_location }}/autoload/notify_send.py'
        state: link
