---
#- name: Get oh-my-fish installer
#  get_url:
#    url: https://get.oh-my.fish
#    dest: /tmp/oh-my.fish
#    mode: '0777'
#    # TORM https://github.com/oh-my-fish/oh-my-fish/issues/799
#    #validate_certs: no
#  changed_when: false
#
#- name: Install oh-my-fish
#  shell: /tmp/oh-my.fish --noninteractive -y
#  args:
#    creates: ~/.config/fish/conf.d/omf.fish
#    executable: /usr/bin/fish
#
#- name: Remove oh-my-fish installer
#  file:
#    path: /tmp/oh-my.fish
#    state: absent
#  changed_when: false

- name: Install fisher
  shell: curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
  args:
    creates: ~/.config/fish/functions/fisher.fish
    executable: fish

- name: Install git plugin
  become_method: su
  shell: fisher install jhillyerd/plugin-git
  args:
    executable: fish

- name: Install done plugin
  become_method: su
  shell: fisher install franciscolourenco/done
  args:
    executable: fish
  when: "'desktop' in group_names"

- name: Copy starship config
  copy:
    src: starship.toml
    dest: ~/.config/

- name: create fish completion dir
  file:
    path: ~/.config/fish/completions
    state: directory

- name: install kubectl fish completion
  git:
    repo: https://github.com/evanlucas/fish-kubectl-completions
    dest: ~/.config/fish/completions/fish-kubectl-completions

- name: enable kubectl fish completion
  file:
    src: ~/.config/fish/completions/fish-kubectl-completions/completions/kubectl.fish
    dest: ~/.config/fish/completions/kubectl.fish
    state: link

# Separated root|users synchronize as module bugs when using become on the task: it copies always in user homedir
- name: Sync fish config files for cli user
  synchronize:
    src: fish/cli/
    dest: ~/.config/fish
    recursive: yes
  when: ansible_user_id != 'root'
  tags: rsync

- name: Sync fish config files for cli root
  synchronize:
    src: fish/cli/
    dest: /root/.config/fish
    recursive: yes
  when: ansible_user_id == 'root'
  tags: rsync

- name: Sync fish config files for desktop user
  synchronize:
    src: fish/desktop/
    dest: ~/.config/fish
    recursive: yes
  when: ansible_user_id != 'root' and 'desktop' in group_names
  tags: rsync
