---
- name: Get oh-my-fish installer
  get_url:
    url: https://get.oh-my.fish
    dest: /tmp/oh-my.fish
    mode: '7550'
  changed_when: false

- name: Install oh-my-fish
  shell: fish -c "/tmp/oh-my.fish --noninteractive -y"
  args:
    creates: ~/.config/fish/conf.d/omf.fish

- name: Remove oh-my-fish installer
  file:
    path: /tmp/oh-my.fish
    state: absent
  changed_when: false

- name: Install pureprompt plugin
  become_method: su
  shell: |
    fish -c "omf install pure"
    fish -lc "ln -s $OMF_PATH/themes/pure/conf.d/pure.fish ~/.config/fish/conf.d/pure.fish"
    fish -lc "ln -s $OMF_PATH/themes/pure/conf.d/_pure_init.fish ~/.config/fish/conf.d/pure_init.fish"
  args:
    creates: ~/.config/fish/conf.d/pure.fish

- name: check git plugin install
  shell: grep 'abbr.*git' ~/.config/fish/fish_variables
  register: gitcheck
  ignore_errors: True
  changed_when: false

- name: Install git plugin
  become_method: su
  shell: fish -c "omf install https://github.com/jhillyerd/plugin-git"
  when: gitcheck is failed

- name: Copy dircolors
  copy:
    src: dircolors
    dest: ~/.config/

- name: Sync fish config files (root)
  synchronize:
    src: files/fish
    dest: /root/.config
    recursive: yes
  when: ansible_user_id == "root"
  tags: rsync

- name: Sync fish config files (users)
  synchronize:
    src: files/fish
    dest: ~/.config
    recursive: yes
  when: ansible_user_id != "root"
  tags: rsync

- name: Laptops fish configuration
  copy:
    src: laptop.fish
    dest: ~/.config/fish/conf.d/
  when: "'laptop' in {{ group_names }}"
