Skip to content

Instantly share code, notes, and snippets.

@akkerman
Last active October 29, 2021 04:56
Show Gist options
  • Save akkerman/461741678d4f5328c339bc8efed36310 to your computer and use it in GitHub Desktop.
Save akkerman/461741678d4f5328c339bc8efed36310 to your computer and use it in GitHub Desktop.
# AKKERMAN ZSH Theme - initially based on AVIT
# vi: set ft=sh:
# settings
typeset +H _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
typeset +H _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
typeset +H _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
PROMPT='
$(_user_host)${_current_dir} $(node_version) $(node_package) $(docker_context) $(git_prompt_info)
%{%(!.${fg[red]}.${fg[white]})%}▶%{$reset_color%} '
PROMPT2='%{%(!.${fg[red]}.${fg[white]})%}◀%{$reset_color%} '
RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}${_return_status}%{$(echotc DO 1)%}'
function node_version() {
version=$(node --version | sed 's/v//g')
echo "%{$fg[green]%}⬢ $version%{$reset_color%}"
}
function docker_context() {
if [[ -n $DOCKER_HOST ]]; then
ctx=$(basename $DOCKER_HOST | sed 's/:.\+//g')
else
ctx=$(docker context ls --format '{{if .Current}}{{.Name}}{{end}}' 2>/dev/null | sed '/^$/d')
fi
version=$(docker version --format "{{.Server.Version}}")
echo "%{$fg[blue]%}🐳$version (${ctx})%{$reset_color%}"
}
function _user_host() {
local me
if [[ -n $SSH_CONNECTION ]]; then
me="%n@%m"
elif [[ $LOGNAME != $USER ]]; then
me="%n"
fi
if [[ -n $me ]]; then
echo "%{$fg[cyan]%}$me%{$reset_color%}:"
fi
}
function node_package() {
if [[ -f package.json ]]; then
local version=$(gawk 'match($0, /version.+"([^"]+)",/, a) {print a[1]}' package.json)
if [[ -n $version ]]; then
echo "%{$fg[yellow]%}v$version%{$reset_color%}"
fi
fi
}
MODE_INDICATOR="%{$fg[yellow]%}❮❮❮%{$reset_color%}"
# Git prompt settings
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}❌%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔ %{$reset_color%}"
@akkerman
Copy link
Author

I saw someone, running the spaceship theme, with the version from package.json in the prompt.
Liked it, added it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment