Added `powermeli.zsh-theme`, removed Agnoster theme and git plugin along with their autodownload functionality from `.zshrc`

master
Meliurwen 3 years ago
parent 8737d60d84
commit af75d08865
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 118
      zsh/.config/zsh/plugins/powermeli.zsh-theme
  2. 51
      zsh/.zshrc

@ -0,0 +1,118 @@
#!/bin/zsh
# Theme: powermeli
# Description: Complete rewrite of omz's Agnoster theme with no bloat
# Original:
# - https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/agnoster.zsh-theme
# Dependencies:
# - https://github.com/Lokaltog/powerline-fonts
# - git
# See:
# - https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
# - https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#vcs_005finfo-Configuration
# - https://wiki.archlinux.org/title/zsh#Prompts
SEGMENT_SEPARATOR= # $'\ue0b0'
PROMPT_LINE=""
prompt_segment() {
separator=""
if [ -n "$OLD_SEP" ]; then
separator="%F{$OLD_BG}$OLD_SEP"
fi
OLD_SEP=$1
OLD_BG=$2
PROMPT_LINE="$PROMPT_LINE%{%K{$2}$separator%}%{%F{$3}%}$4"
unset separator
}
prompt_context() {
if [ $(id -u) -eq 0 ]; then
prompt_segment "$SEGMENT_SEPARATOR" black yellow
else
prompt_segment "$SEGMENT_SEPARATOR" black default
fi
if [ -z ${SSH_CLIENT+x} ]; then
PROMPT_LINE="$PROMPT_LINE %n "
else
PROMPT_LINE="$PROMPT_LINE %n@%m "
fi
}
prompt_git() {
if [ "$ZSH_THEME_GIT_MODE" = "disabled" ]; then
return
fi
if ! type git > /dev/null 2>&1; then
return
fi
PL_BRANCH_CHAR="" # $'\ue0a0'
if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" = "true" ]; then
repo_path=$(git rev-parse --git-dir 2> /dev/null)
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
if [ -n "$(git status --porcelain --ignore-submodules=dirty 2> /dev/null | tail -n 1)" ]; then
prompt_segment "$SEGMENT_SEPARATOR" yellow black
else
prompt_segment "$SEGMENT_SEPARATOR" green black
fi
if [ -e "${repo_path}/BISECT_LOG" ]; then
mode=" <B>"
elif [ -e "${repo_path}/MERGE_HEAD" ]; then
mode=" >M<"
elif [ -e "${repo_path}/rebase" ] || [ -e "${repo_path}/rebase-apply" ] || [ -e "${repo_path}/rebase-merge" ] || [ -e "${repo_path}/../.dotest" ]; then
mode=" >R>"
fi
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:*' unstagedstr '±'
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info
PROMPT_LINE="$PROMPT_LINE${${ref:gs/%/%%}/refs\/heads\// $PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode} "
unset repo_path ref mode
fi
unset PL_BRANCH_CHAR
}
prompt_virtualenv() {
if [ -n "$VIRTUAL_ENV" ] && [ -n "$VIRTUAL_ENV_DISABLE_PROMPT" ]; then
prompt_segment "$SEGMENT_SEPARATOR" blue black "(${VIRTUAL_ENV:t:gs/%/%%})"
fi
}
prompt_status() {
symbols=""
[ $RETVAL -ne 0 ] && symbols="$symbols%{%F{red}%}✘" # last command exit code
[ $(jobs -l | wc -l) -gt 0 ] && symbols="$symbols%{%F{cyan}%}⚙" # background jobs
[ $(id -u) -eq 0 ] && symbols="$symbols%{%F{yellow}%}⚡" # root or not
[ -n "$symbols" ] && prompt_segment "" black default " $symbols"
unset symbols
}
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
prompt_context
prompt_segment "$SEGMENT_SEPARATOR" blue black " %~ "
prompt_git
PROMPT_LINE="$PROMPT_LINE%{%k%F{${OLD_BG:-blue}}%}$SEGMENT_SEPARATOR%{%f%}"
unset OLD_BG OLD_SEP
printf "%s%s " "%{%f%b%k%}" "$PROMPT_LINE"
unset PROMPT_LINE
unset -f prompt_segment prompt_status prompt_virtualenv prompt_context prompt_git
}
setopt prompt_subst
PROMPT='$(build_prompt)'

@ -1,5 +1,8 @@
#!/bin/zsh #!/bin/zsh
# ~/.zshrc # ~/.zshrc
# See:
# - https://zsh.sourceforge.io/Doc/Release/
# - https://stevenvanbael.com/profiling-zsh-startup
### History ### History
HISTFILE="$HOME/.zsh_history" HISTFILE="$HOME/.zsh_history"
@ -188,32 +191,6 @@ function zsh_stats() {
# This is ugly as hell, but is efficient and reliable # This is ugly as hell, but is efficient and reliable
# TODO: find a clean, reliable and efficient solution to this mess # TODO: find a clean, reliable and efficient solution to this mess
zsh_base_dir="$HOME/.config/zsh" zsh_base_dir="$HOME/.config/zsh"
# Git
# git theming default: Variables for theming the git info prompt
function zsh_git_theme() {
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # At the very beginning of the prompt
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
ZSH_THEME_RUBY_PROMPT_PREFIX="("
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
}
# Source: https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/git.zsh
zsh_tmp_path="$zsh_base_dir/plugins/git.zsh"
if [ -f "$zsh_tmp_path" ]; then
zsh_git_theme
else
mkdir -p "$zsh_base_dir/plugins"
src_url='https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/lib/git.zsh'
echo "Downloading $src_url ..."
eval "curl -s --max-time 5 -o \""$zsh_tmp_path"\" \"$src_url\"" && \
unset src_url && \
chmod +x "$zsh_tmp_path" && \
zsh_git_theme || \
echo "[Warning] Failed to create the file or unrecheable URL: $src_url"
fi
unfunction zsh_git_theme
# Rudimentary plugin loader # Rudimentary plugin loader
# Note: the files are loaded in alphabetical order # Note: the files are loaded in alphabetical order
@ -227,24 +204,6 @@ for plugin_f in "$zsh_base_dir/plugins/"*(.zsh|.zsh-theme)(xEXN); do
source $plugin_f || printf "An error has occurred sourcing: %s\n" "$plugin_f" source $plugin_f || printf "An error has occurred sourcing: %s\n" "$plugin_f"
done done
# For `prompt_subst` see: #PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
# https://github.com/agnoster/agnoster-zsh-theme/pull/12
# Fork used:
# https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/agnoster.zsh-theme
zsh_tmp_path="$zsh_base_dir/agnoster.zsh-theme"
if [ -f "$zsh_tmp_path" ]; then
setopt prompt_subst
source "$zsh_tmp_path"
else
mkdir -p "$zsh_base_dir"
src_url='https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/themes/agnoster.zsh-theme'
echo "Downloading $src_url ..."
eval "curl -s --max-time 5 -o \""$zsh_tmp_path"\" \"$src_url\"" && \
unset src_url && \
setopt prompt_subst && \
source "$zsh_tmp_path" || \
echo "[Warning] Failed to create the file or unrecheable URL: $src_url" && \
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
fi
unset zsh_tmp_path
unset zsh_base_dir unset zsh_base_dir

Loading…
Cancel
Save