89 lines
3.0 KiB
YAML
89 lines
3.0 KiB
YAML
---
|
|
# Install powerlevel10k
|
|
- name: Ensure dependencies are installed.
|
|
ansible.builtin.package:
|
|
name: "{{ p10k_dependencies }}"
|
|
state: present
|
|
become: true
|
|
when: p10k_dependencies
|
|
|
|
- name: Get ZSH version
|
|
ansible.builtin.shell: "set -o pipefail; zsh --version | cut -d ' ' -f2 | cut -c1-3"
|
|
args:
|
|
executable: /bin/bash
|
|
check_mode: no
|
|
changed_when: false
|
|
register: zsh_version
|
|
|
|
- name: Powerlevel10k works only with ZSH >= 5.1
|
|
ansible.builtin.fail:
|
|
msg: "You are using ZSH version {{ zsh_version.stdout }}. The minimum required version for Powerlevel10k is 5.1"
|
|
when: zsh_version.stdout|float < 5.1
|
|
|
|
- name: Get users information
|
|
ansible.builtin.user:
|
|
name: "{{ item }}"
|
|
state: present
|
|
register: p10k_users_register
|
|
loop: "{{ p10k_users }}"
|
|
|
|
- name: Extract only 'name', 'home' and 'group' fields from users information
|
|
ansible.builtin.set_fact:
|
|
p10k_users_information: "{{ p10k_users_information | default([]) + [{'name': item['name'], 'home': item['home'], 'group': item['group']}] }}"
|
|
no_log: true
|
|
loop: "{{ p10k_users_register.results }}"
|
|
|
|
- name: Install powerlevel10k.
|
|
ansible.builtin.git:
|
|
repo: "{{ p10k_repository_url }}"
|
|
dest: "{{ item['home'] }}/{{ p10k_path[zsh_plugin] | default('~/powerlevel10k', True) }}"
|
|
depth: '1'
|
|
update: no
|
|
version: 'master'
|
|
loop: "{{ p10k_users_information }}"
|
|
|
|
- name: Setup powerlevel10k file permissions.
|
|
ansible.builtin.file:
|
|
path: "{{ item['home'] }}/{{ p10k_path[zsh_plugin] | default('~/powerlevel10k', True) }}"
|
|
owner: "{{ item['name'] }}"
|
|
group: "{{ item['group'] }}"
|
|
recurse: yes
|
|
loop: "{{ p10k_users_information }}"
|
|
|
|
- name: Add powerlevel10k to zsh plugin
|
|
ansible.builtin.lineinfile:
|
|
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
|
|
regexp: "{{ p10k_zshrc_config[zsh_plugin]['regexp'] }}"
|
|
line: "{{ p10k_zshrc_config[zsh_plugin]['line'] }}"
|
|
owner: "{{ item['name'] }}"
|
|
group: "{{ item['group'] }}"
|
|
mode: '0644'
|
|
create: yes
|
|
loop: "{{ p10k_users_information }}"
|
|
|
|
- name: Enable powerlevel10 instant prompt
|
|
ansible.builtin.blockinfile:
|
|
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
|
|
owner: "{{ item['name'] }}"
|
|
group: "{{ item['group'] }}"
|
|
block: |
|
|
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
|
|
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
|
|
fi
|
|
insertbefore: BOF
|
|
marker_begin: "BEGIN P10K INSTANT PROMPT"
|
|
marker_end: "END P10K INSTANT PROMPT"
|
|
loop: "{{ p10k_users_information }}"
|
|
|
|
- name: Enable powerlevel10k config file
|
|
ansible.builtin.blockinfile:
|
|
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
|
|
owner: "{{ item['name'] }}"
|
|
group: "{{ item['group'] }}"
|
|
block: |
|
|
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
|
|
insertafter: EOF
|
|
marker_begin: "BEGIN P10K CONFIG FILE"
|
|
marker_end: "END P10K CONFIG FILE"
|
|
loop: "{{ p10k_users_information }}"
|