Skip to content

Complete

Patrick edited this page Mar 28, 2026 · 4 revisions

Full example of a zsh shell.

  • Install the zsh package.
  • Set zsh as default shell for the specified users.
  • Distribute a custom .zshrc for each user.
  • Install autosuggestions, syntax-highlighting and eza.
  • Set history, color and cd settings.

main.yml file in your project folder:

- name: zsh
  hosts: all
  vars:
    zsh_config_backup: false
    zsh_config_overwrite: true

    zsh_users:
      - lorem
      - ipsum

    zsh_users_config:
      - template: "zshrc.j2"
        filename: ".zshrc"

    zsh_dependencies:
      - eza
      - zsh-autosuggestions
      - zsh-syntax-highlighting

    zsh_additional_lines: ""
  roles:
    - bec.shell.zsh
  tasks:
    - ansible.builtin.debug:
        msg: "ZSH was installed."

zshrc.j2 file in your templates folder:

{% if zsh_config_overwrite is true %}
#
# {{ ansible_managed }}
#
{% endif %}

autoload colors && colors

{% raw %}
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=" %{$fg[cyan]%}%c%{$reset_color%} "
{% endraw %}

source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

alias ls='eza --group-directories-first'
alias ll='eza --group-directories-first -a -l -b -g -F -G'
alias lx='eza --group-directories-first -a -l -b -g -h -H -i -m -S --time-style=long-iso'

HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=50000

setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_REDUCE_BLANKS
setopt AUTOCD

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

{% if zsh_additional_lines is defined and zsh_additional_lines | length %}
#
# Host specific additions
#
{{ zsh_additional_lines }}
{% endif %}

Clone this wiki locally