- name: copy wallpaper file
  copy:
    src: files/wallpaper.png
    dest: /usr/share/backgrounds/ansible-wallpaper.png
    owner: root
    group: root

- name: download s76 gnome extension
  ansible.builtin.git:
    repo: https://github.com/pop-os/gnome-shell-extension-system76-power.git
    dest: /tmp/s76-power
    single_branch: yes

- name: Build s76 gnome extension
  community.general.make:
    chdir: /tmp/s76-power

- name: Run 'install' s76 gnome extension
  community.general.make:
    chdir: /tmp/s76-power
    target: install       

- name: set gnome config
  become_user: user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:  "{{ dconf }}"      

- name: Check that Oh My ZSH is installed
  become_user: user 
  stat:
    path: "~/.oh-my-zsh"
  register: ohmyzsh_result

- name: Install Oh My ZSH
  become_user: user
  shell: sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  args:
    creates: "~/.oh-my-zsh"
  when: not ohmyzsh_result.stat.exists

- name: "Create a default ZSH configuration"
  become_user: user
  template:
    src: files/zshrc
    dest: "~/.zshrc"
    owner: "user"
    force: yes

- name: Check that Auto Suggestions is installed
  become_user: user
  stat:
    path: ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
  register: auto_suggestions_result

- name: Install Auto Suggestions
  become_user: user
  shell: git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
  when: not auto_suggestions_result.stat.exists
  
- user:
    name: "user"
    shell: /opt/microsoft/powershell/7/pwsh

- name: Create bin folder
  become_user: user
  ansible.builtin.file:
    path: ~/.local/bin
    owner: "user"
    group: "user"
    mode: '0770'     
    state: directory 

- name: Create credentials folder
  become_user: user
  ansible.builtin.file:
    path: ~/.credentials
    owner: "user"
    group: "user"
    mode: '0700'     
    state: directory 

- name: Create config folders
  become_user: user
  ansible.builtin.file:
    path: ~/.config/{{ item.dest }}
    owner: "user"
    group: "user"
    mode: '0700'     
    state: directory 
  with_items:  "{{ configs }}"       
#
#- name: "Copy Config files"
#  become_user: user
#  template:
#    src: "templates/{{ item.src }}"
#    dest: "~/.config/{{ item.dest }}/{{ item.destname }}"
#    owner: "user"
#    force: yes    
#  with_items:  "{{ configs }}"          

- name: Copy Config files
  become_user: user
  copy:
    src: "files/{{ item.src }}"
    dest: "~/.config/{{ item.dest }}/{{ item.destname }}"
    owner: "user"
    force: yes  
  with_items:  "{{ configs }}"   
