Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lazy] Switch to zsh / oh-my-zsh / starship #456

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lazy.ansible/.manala.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ system:
env_file: []
# @schema {"items": {"type": "string"}}
mount: []
starship:
# @schema {"type": ["null", "string"]}
config: ~
docker: false
goss:
# @schema {"enum": [null, "0.4.8", "0.3.23"]}
Expand Down
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
41 changes: 23 additions & 18 deletions lazy.ansible/.manala/docker/Dockerfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ARG GOMPLATE_VERSION="4.2.0"
ARG DIRENV_VERSION="2.35.0"
ARG JQ_VERSION="1.7.1"
ARG YQ_VERSION="4.44.5"
ARG STARSHIP_VERSION="1.21.1"
ARG FZF_VERSION="0.56.3"

# The 'container' environment variable tells systemd that it's running inside a
# Docker container environment.
Expand All @@ -23,13 +25,15 @@ ENV container="docker"
# Default locale
ENV LANG="C.UTF-8"

# Starship
ENV STARSHIP_CONFIG=/etc/starship/starship.toml

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

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 +47,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 +73,20 @@ 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 \
# Starship
&& curl -sSLf "https://github.com/starship/starship/releases/download/v${STARSHIP_VERSION}/starship-{{ include "arch_map" (dict "amd64" "x86_64" "arm64" "aarch64") }}-unknown-linux-musl.tar.gz" \
| bsdtar -xvf - -C /usr/local/bin \
&& echo "Defaults env_keep += STARSHIP_CONFIG" > /etc/sudoers.d/starship \
# 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 +105,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 +189,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 +205,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.

29 changes: 29 additions & 0 deletions lazy.ansible/.manala/etc/starship/starship.toml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Starship config template
# Don't edit this file directly. Instead, set config in project .manala.yaml, and run `manala up`.

format = """
[╭─](cyan)$username$hostname$directory$direnv$env_var$custom
[╰](cyan) $cmd_duration$character"""

[username]
show_always = true
format = '[$user]($style)@'
style_user = 'yellow'

[hostname]
ssh_only = false
style = 'yellow'

[directory]
truncation_length = 1
truncation_symbol = '…/'
read_only = ''
style = 'cyan'

[direnv]
disabled = false

{{- if .Vars.system.starship.config }}

{{ .Vars.system.starship.config | trim }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ printf " \033[36m· {{ $dependency }}\033[0m\n"
{{- if $terraform.version }}
printf " \033[36m‣ terraform \033[35m{{ $terraform.version }}\033[0m\n"
{{- end }}
printf "\n"

{{- $help := .Vars.project.help }}
{{- if $help }}
printf "\n"
cat << EOF
{{ $help }}
{{ $help | trim }}
EOF
{{- end }}
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
Loading