---
- name: pyenv | Clone pyenv repository
  git:
    depth: 1
    repo: https://github.com/pyenv/pyenv.git
    dest: '{{ ansible_env.PYENV_ROOT }}'

- name: pyenv | Clone pyenv plugins
  git:
    depth: 1
    repo: 'https://github.com/pyenv/{{ item }}.git'
    dest: '{{ ansible_env.PYENV_ROOT }}/plugins/{{ item }}'
  loop:
    - pyenv-ccache # requires `ccache` package installed
    - pyenv-update
    - pyenv-virtualenv

- name: pyenv | Symlink pyenv executable
  file:
    src: '{{ ansible_env.PYENV_ROOT }}/libexec/pyenv'
    dest: '{{ xdg_dir.bin_home }}/pyenv'
    state: link

- name: pyenv | Add fish startup hooks
  tags: fish
  blockinfile:
    path: '{{ xdg_dir.config_home }}/fish/config.fish'
    marker: '# {mark} pyenv startup hooks'
    block: |
      status is-interactive; and pyenv init - fish | source
      status is-interactive; and pyenv virtualenv-init - fish | source
    state: present
