generalize zsh role to support darwin
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
---
|
||||
zsh_home: "{{ '/root' if zsh_user == 'root' else '/home/' + zsh_user }}"
|
||||
zsh_os_darwin: "{{ ansible_facts['os_family'] == 'Darwin' }}"
|
||||
zsh_home: >-
|
||||
{{ (zsh_os_darwin | bool)
|
||||
| ternary(ansible_env.HOME,
|
||||
('/root' if zsh_user == 'root' else '/home/' + zsh_user)) }}
|
||||
# Primary group of the managed files. macOS has no per-user group (it's `staff`).
|
||||
zsh_group: >-
|
||||
{{ (zsh_os_darwin | bool) | ternary('staff', zsh_user) }}
|
||||
zsh_base_config: "{{ zsh_home }}/.zshrc"
|
||||
zsh_config_path: "{{ zsh_home }}/.config/zsh"
|
||||
zsh_config_file: "{{ zsh_config_path }}/.zshrc"
|
||||
@@ -7,4 +14,13 @@ zsh_p10k_theme_config: "{{ zsh_config_path }}/p10k.zsh"
|
||||
zsh_users:
|
||||
- jokester
|
||||
- root
|
||||
zsh_plugins_path: "/opt/zsh/plugins"
|
||||
# System-wide on Linux (root:users); per-user on macOS (user:staff).
|
||||
zsh_plugins_path: >-
|
||||
{{ (zsh_os_darwin | bool) | ternary(zsh_config_path + '/plugins', '/opt/zsh/plugins') }}
|
||||
zsh_plugins_owner: >-
|
||||
{{ (zsh_os_darwin | bool) | ternary(ansible_user, 'root') }}
|
||||
zsh_plugins_group: >-
|
||||
{{ (zsh_os_darwin | bool) | ternary('staff', 'users') }}
|
||||
# fzf shell integrations (key-bindings.zsh / completion.zsh).
|
||||
zsh_fzf_shell_path: >-
|
||||
{{ (zsh_os_darwin | bool) | ternary('$(brew --prefix)/opt/fzf/shell', '/usr/share/fzf') }}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
---
|
||||
- name: Install zsh
|
||||
- name: Install zsh (Linux)
|
||||
ansible.builtin.package:
|
||||
name: zsh
|
||||
state: present
|
||||
when: not (zsh_os_darwin | bool)
|
||||
|
||||
- name: Install eza (better ls)
|
||||
- name: Install eza (Linux)
|
||||
ansible.builtin.package:
|
||||
name: eza
|
||||
state: present
|
||||
when: not (zsh_os_darwin | bool)
|
||||
|
||||
- name: Install eza (macOS)
|
||||
community.general.homebrew:
|
||||
name: eza
|
||||
state: present
|
||||
become: false
|
||||
when: zsh_os_darwin | bool
|
||||
|
||||
- name: Install alacritty terminfo
|
||||
ansible.builtin.include_tasks: alacritty-terminfo.yml
|
||||
when: not (zsh_os_darwin | bool)
|
||||
|
||||
- name: Install zsh plugins
|
||||
ansible.builtin.include_tasks: plugins.yml
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
ansible.builtin.file:
|
||||
path: "{{ zsh_plugins_path }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: users
|
||||
owner: "{{ zsh_plugins_owner }}"
|
||||
group: "{{ zsh_plugins_group }}"
|
||||
mode: "0755"
|
||||
|
||||
- name: Add a readme file to advice from where this comes
|
||||
@@ -14,8 +14,8 @@
|
||||
# zsh plugins
|
||||
Managed by Ansible
|
||||
mode: "0644"
|
||||
group: users
|
||||
owner: root
|
||||
group: "{{ zsh_plugins_group }}"
|
||||
owner: "{{ zsh_plugins_owner }}"
|
||||
|
||||
- name: "Git clone plugins"
|
||||
ansible.builtin.git:
|
||||
@@ -36,16 +36,24 @@
|
||||
dest: "{{ zsh_plugins_path }}/fzf-tab"
|
||||
version: master
|
||||
|
||||
- name: Install fzf package
|
||||
- name: Install fzf package (Linux)
|
||||
ansible.builtin.package:
|
||||
name: fzf
|
||||
state: present
|
||||
when: not (zsh_os_darwin | bool)
|
||||
|
||||
- name: Install fzf package (macOS)
|
||||
community.general.homebrew:
|
||||
name: fzf
|
||||
state: present
|
||||
become: false
|
||||
when: zsh_os_darwin | bool
|
||||
|
||||
- name: Assert plugins are available for any user
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
owner: root
|
||||
group: users
|
||||
owner: "{{ zsh_plugins_owner }}"
|
||||
group: "{{ zsh_plugins_group }}"
|
||||
mode: "0755"
|
||||
state: directory
|
||||
loop:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
src: zshenv.j2
|
||||
dest: "{{ zsh_home }}/.zshenv"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Setup .zprofile (login banner)
|
||||
@@ -12,7 +12,7 @@
|
||||
src: zprofile.j2
|
||||
dest: "{{ zsh_home }}/.zprofile"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Setup zsh base config
|
||||
@@ -20,7 +20,7 @@
|
||||
src: main.zshrc.j2
|
||||
dest: "{{ zsh_base_config }}"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Setup .config/zsh directory
|
||||
@@ -28,7 +28,7 @@
|
||||
path: "{{ zsh_config_path }}"
|
||||
state: directory
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0700"
|
||||
|
||||
- name: Configure zsh config
|
||||
@@ -36,15 +36,15 @@
|
||||
src: zshrc.j2
|
||||
dest: "{{ zsh_config_file }}"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Copy aliases
|
||||
ansible.builtin.copy:
|
||||
src: ./templates/aliases
|
||||
ansible.builtin.template:
|
||||
src: aliases.j2
|
||||
dest: "{{ zsh_config_path }}/aliases"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Configure fzf-tab plugin
|
||||
@@ -56,18 +56,19 @@
|
||||
zstyle ':fzf-tab:*' group-colors ''
|
||||
zstyle ':fzf-tab:*' preview-contained-categories true
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Change default shell to zsh
|
||||
ansible.builtin.user:
|
||||
name: "{{ zsh_user }}"
|
||||
shell: /bin/zsh
|
||||
when: not (zsh_os_darwin | bool)
|
||||
|
||||
- name: Configure powerlevel10k theme
|
||||
ansible.builtin.copy:
|
||||
src: "./templates/{{ 'root.p10k.zsh' if zsh_user == 'root' else 'user.p10k.zsh' }}"
|
||||
dest: "{{ zsh_p10k_theme_config }}"
|
||||
owner: "{{ zsh_user }}"
|
||||
group: "{{ zsh_user }}"
|
||||
group: "{{ zsh_group }}"
|
||||
mode: "0600"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# {{ ansible_managed }}
|
||||
alias ls="eza --icons --group-directories-first"
|
||||
alias ll="eza --icons --group-directories-first -l"
|
||||
alias la="eza --icons --group-directories-first -la"
|
||||
{% if not (zsh_os_darwin | bool) %}
|
||||
alias p="podman"
|
||||
alias pp="podman play"
|
||||
alias pl="podman logs -f"
|
||||
@@ -10,4 +12,5 @@ alias jd="journalctl -xe"
|
||||
alias docker="echo 'use podman instead'"
|
||||
alias docker-compose="echo 'use podman-compose instead'"
|
||||
alias dc="echo 'use podman-compose instead'"
|
||||
{% endif %}
|
||||
alias w='cd $HOME/workspace'
|
||||
@@ -61,8 +61,8 @@ source $ZSH_PLUGINS/zsh-history-substring-search/zsh-history-substring-search.zs
|
||||
source $ZSH_PLUGINS/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||
|
||||
# Enable fzf integration (Ctrl+R, Ctrl+T, Alt+C)
|
||||
source /usr/share/fzf/key-bindings.zsh
|
||||
source /usr/share/fzf/completion.zsh
|
||||
source {{ zsh_fzf_shell_path }}/key-bindings.zsh
|
||||
source {{ zsh_fzf_shell_path }}/completion.zsh
|
||||
|
||||
# Enable fzf-tab for completions (after compinit)
|
||||
source $ZSH_PLUGINS/fzf-tab/fzf-tab.zsh
|
||||
|
||||
Reference in New Issue
Block a user