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

- name: Clone pyenv plugins
  git:
    depth: 1
    repo: 'https://github.com/pyenv/{{ item }}.git'
    dest: '{{ ansible_env.PYENV_ROOT }}/plugins/{{ item }}'
  loop:
    - pyenv-update
    - pyenv-virtualenv

- name: Symlink pyenv executable
  file:
    src: '{{ ansible_env.PYENV_ROOT }}/libexec/pyenv'
    dest: ~/.local/bin/pyenv
    state: link

- name: Add fish startup hooks
  tags: fish
  blockinfile:
    path: ~/.config/fish/config.fish
    block: |
      # pyenv startup hooks
      status is-login; and pyenv init --path | source
      status is-interactive; and pyenv init - | source
      status is-interactive; and pyenv virtualenv-init - | source
