---
- set_fact:
    powershell_config_dir:
      '{{ansible_env.USERPROFILE}}/Documents/WindowsPowerShell'

- name: clone config repos
  win_git:
    repo: https://git.infektor.net/config/WindowsPowerShell.git
    dest: '{{powershell_config_dir}}'
    branch: main

- name: remove cmder chocolatey package
  win_chocolatey:
    name: Cmder
    state: absent

- name: get NuGet package provider
  ansible.windows.win_powershell:
    script:
      Get-PackageProvider -Name NuGet
  changed_when: false
  register: nuget_package_provider

- name: install NuGet package provider
  when: nuget_package_provider.error | length > 0
  ansible.windows.win_powershell:
    script: |
      Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

- name: install PsReadline module
  win_psmodule:
    name: PsReadline
    state: latest
    accept_license: true

- name: install posh-git module
  win_psmodule:
    name: posh-git
    state: latest
    accept_license: true

- name: install pwsh for powershell lsp
  community.windows.win_scoop:
    name: pwsh
    state: present

- name: run install script
  win_command:
    cmd: 'powershell.exe {{powershell_config_dir}}/install.ps1'
  register: powershell_install
  changed_when: "'changed' in powershell_install.stdout"