---
- name: Add zsh-syntax-highlighting repo key [Debian jessie]
  apt_key:
    url: https://download.opensuse.org/repositories/shells:zsh-users:zsh-syntax-highlighting/Debian_8.0/Release.key
    state: present
  become: True
  when:
    - ansible_distribution == "Debian"
    - ansible_distribution_release == "jessie"

- name: Add zsh-syntax-highlighting repo key [Debian stretch]
  apt_key:
    url: https://download.opensuse.org/repositories/shells:zsh-users:zsh-syntax-highlighting/Debian_9.0/Release.key
    state: present
  become: True
  when:
    - ansible_distribution == "Debian"
    - ansible_distribution_release == "stretch"

- name: Configure zsh-syntax-highlighting repo [Debian jessie]
  apt_repository:
    repo: 'deb http://download.opensuse.org/repositories/shells:/zsh-users:/zsh-syntax-highlighting/Debian_8.0/ /'
    state: present
    update_cache: yes
  become: True
  when:
    - ansible_distribution == "Debian"
    - ansible_distribution_release == "jessie"

- name: Configure zsh-syntax-highlighting repo [Debian stretch]
  apt_repository:
    repo: 'deb http://download.opensuse.org/repositories/shells:/zsh-users:/zsh-syntax-highlighting/Debian_9.0/ /'
    state: present
    update_cache: yes
  become: True
  when:
    - ansible_distribution == "Debian"
    - ansible_distribution_release == "stretch"

- name: Install zsh [Debian]
  apt: name={{item}} state=present force=yes update_cache=yes
  with_items:
    - zsh
    - most
    - zsh-syntax-highlighting
  become: True
  when: ansible_distribution == "Debian"
  ignore_errors: True

- name: Configure zsh-syntax-highlighting repo [CentOS]
  shell: creates=/etc/yum.repos.d/shells:zsh-users:zsh-syntax-highlighting.repo cd /etc/yum.repos.d/; wget https://download.opensuse.org/repositories/shells:zsh-users:zsh-syntax-highlighting/CentOS_7/shells:zsh-users:zsh-syntax-highlighting.repo
  become: True
  when: ansible_distribution == "CentOS"

- name: Install zsh
  package: name={{item}} state=present
  with_items:
    - zsh
    - most
    - zsh-syntax-highlighting
  become: True
  when: ansible_distribution != "Debian"
  ignore_errors: True

- name: Install oh-my-zsh
  shell: creates=~/.oh-my-zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh) ||:"

- name: Search for zsh-syntax-highlighting
  shell: find /usr -name zsh-syntax-highlighting.zsh 2>/dev/null
  become: True
  check_mode: no
  changed_when: False
  register: zsh_syntax_highlighting_dir

- name: Configure zshrc
  template: src=templates/zshrc.j2 dest=~/.zshrc backup=yes

- debug:
    msg: "Do not forget to 'chsh /usr/bin/zsh'"

- name: Create zsh dirs
  file: path={{item}} state=directory
  with_items:
    - ~/.zfunctions
    - ~/.zsh

- name: Clone zsh-autosuggestions repo
  git:
    repo: https://github.com/zsh-users/zsh-autosuggestions
    dest: ~/.zsh/zsh-autosuggestions

- name: Clone pure repo
  git:
    repo: https://github.com/sindresorhus/pure
    dest: ~/.zsh/pure

- name: Configure Pure Prompt
  file: src=~/.zsh/pure/pure.zsh dest=~/.zfunctions/prompt_pure_setup state=link
  ignore_errors: True

- name: Configure Pure Prompt bis
  file: src=~/.zsh/pure/async.zsh dest=~/.zfunctions/async state=link
  ignore_errors: True

- name: Init zshrc_node
  file: path=~/.zshrc_node state=touch
  changed_when: False

