Skip to content

Commit

Permalink
feat(zsh): change prompt {playtime => century}
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanz committed Feb 11, 2024
1 parent 3b9668b commit 8372412
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 202 deletions.
72 changes: 33 additions & 39 deletions apps/zsh/after/highlight.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
4 changes: 2 additions & 2 deletions apps/zsh/after/utils/fzf.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions apps/zsh/plugin/vi-mode.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
163 changes: 163 additions & 0 deletions apps/zsh/themes/prompt_century_setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# File: prompt_century_setup
# Author: Zakhary Kaplan <https://zakhary.dev>
# 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 <<EOF
Usage: prompt century [OPTIONS]
Options:
-1 Render as one line
-2 Render as two lines
EOF
}



# ----------------
# -- Prompt --
# ----------------

function prompt_century_setup() {
# Parse opts
local nlines=2
while getopts "12" opt; do
case $opt in
1)
nlines=1
;;
2)
nlines=2
;;
esac
done

# Autoloads
local -A schars
autoload -Uz prompt_special_chars
prompt_special_chars

# Blocks
local CLK="%b%F{$CENTURY[BW2]}[%D{%X}]"
local CTX="%b%F{$CENTURY[YLW]}%_"
local CWD="%B%F{$CENTURY[BLU]}%2~"
local GIT='$CENTURY[GIT] '
local JOB="%b%F{$CENTURY[YLW]}%(1j.%j! .)"
local RET="%b%F{$CENTURY[RED]}%(0?..%? )"
local SYM="%B%F{%(0?.$CENTURY[GRN].$CENTURY[RED])}%(!.#.❯) "
local TMR='$CENTURY[TMR] '
local USR="%b%F{$CENTURY[CYN]}%n${SSH_TTY:+@%m} "

# Special
local TOP="%F{$CENTURY[BW1]}┏ "
local PLN="$prompt_newline"
local BTM="%F{$CENTURY[BW1]}┗ "
local RST="%b%f%k"

# Prompts
PS1=
PS2=
case $nlines in
1)
PS1+="${USR}${JOB}${RET}${SYM}${RST}"
RPS1="${TMR}${CWD}${GIT}${CLK}${RST}"
;;
2)
PS1+="${TOP}${CWD}${GIT}${PLN}"
PS1+="${BTM}${USR}${JOB}${RET}${SYM}${RST}"
RPS1="${TMR}${CLK}${RST}"
;;
esac
PS2+="${CTX} » ${RST}"
ZLE_RPROMPT_INDENT=0
}


# ----------------
# -- Hooks --
# ----------------

function hook-preexec-timer() {
CENTURY[ERT]=$EPOCHREALTIME
}
add-zsh-hook preexec hook-preexec-timer

function hook-precmd-timer() {
let local timer="$EPOCHREALTIME-${CENTURY[ERT]:-$EPOCHREALTIME}"
local tmr
(( $timer > 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 "$@"
Loading

0 comments on commit 8372412

Please sign in to comment.