-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzsh_powerlevel10k.yml
More file actions
177 lines (154 loc) · 6.6 KB
/
Copy pathzsh_powerlevel10k.yml
File metadata and controls
177 lines (154 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
- hosts: all
become: true
tasks:
- name: Update apt cache and Install Zsh, fzf, git, and curl
apt:
name:
- zsh
- fzf
- git
- curl
state: latest
update_cache: yes
- name: Find user directories in /home/
ansible.builtin.find:
paths: /home
file_type: directory
register: found_users
- name: Set user directories variable
set_fact:
user_dirs: "{{ found_users.files | map(attribute='path') | list }}"
- name: Check if .oh-my-zsh exists for each user
ansible.builtin.stat:
path: '{{ item }}/.oh-my-zsh'
loop: '{{ user_dirs }}'
register: oh_my_zsh_check
- name: Install Oh-My-Zsh for each user
ansible.builtin.shell: |
sudo -u {{ item | regex_replace('^/home/', '') }} sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
loop: '{{ user_dirs }}'
args:
creates: '{{ item }}/.oh-my-zsh'
- name: Clone Powerlevel10k theme into Oh-My-Zsh custom themes folder for each user
ansible.builtin.git:
repo: 'https://github.com/romkatv/powerlevel10k.git'
dest: '{{ item }}/.oh-my-zsh/custom/themes/powerlevel10k'
version: 'master'
loop: '{{ user_dirs }}'
- name: Set ZSH_THEME to powerlevel10k/powerlevel10k in .zshrc for each user
ansible.builtin.lineinfile:
path: '{{ item }}/.zshrc'
regexp: '^ZSH_THEME="[^"]*"'
line: 'ZSH_THEME="powerlevel10k/powerlevel10k"'
state: present
loop: '{{ user_dirs }}'
- name: Check if zsh-autosuggestions plugin exists for each user
ansible.builtin.stat:
path: '{{ item }}/.oh-my-zsh/custom/plugins/zsh-autosuggestions'
loop: '{{ user_dirs }}'
register: zsh_autosuggestions_check
become: true
- name: Clone zsh-autosuggestions plugin for each user
ansible.builtin.git:
repo: 'https://github.com/zsh-users/zsh-autosuggestions.git'
dest: '{{ item.item }}/.oh-my-zsh/custom/plugins/zsh-autosuggestions'
version: master
loop: '{{ zsh_autosuggestions_check.results }}'
when: not item.stat.exists
become: true
become_user: "{{ item.item | regex_replace('^/home/', '') }}"
- name: Check if zsh-syntax-highlighting plugin exists for each user
ansible.builtin.stat:
path: '{{ item }}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting'
loop: '{{ user_dirs }}'
register: zsh_syntax_highlighting_check
become: true
- name: Clone zsh-syntax-highlighting plugin for each user
ansible.builtin.git:
repo: 'https://github.com/zsh-users/zsh-syntax-highlighting.git'
dest: '{{ item.item }}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting'
version: master
loop: '{{ zsh_syntax_highlighting_check.results }}'
when: not item.stat.exists
- name: Check if zsh-history-substring-search plugin exists for each user
ansible.builtin.stat:
path: '{{ item }}/.oh-my-zsh/custom/plugins/zsh-history-substring-search'
loop: '{{ user_dirs }}'
register: zsh_history_substring_search_check
become: true
- name: Clone zsh-history-substring-search plugin for each user
ansible.builtin.git:
repo: 'https://github.com/zsh-users/zsh-history-substring-search.git'
dest: '{{ item.item }}/.oh-my-zsh/custom/plugins/zsh-history-substring-search'
version: master
loop: '{{ zsh_history_substring_search_check.results }}'
when: not item.stat.exists
- name: Enable additional plugins in .zshrc for each user
ansible.builtin.lineinfile:
path: '{{ item }}/.zshrc'
regexp: '^(plugins=\()'
line: 'plugins=(git zsh-autosuggestions zsh-interactive-cd zsh-syntax-highlighting zsh-history-substring-search)'
backrefs: yes
loop: '{{ user_dirs }}'
- name: Change default shell to Zsh for each user excluding root
ansible.builtin.user:
name: "{{ item | regex_replace('(^/home/)', '') }}"
shell: /bin/zsh
loop: '{{ user_dirs }}'
when: "'/root' not in item"
- name: Copy .p10k.zsh to each user's home directory
ansible.builtin.copy:
src: ../static/.p10k.zsh
dest: '{{ item }}/.p10k.zsh'
owner: "{{ item | regex_replace('^/home/', '') }}"
group: "{{ item | regex_replace('^/home/', '') }}"
mode: '0644'
loop: '{{ user_dirs }}'
- name: Uncomment desired segments in .p10k.zsh for each user
ansible.builtin.replace:
path: '{{ item }}/.p10k.zsh'
regexp: '^\s*# (vpn_ip|load|disk_usage|ram|swap|cpu_arch|ip|public_ip|proxy|battery|wifi)'
replace: ' \1'
loop: '{{ user_dirs }}'
ignore_errors: yes
- name: Add custom Powerlevel10k configuration prompt to .zshrc
ansible.builtin.blockinfile:
path: '{{ item }}/.zshrc'
block: |
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
marker: '# {mark} ANSIBLE MANAGED BLOCK for p10k'
loop: '{{ user_dirs }}'
- name: Fetch the latest lsd release version
uri:
url: https://api.github.com/repos/lsd-rs/lsd/releases/latest
method: GET
return_content: yes
headers:
Accept: application/vnd.github.v3+json
register: latest_lsd_release
# Ensure the task fails gracefully if the API rate limit is exceeded or other issues occur
ignore_errors: yes
- name: Set the latest lsd version as a fact
set_fact:
lsd_version: '{{ (latest_lsd_release.content | from_json).tag_name }}'
when: latest_lsd_release is succeeded
- name: Determine architecture
set_fact:
architecture: "{{ 'x86_64' if ansible_architecture == 'x86_64' else 'aarch64' }}"
- name: Download lsd binary based on architecture and version
ansible.builtin.get_url:
url: 'https://github.com/lsd-rs/lsd/releases/download/{{ lsd_version }}/lsd-{{ lsd_version }}-{{ architecture }}-unknown-linux-gnu.tar.gz'
dest: '/tmp/lsd-{{ lsd_version }}-{{ architecture }}-unknown-linux-gnu.tar.gz'
when: lsd_version is defined
- name: Extract lsd tarball
ansible.builtin.unarchive:
src: '/tmp/lsd-{{ lsd_version }}-{{ architecture }}-unknown-linux-gnu.tar.gz'
dest: '/tmp/'
remote_src: yes
when: lsd_version is defined
- name: Move lsd binary to /usr/bin
ansible.builtin.command:
cmd: 'mv /tmp/lsd-{{ lsd_version }}-{{ architecture }}-unknown-linux-gnu/lsd /usr/bin/'
when: lsd_version is defined