---
# tasks file for starship
- name: Install starship (cross-shell prompt) as a package
  become: true
  ansible.builtin.package:
    state: present
    name: starship
  when: ansible_os_family == 'Archlinux'

- name: Install curl (for starship installation)
  become: true
  ansible.builtin.package:
    state: present
    name: curl
  when: ansible_os_family != 'Archlinux'

- name: Get starship install script
  ansible.builtin.get_url:
    url: https://starship.rs/install.sh
    dest: /tmp/starship_install.sh
    mode: '0755'
  register: starship_installation_script
  when: ansible_os_family != 'Archlinux'

- name: Install starship with installation script
  become: true
  ansible.builtin.shell:
    cmd: /tmp/starship_install.sh --yes
    executable: /bin/sh
  when: ansible_os_family != 'Archlinux' and starship_installation_script.changed
# if the previous task hasn't changed, the shell script is already there
# and we have already installed starship
# we check this to satisfy idempotence

- name: Copy zshrc (for starship)
  ansible.builtin.copy:
    src: zshrc-starship
    dest: ~/.zshrc
    mode: 0644
  when: copy_dot_files