Skip to content

Commit

Permalink
[Lazy] Switch to zsh / oh-my-zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed Nov 21, 2024
1 parent e721719 commit e223755
Show file tree
Hide file tree
Showing 21 changed files with 517 additions and 539 deletions.
2 changes: 1 addition & 1 deletion lazy.ansible/.manala/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sh:
else \
$(call manala_docker_command, \
$(if $(PORT),--publish $(PORT)), \
) bash --login ; \
) zsh --login ; \
fi
.PHONY: sh

Expand Down
33 changes: 15 additions & 18 deletions lazy.ansible/.manala/docker/Dockerfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ARG GOMPLATE_VERSION="4.1.0"
ARG DIRENV_VERSION="2.34.0"
ARG JQ_VERSION="1.7.1"
ARG YQ_VERSION="4.44.3"
ARG FZF_VERSION="0.55.0"

# The 'container' environment variable tells systemd that it's running inside a
# Docker container environment.
Expand All @@ -29,7 +30,6 @@ RUN \
apt-get --quiet update \
&& apt-get --quiet --yes --purge --autoremove upgrade \
&& apt-get --quiet --yes --no-install-recommends --verbose-versions install \
bash-completion \
bzip2 \
ca-certificates \
curl \
Expand All @@ -43,9 +43,10 @@ RUN \
socat \
sudo \
vim \
zsh \
# User
&& addgroup --gid ${MANALA_GROUP_ID} lazy \
&& adduser --home /home/lazy --shell /bin/bash --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \
&& adduser --home /home/lazy --shell /bin/zsh --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \
&& install --verbose --mode 0755 --group lazy --owner lazy --directory /run/user/${MANALA_USER_ID} \
&& echo "lazy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/lazy \
# Gosu
Expand All @@ -68,10 +69,16 @@ RUN \
&& curl -sSLf "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}" \
--output /usr/local/bin/yq \
&& chmod +x /usr/local/bin/yq \
# Bash completion
&& install --verbose --mode 0755 --directory /etc/bash_completion.d \
# Oh My Bash
&& git clone https://github.com/ohmybash/oh-my-bash.git /usr/local/share/oh-my-bash \
# Oh My Zsh
&& git clone https://github.com/ohmyzsh/ohmyzsh.git /usr/local/share/oh-my-zsh \
# See: https://github.com/ohmyzsh/ohmyzsh/issues/11995
&& git clone https://github.com/zsh-users/zsh-autosuggestions.git /usr/local/share/oh-my-zsh/custom/plugins/zsh-autosuggestions \
&& git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /usr/local/share/oh-my-zsh/custom/plugins/zsh-syntax-highlighting \
&& echo "ZDOTDIR=/etc/zsh" > /etc/zsh/zshenv \
# Fzf
&& curl -sSLf "https://github.com/junegunn/fzf/releases/download/v${FZF_VERSION}/fzf-${FZF_VERSION}-linux_{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}.tar.gz" \
| bsdtar -xvf - -C /usr/local/bin \
&& chmod +x /usr/local/bin/fzf \
# Clean
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -90,16 +97,13 @@ RUN \
openssh-client \
pipx \
python3 \
python3-argcomplete \
shellcheck \
sshpass \
{{- range $package := $apt.packages }}
{{ $package }} \
{{- end }}
# Sudo
&& echo "Defaults env_keep += \"PIPX_*\"" > /etc/sudoers.d/pipx \
# Bash completion
&& activate-global-python-argcomplete --dest /etc/bash_completion.d \
# Clean
&& rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -177,7 +181,6 @@ RUN \
RUN \
pipx install --pip-args="--no-cache-dir" \
molecule=={{ $molecule.version }} \
&& _MOLECULE_COMPLETE=bash_source molecule > /etc/bash_completion.d/molecule \
{{- if $molecule.dependencies }}
&& pipx inject --pip-args="--no-cache-dir" molecule \
{{- range $i, $dependency := $molecule.dependencies }}
Expand All @@ -194,17 +197,11 @@ RUN \
RUN \
curl -sSLf "https://releases.hashicorp.com/terraform/{{ $terraform.version }}/terraform_{{ $terraform.version }}_linux_{{ include "arch_map" (dict "amd64" "amd64" "arm64" "arm64") }}.zip" \
| bsdtar -xvf - -C /usr/local/bin \
&& chmod +x /usr/local/bin/terraform \
# Bash completion
&& echo "complete -C /usr/local/bin/terraform terraform" > /etc/bash_completion.d/terraform \
# Bash aliases
&& printf "alias tf='terraform'\n\
complete -C /usr/local/bin/terraform tf\n\
" > /etc/profile.d/terraform.sh
&& chmod +x /usr/local/bin/terraform

{{ end -}}

# Run
COPY docker/entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
CMD ["zsh"]
148 changes: 0 additions & 148 deletions lazy.ansible/.manala/etc/profile.d/oh-my-bash.sh.tmpl

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
eval "$(direnv hook bash)"
##########
# Direnv #
##########

# Config directory
export DIRENV_CONFIG=/etc/direnv
Expand Down
121 changes: 121 additions & 0 deletions lazy.ansible/.manala/etc/zsh/.zshrc.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Path to your Oh My Zsh installation.
export ZSH=/usr/local/share/oh-my-zsh

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="strug"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
direnv
zsh-autosuggestions
zsh-syntax-highlighting
fzf
ansible
{{- if .Vars.system.docker }}
docker
{{- end }}
{{- if .Vars.system.terraform }}
terraform
{{- end }}
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='nvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch $(uname -m)"

# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# Theme customization
PROMPT="%{$fg[green]%}╭─%n@%m %{$reset_color%}%{$fg[yellow]%}in %1~ %{$reset_color%}${git_branch}
%{$fg[green]%}╰\$ %{$reset_color%}"
2 changes: 1 addition & 1 deletion lazy.ansible/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ user:
exists: true
groups:
- lazy
shell: /bin/bash
shell: /bin/zsh

file:
# Base
Expand Down
2 changes: 1 addition & 1 deletion lazy.kubernetes/.manala/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sh:
else \
$(call manala_docker_command, \
$(if $(PORT),--publish $(PORT)), \
) bash --login ; \
) zsh --login ; \
fi
.PHONY: sh

Expand Down
Loading

0 comments on commit e223755

Please sign in to comment.