-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zsh): change prompt {playtime => century}
- Loading branch information
Showing
6 changed files
with
145 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# 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 | ||
|
||
|
||
# ---------------- | ||
# -- Prompt -- | ||
# ---------------- | ||
|
||
function prompt_century_setup() { | ||
local RST="%b%f%k" | ||
local JOB="%b%F{${CENTURY[YLW]}}%(1j.%j! .)" | ||
local SYM="%B%F{%(0?.${CENTURY[GRN]}.${CENTURY[RED]})}%(!.#.❯) " | ||
local USR="%b%F{${CENTURY[CYN]}}%n " | ||
PS1=" ${USR}${JOB}${SYM}${RST}" | ||
|
||
local CLK="%b%F{${CENTURY[BW2]}}[%D{%X}]" | ||
local CWD="%B%F{${CENTURY[BLU]}}%2~" | ||
local GIT='${CENTURY[GIT]} ' | ||
local RET="%b%F{${CENTURY[RED]}}%(0?..%? )" | ||
local TMR='${CENTURY[TMR]} ' | ||
RPS1="${RET}${TMR}${CWD}${GIT}${CLK}${RST}" | ||
} | ||
|
||
|
||
# ---------------- | ||
# -- Hooks -- | ||
# ---------------- | ||
|
||
function hook-preexec-timer() { | ||
CENTURY[ERT]=$EPOCHREALTIME | ||
} | ||
add-zsh-hook preexec hook-preexec-timer | ||
|
||
function hook-precmd-timer() { | ||
local -A color | ||
color[TMR]="${CENTURY[BW1]}" | ||
|
||
let local timer="$EPOCHREALTIME-${CENTURY[ERT]:-$EPOCHREALTIME}" | ||
local tmr | ||
(( $timer > 0 )) && { | ||
tmr="$(printf '%.2fs' $timer)" | ||
CENTURY[ERT]= | ||
} | ||
|
||
CENTURY[TMR]="%b%F{${color[TMR]}}${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 -A color | ||
color[DRY]="${CENTURY[YL2]}" | ||
color[PAR]="${CENTURY[BLU]}" | ||
color[REF]="${CENTURY[GR2]}" | ||
|
||
local dry="$(git status --porcelain)" | ||
local ref="$(git symbolic-ref -q --short HEAD)" \ | ||
|| ref="$(git rev-parse --short HEAD)" \ | ||
|| return | ||
|
||
local OPN="%b%F{${color[PAR]}}(" | ||
local DRY="%b%F{${color[DRY]}}${dry:+*}" | ||
local REF="%b%F{${color[REF]}}${ref}" | ||
local CLS="%b%F{${color[PAR]}})" | ||
|
||
CENTURY[GIT]="${OPN}${REF}${DRY}${CLS}" | ||
} | ||
add-zsh-hook precmd hook-precmd-git | ||
|
||
|
||
# ---------------- | ||
# -- Setup -- | ||
# ---------------- | ||
|
||
prompt_century_setup "$@" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters