From 83724129dc0819212c8f442274b205d263cbcafc Mon Sep 17 00:00:00 2001 From: Zakhary Kaplan Date: Sun, 11 Feb 2024 00:00:00 -0500 Subject: [PATCH] feat(zsh): change prompt {playtime => century} --- apps/zsh/after/highlight.zsh | 72 ++++++------ apps/zsh/after/utils/fzf.zsh | 4 +- apps/zsh/plugin/vi-mode.zsh | 2 - apps/zsh/themes/prompt_century_setup | 163 ++++++++++++++++++++++++++ apps/zsh/themes/prompt_playtime_setup | 158 ------------------------- apps/zsh/zshrc | 2 +- 6 files changed, 199 insertions(+), 202 deletions(-) create mode 100644 apps/zsh/themes/prompt_century_setup delete mode 100644 apps/zsh/themes/prompt_playtime_setup diff --git a/apps/zsh/after/highlight.zsh b/apps/zsh/after/highlight.zsh index 4cc32b55..dfe60685 100644 --- a/apps/zsh/after/highlight.zsh +++ b/apps/zsh/after/highlight.zsh @@ -3,54 +3,48 @@ # Created: 19 May 2021 # SPDX-License-Identifier: MIT -# Define syntax highlighting colurs. -red="$ZSH_PROMPT_COLOUR_RED" -green="$ZSH_PROMPT_COLOUR_GREEN" -yellow="$ZSH_PROMPT_COLOUR_YELLOW" -blue="$ZSH_PROMPT_COLOUR_BLUE" -magenta="$ZSH_PROMPT_COLOUR_MAGENTA" -cyan="$ZSH_PROMPT_COLOUR_CYAN" +# Create a hash table for globally stashing variables without polluting main +# scope with a bunch of identifiers. +typeset -gA HIGHLIGHT +HIGHLIGHT[RED]=167 +HIGHLIGHT[GRN]=107 +HIGHLIGHT[BLU]=025 +HIGHLIGHT[CYN]=110 +HIGHLIGHT[MGA]=183 +HIGHLIGHT[YLW]=222 +HIGHLIGHT[GRY]=246 -# Define syntax highlighting styles. ZSH_HIGHLIGHT_STYLES[default]="none" -ZSH_HIGHLIGHT_STYLES[unknown-token]="fg=$red,bold" -ZSH_HIGHLIGHT_STYLES[reserved-word]="fg=$yellow" -ZSH_HIGHLIGHT_STYLES[suffix-alias]="fg=$green,underline" -ZSH_HIGHLIGHT_STYLES[global-alias]="fg=$cyan" -ZSH_HIGHLIGHT_STYLES[precommand]="fg=$green,underline" +ZSH_HIGHLIGHT_STYLES[unknown-token]="fg=$HIGHLIGHT[RED],bold" +ZSH_HIGHLIGHT_STYLES[reserved-word]="fg=$HIGHLIGHT[YLW]" +ZSH_HIGHLIGHT_STYLES[suffix-alias]="fg=$HIGHLIGHT[GRN],underline" +ZSH_HIGHLIGHT_STYLES[global-alias]="fg=$HIGHLIGHT[CYN]" +ZSH_HIGHLIGHT_STYLES[precommand]="fg=$HIGHLIGHT[GRN],underline" ZSH_HIGHLIGHT_STYLES[commandseparator]="none" -ZSH_HIGHLIGHT_STYLES[autodirectory]="fg=$green,underline" +ZSH_HIGHLIGHT_STYLES[autodirectory]="fg=$HIGHLIGHT[GRN],underline" ZSH_HIGHLIGHT_STYLES[path]=underline ZSH_HIGHLIGHT_STYLES[path_pathseparator]= ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]= -ZSH_HIGHLIGHT_STYLES[globbing]="fg=$blue" -ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=$blue" +ZSH_HIGHLIGHT_STYLES[globbing]="fg=$HIGHLIGHT[BLU]" +ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=$HIGHLIGHT[BLU]" ZSH_HIGHLIGHT_STYLES[command-substitution]="none" -ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]="fg=$magenta" +ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]="fg=$HIGHLIGHT[MGA]" ZSH_HIGHLIGHT_STYLES[process-substitution]="none" -ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]="fg=$magenta" -ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="none" -ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="none" +ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]="fg=$HIGHLIGHT[MGA]" +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fd=$HIGHLIGHT[GRY]" +ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fd=$HIGHLIGHT[GRY]" ZSH_HIGHLIGHT_STYLES[back-quoted-argument]="none" -ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]="fg=$magenta" -ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=$yellow" -ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=$yellow" -ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]="fg=$yellow" -ZSH_HIGHLIGHT_STYLES[rc-quote]="fg=$cyan" -ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=$cyan" -ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=$cyan" -ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]="fg=$cyan" +ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]="fg=$HIGHLIGHT[MGA]" +ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=$HIGHLIGHT[GRY]" +ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=$HIGHLIGHT[GRY]" +ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]="fg=$HIGHLIGHT[YLW]" +ZSH_HIGHLIGHT_STYLES[rc-quote]="fg=$HIGHLIGHT[CYN]" +ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=$HIGHLIGHT[CYN]" +ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=$HIGHLIGHT[CYN]" +ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]="fg=$HIGHLIGHT[CYN]" ZSH_HIGHLIGHT_STYLES[assign]="none" -ZSH_HIGHLIGHT_STYLES[redirection]="fg=$yellow" -ZSH_HIGHLIGHT_STYLES[comment]="fg=black,bold" +ZSH_HIGHLIGHT_STYLES[redirection]="fg=$HIGHLIGHT[YLW]" +ZSH_HIGHLIGHT_STYLES[comment]="fg=$HIGHLIGHT[GRY],bold" ZSH_HIGHLIGHT_STYLES[named-fd]="none" ZSH_HIGHLIGHT_STYLES[numeric-fd]="none" -ZSH_HIGHLIGHT_STYLES[arg0]="fg=$green" - -# Unset syntax highlighting colurs. -unset red -unset green -unset yellow -unset blue -unset magenta -unset cyan +ZSH_HIGHLIGHT_STYLES[arg0]="fg=$HIGHLIGHT[GRN]" diff --git a/apps/zsh/after/utils/fzf.zsh b/apps/zsh/after/utils/fzf.zsh index 69bd26ee..143de68d 100644 --- a/apps/zsh/after/utils/fzf.zsh +++ b/apps/zsh/after/utils/fzf.zsh @@ -17,11 +17,11 @@ export FZF_DEFAULT_OPTS=" --bind 'ctrl-a:toggle-all' --bind 'ctrl-v:execute(echo {+} | xargs -o "$EDITOR")' --bind 'ctrl-y:execute-silent(echo {+} | pbcopy)' - --color='prompt:25,pointer:110,marker:222' + --color='prompt:183,pointer:110,marker:222' --exit-0 --info=inline --multi - --prompt='~ ' + --prompt='❯ ' --select-1 " export FZF_CTRL_T_COMMAND='$FZF_DEFAULT_COMMAND --strip-cwd-prefix' diff --git a/apps/zsh/plugin/vi-mode.zsh b/apps/zsh/plugin/vi-mode.zsh index e03a3409..bcd4eabe 100644 --- a/apps/zsh/plugin/vi-mode.zsh +++ b/apps/zsh/plugin/vi-mode.zsh @@ -69,8 +69,6 @@ function _zsh_set_cursor_shape_for_keymap() { # -- Widgets -- {{{ # Updates editor information when the keymap changes. function zle-keymap-select() { - # Set the prompt variable - ZSH_PROMPT_VAR_VIMODE="$(prompt_playtime_vimode)" # Set the cursor shape for the keymap _zsh_set_cursor_shape_for_keymap "${KEYMAP}" # Reset the prompt on a mode change diff --git a/apps/zsh/themes/prompt_century_setup b/apps/zsh/themes/prompt_century_setup new file mode 100644 index 00000000..d2b2e0a8 --- /dev/null +++ b/apps/zsh/themes/prompt_century_setup @@ -0,0 +1,163 @@ +# File: prompt_century_setup +# Author: Zakhary Kaplan +# Created: 11 Feb 2024 +# SPDX-License-Identifier: MIT +# Vim: set ft=zsh: + +# ---------------- +# -- Modules -- +# ---------------- + +zmodload zsh/datetime + + +# ---------------- +# -- Global -- +# ---------------- + +# Create a hash table for globally stashing variables without polluting main +# scope with a bunch of identifiers. +typeset -gA CENTURY + +# Primary +CENTURY[RED]=167 +CENTURY[GRN]=107 +CENTURY[BLU]=025 +CENTURY[CYN]=110 +CENTURY[MGA]=183 +CENTURY[YLW]=222 +# Secondary +CENTURY[GR2]=071 +CENTURY[YL2]=215 +# Greys +CENTURY[BW1]=239 +CENTURY[BW2]=242 + + +# ---------------- +# -- Help -- +# ---------------- + +prompt_century_help () { + cat < 0 )) && { + tmr="$(printf '%.2fs' $timer)" + CENTURY[ERT]= + } + + CENTURY[TMR]="%b%F{$CENTURY[BW1]}${tmr}" +} +add-zsh-hook precmd hook-precmd-timer + +function hook-preexec-git() { + CENTURY[GIT]= +} +add-zsh-hook preexec hook-preexec-git + +function hook-precmd-git() { + git rev-parse --is-inside-work-tree &> /dev/null || return + + local dry="$(git status --porcelain)" + local ref="$(git symbolic-ref -q --short HEAD)" \ + || ref="$(git rev-parse --short HEAD)" \ + || return + + # Blocks + local DRY="%b%F{$CENTURY[YL2]}${dry:+*}" + local REF="%b%F{$CENTURY[GR2]}${ref}" + + # Special + local OPN="%b%F{$CENTURY[BLU]}(" + local CLS="%b%F{$CENTURY[BLU]})" + + CENTURY[GIT]="${OPN}${REF}${DRY}${CLS}" +} +add-zsh-hook precmd hook-precmd-git + + +# ---------------- +# -- Setup -- +# ---------------- + +prompt_century_setup "$@" diff --git a/apps/zsh/themes/prompt_playtime_setup b/apps/zsh/themes/prompt_playtime_setup deleted file mode 100644 index 118d9bd6..00000000 --- a/apps/zsh/themes/prompt_playtime_setup +++ /dev/null @@ -1,158 +0,0 @@ -# File: prompt_playtime_setup -# Author: Zakhary Kaplan -# Created: 13 May 2019 -# SPDX-License-Identifier: MIT -# Vim: set ft=zsh fdl=0 fdm=marker: - -# -- Modules -- {{{ -zmodload zsh/datetime -# }}} - -# -- Variables -- {{{ -# Colours -ZSH_PROMPT_COLOUR_RED='167' -ZSH_PROMPT_COLOUR_GREEN='107' -ZSH_PROMPT_COLOUR_YELLOW='222' -ZSH_PROMPT_COLOUR_BLUE='31' -ZSH_PROMPT_COLOUR_MAGENTA='183' -ZSH_PROMPT_COLOUR_CYAN='110' -# Shades -ZSH_PROMPT_COLOUR_GREY1_BG='233' -ZSH_PROMPT_COLOUR_GREY1_FG='242' -ZSH_PROMPT_COLOUR_GREY2_BG='236' -ZSH_PROMPT_COLOUR_GREY2_FG='246' -# Items -ZSH_PROMPT_COLOUR_MAIN='25' -# Git -ZSH_PROMPT_COLOUR_GIT_BRANCH='71' -ZSH_PROMPT_COLOUR_GIT_STATUS='215' -ZSH_PROMPT_ICON_GIT_CLEAN='' -ZSH_PROMPT_ICON_GIT_DIRTY='*' -ZSH_PROMPT_ICON_GIT_PREFIX='(' -ZSH_PROMPT_ICON_GIT_SUFFIX=')' -# }}} - -# -- Help -- {{{ -function prompt_playtime_help() { - cat << EOF -TODO: Write a help menu. -EOF -} -# }}} - -# -- Setup -- {{{ -function prompt_playtime_setup() { - # Colours - local red='$ZSH_PROMPT_COLOUR_RED' - local green='$ZSH_PROMPT_COLOUR_GREEN' - local yellow='$ZSH_PROMPT_COLOUR_YELLOW' - local blue='$ZSH_PROMPT_COLOUR_BLUE' - local magenta='$ZSH_PROMPT_COLOUR_MAGENTA' - local cyan='$ZSH_PROMPT_COLOUR_CYAN' - # Shades - local grey1_bg='$ZSH_PROMPT_COLOUR_GREY1_BG' - local grey1_fg='$ZSH_PROMPT_COLOUR_GREY1_FG' - local grey2_bg='$ZSH_PROMPT_COLOUR_GREY2_BG' - local grey2_fg='$ZSH_PROMPT_COLOUR_GREY2_FG' - # Items - local main='$ZSH_PROMPT_COLOUR_MAIN' - # Variables - local cmdtime='$ZSH_PROMPT_VAR_CMDTIME' - local vimode='$ZSH_PROMPT_VAR_VIMODE' - - # Prompt - local directory="%F{$main}%3~%f" - local gitinfo='$ZSH_PROMPT_VAR_GITINFO' - local symbol="%F{$cyan}%(!.#.»)%f" - PS1="${directory}${gitinfo} ${symbol} " - - # Right Prompt - local cmdtime="%F{$grey1_fg}%K{$grey1_bg} $cmdtime %f%k" - cmdtime="\${ZSH_PROMPT_VAR_CMDTIME:+\"$cmdtime\"}" # hide if unset - local datetime="%F{$grey2_fg}%K{$grey2_bg} %D{%X}%E%f%k" - local exitstatus="%(?,,%F{$red}%K{$grey1_bg} %? %f%k)" - local upjobs="%(1j,%F{$yellow}%K{$grey1_bg} %j %f%k,)" - local userhost="%F{$blue}%K{$grey1_bg} %n@%m %f%k" - userhost="\${SSH_TTY:+\"$userhost\"}" # hide if unset - local vimode="%F{$grey1_fg}%K{$grey1_bg} $vimode %f%k" - vimode="\${KEYMAP:+\"$vimode\"}" # hide if unset - RPS1="${cmdtime}${exitstatus}${upjobs}${userhost}${vimode}${datetime}" - - # Hooks - add-zsh-hook precmd prompt_playtime_precmd - add-zsh-hook preexec prompt_playtime_preexec -} -# }}} - -# -- Hooks -- {{{ -function prompt_playtime_precmd() { - # Get the elapsed command execution time - ZSH_PROMPT_VAR_CMDTIME="${ZSH_PROMPT_VAR_TIMESTAMP:+$(prompt_playtime_cmdtime)}" - # Get the gitinfo for the current directory - ZSH_PROMPT_VAR_GITINFO="${ZSH_PROMPT_VAR_GITINFO:-$(prompt_playtime_gitinfo)}" - # Unset the previous command timestamp - unset ZSH_PROMPT_VAR_TIMESTAMP - # Unset the previous vi-mode - unset ZSH_PROMPT_VAR_VIMODE -} - -function prompt_playtime_preexec() { - # Get the initial command timestamp - ZSH_PROMPT_VAR_TIMESTAMP="$EPOCHREALTIME" - # Unset the previous gitinfo - unset ZSH_PROMPT_VAR_GITINFO -} -# }}} - -# -- Functions -- {{{ -# Calculate command execution time -function prompt_playtime_cmdtime() { - local stop="$EPOCHREALTIME" - local start="${ZSH_PROMPT_VAR_TIMESTAMP:-$stop}" - let local elapsed="$stop - $start" - (( $elapsed > 0 )) && printf '%.2fs' $elapsed -} - -# Determine gitinfo for the current directory -function prompt_playtime_gitinfo() { - # Nothing to print if not inside a git directory - git rev-parse --is-inside-work-tree &> /dev/null || return - # Format the prefix - local prefix="%F{$ZSH_PROMPT_COLOUR_MAIN}$ZSH_PROMPT_ICON_GIT_PREFIX%f" - # Get the current ref - local ref - ref="$(git symbolic-ref --short HEAD 2> /dev/null)" \ - || ref="$(git rev-parse --short HEAD 2> /dev/null)" \ - || return - # Format the branch - local branch="%F{$ZSH_PROMPT_COLOUR_GIT_BRANCH}$ref%f" - # Get the git directory status - local gstatus=$(git status --porcelain) - # Check if the working tree is dirty - local icon - if [ -z "$gstatus" ]; then - icon="$ZSH_PROMPT_ICON_GIT_CLEAN" - else - icon="$ZSH_PROMPT_ICON_GIT_DIRTY" - fi - # Format the icon - icon="%F{$ZSH_PROMPT_COLOUR_GIT_STATUS}$icon%f" - # Format the suffix - local suffix="%F{$ZSH_PROMPT_COLOUR_MAIN}$ZSH_PROMPT_ICON_GIT_SUFFIX%f" - # Return formatted gitinfo - echo "${prefix}${branch}${icon}${suffix}" -} - -# Determine the current vi-mode -function prompt_playtime_vimode() { - local vimode - case $KEYMAP in - main) ;& - viins) vimode='%F{$ZSH_PROMPT_COLOUR_CYAN}INSERT%f' ;; - vicmd) vimode='%F{$ZSH_PROMPT_COLOUR_MAGENTA}NORMAL%f' ;; - esac - echo -n "$vimode" -} -# }}} - -prompt_playtime_setup "$@" diff --git a/apps/zsh/zshrc b/apps/zsh/zshrc index d7068d15..99f6a39a 100644 --- a/apps/zsh/zshrc +++ b/apps/zsh/zshrc @@ -153,7 +153,7 @@ autoload -U promptinit promptinit # Set the prompt theme. -prompt playtime +prompt century # }}} # -- After-hooks -- {{{