---

- name: Install visidata and libraries
  pacman:
    name:
      - visidata
      - python-lxml
      - python-openpyxl
      - python-pandas
      - python-requests
      - python-xlrd
    state: present

- name: Push visidata desktop file
  copy:
    src: visidata.desktop
    dest: /usr/local/share/applications/visidata.desktop

- name: Verify mimeapps.list exists
  copy:
    content: ""
    dest: /etc/xdg/mimeapps.list
    force: false

- name: Set visidata as default application for relevant mimetypes
  lineinfile:
    dest: /etc/xdg/mimeapps.list
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
  with_items:
    - { regexp: '^text/csv=', line: 'text/csv=visidata.desktop' }
    - { regexp: '^text/tab-separated-values=', line: 'text/tab-separated-values=visidata.desktop' }
