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_base_config: "{{ zsh_home }}/.zshrc"
|
||||||
zsh_config_path: "{{ zsh_home }}/.config/zsh"
|
zsh_config_path: "{{ zsh_home }}/.config/zsh"
|
||||||
zsh_config_file: "{{ zsh_config_path }}/.zshrc"
|
zsh_config_file: "{{ zsh_config_path }}/.zshrc"
|
||||||
@@ -7,4 +14,13 @@ zsh_p10k_theme_config: "{{ zsh_config_path }}/p10k.zsh"
|
|||||||
zsh_users:
|
zsh_users:
|
||||||
- jokester
|
- jokester
|
||||||
- root
|
- 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:
|
ansible.builtin.package:
|
||||||
name: zsh
|
name: zsh
|
||||||
state: present
|
state: present
|
||||||
|
when: not (zsh_os_darwin | bool)
|
||||||
|
|
||||||
- name: Install eza (better ls)
|
- name: Install eza (Linux)
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name: eza
|
name: eza
|
||||||
state: present
|
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
|
- name: Install alacritty terminfo
|
||||||
ansible.builtin.include_tasks: alacritty-terminfo.yml
|
ansible.builtin.include_tasks: alacritty-terminfo.yml
|
||||||
|
when: not (zsh_os_darwin | bool)
|
||||||
|
|
||||||
- name: Install zsh plugins
|
- name: Install zsh plugins
|
||||||
ansible.builtin.include_tasks: plugins.yml
|
ansible.builtin.include_tasks: plugins.yml
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ zsh_plugins_path }}"
|
path: "{{ zsh_plugins_path }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: "{{ zsh_plugins_owner }}"
|
||||||
group: users
|
group: "{{ zsh_plugins_group }}"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Add a readme file to advice from where this comes
|
- name: Add a readme file to advice from where this comes
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
# zsh plugins
|
# zsh plugins
|
||||||
Managed by Ansible
|
Managed by Ansible
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
group: users
|
group: "{{ zsh_plugins_group }}"
|
||||||
owner: root
|
owner: "{{ zsh_plugins_owner }}"
|
||||||
|
|
||||||
- name: "Git clone plugins"
|
- name: "Git clone plugins"
|
||||||
ansible.builtin.git:
|
ansible.builtin.git:
|
||||||
@@ -36,16 +36,24 @@
|
|||||||
dest: "{{ zsh_plugins_path }}/fzf-tab"
|
dest: "{{ zsh_plugins_path }}/fzf-tab"
|
||||||
version: master
|
version: master
|
||||||
|
|
||||||
- name: Install fzf package
|
- name: Install fzf package (Linux)
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name: fzf
|
name: fzf
|
||||||
state: present
|
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
|
- name: Assert plugins are available for any user
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
owner: root
|
owner: "{{ zsh_plugins_owner }}"
|
||||||
group: users
|
group: "{{ zsh_plugins_group }}"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
state: directory
|
state: directory
|
||||||
loop:
|
loop:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
src: zshenv.j2
|
src: zshenv.j2
|
||||||
dest: "{{ zsh_home }}/.zshenv"
|
dest: "{{ zsh_home }}/.zshenv"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Setup .zprofile (login banner)
|
- name: Setup .zprofile (login banner)
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
src: zprofile.j2
|
src: zprofile.j2
|
||||||
dest: "{{ zsh_home }}/.zprofile"
|
dest: "{{ zsh_home }}/.zprofile"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Setup zsh base config
|
- name: Setup zsh base config
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
src: main.zshrc.j2
|
src: main.zshrc.j2
|
||||||
dest: "{{ zsh_base_config }}"
|
dest: "{{ zsh_base_config }}"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Setup .config/zsh directory
|
- name: Setup .config/zsh directory
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
path: "{{ zsh_config_path }}"
|
path: "{{ zsh_config_path }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0700"
|
mode: "0700"
|
||||||
|
|
||||||
- name: Configure zsh config
|
- name: Configure zsh config
|
||||||
@@ -36,15 +36,15 @@
|
|||||||
src: zshrc.j2
|
src: zshrc.j2
|
||||||
dest: "{{ zsh_config_file }}"
|
dest: "{{ zsh_config_file }}"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Copy aliases
|
- name: Copy aliases
|
||||||
ansible.builtin.copy:
|
ansible.builtin.template:
|
||||||
src: ./templates/aliases
|
src: aliases.j2
|
||||||
dest: "{{ zsh_config_path }}/aliases"
|
dest: "{{ zsh_config_path }}/aliases"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Configure fzf-tab plugin
|
- name: Configure fzf-tab plugin
|
||||||
@@ -56,18 +56,19 @@
|
|||||||
zstyle ':fzf-tab:*' group-colors ''
|
zstyle ':fzf-tab:*' group-colors ''
|
||||||
zstyle ':fzf-tab:*' preview-contained-categories true
|
zstyle ':fzf-tab:*' preview-contained-categories true
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
- name: Change default shell to zsh
|
- name: Change default shell to zsh
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ zsh_user }}"
|
name: "{{ zsh_user }}"
|
||||||
shell: /bin/zsh
|
shell: /bin/zsh
|
||||||
|
when: not (zsh_os_darwin | bool)
|
||||||
|
|
||||||
- name: Configure powerlevel10k theme
|
- name: Configure powerlevel10k theme
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "./templates/{{ 'root.p10k.zsh' if zsh_user == 'root' else 'user.p10k.zsh' }}"
|
src: "./templates/{{ 'root.p10k.zsh' if zsh_user == 'root' else 'user.p10k.zsh' }}"
|
||||||
dest: "{{ zsh_p10k_theme_config }}"
|
dest: "{{ zsh_p10k_theme_config }}"
|
||||||
owner: "{{ zsh_user }}"
|
owner: "{{ zsh_user }}"
|
||||||
group: "{{ zsh_user }}"
|
group: "{{ zsh_group }}"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
alias ls="eza --icons --group-directories-first"
|
alias ls="eza --icons --group-directories-first"
|
||||||
alias ll="eza --icons --group-directories-first -l"
|
alias ll="eza --icons --group-directories-first -l"
|
||||||
alias la="eza --icons --group-directories-first -la"
|
alias la="eza --icons --group-directories-first -la"
|
||||||
|
{% if not (zsh_os_darwin | bool) %}
|
||||||
alias p="podman"
|
alias p="podman"
|
||||||
alias pp="podman play"
|
alias pp="podman play"
|
||||||
alias pl="podman logs -f"
|
alias pl="podman logs -f"
|
||||||
@@ -10,4 +12,5 @@ alias jd="journalctl -xe"
|
|||||||
alias docker="echo 'use podman instead'"
|
alias docker="echo 'use podman instead'"
|
||||||
alias docker-compose="echo 'use podman-compose instead'"
|
alias docker-compose="echo 'use podman-compose instead'"
|
||||||
alias dc="echo 'use podman-compose instead'"
|
alias dc="echo 'use podman-compose instead'"
|
||||||
|
{% endif %}
|
||||||
alias w='cd $HOME/workspace'
|
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
|
source $ZSH_PLUGINS/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||||
|
|
||||||
# Enable fzf integration (Ctrl+R, Ctrl+T, Alt+C)
|
# Enable fzf integration (Ctrl+R, Ctrl+T, Alt+C)
|
||||||
source /usr/share/fzf/key-bindings.zsh
|
source {{ zsh_fzf_shell_path }}/key-bindings.zsh
|
||||||
source /usr/share/fzf/completion.zsh
|
source {{ zsh_fzf_shell_path }}/completion.zsh
|
||||||
|
|
||||||
# Enable fzf-tab for completions (after compinit)
|
# Enable fzf-tab for completions (after compinit)
|
||||||
source $ZSH_PLUGINS/fzf-tab/fzf-tab.zsh
|
source $ZSH_PLUGINS/fzf-tab/fzf-tab.zsh
|
||||||
|
|||||||
Reference in New Issue
Block a user