prompter coloring and theme

This commit is contained in:
Harivansh Rathi 2026-03-30 22:39:20 -04:00
parent b224a23656
commit 4b436bdbfa
8 changed files with 146 additions and 123 deletions

View file

@ -17,6 +17,7 @@
./mise.nix
./migration.nix
./nvim.nix
./prompt.nix
./skills.nix
./scripts.nix
./ssh.nix

View file

@ -4,16 +4,15 @@
...
}:
{
imports =
[
./common.nix
]
++ lib.optionals hostConfig.isDarwin [
./colima.nix
./rectangle.nix
./karabiner.nix
]
++ lib.optionals hostConfig.isLinux [
./netty-worktree.nix
];
imports = [
./common.nix
]
++ lib.optionals hostConfig.isDarwin [
./colima.nix
./rectangle.nix
./karabiner.nix
]
++ lib.optionals hostConfig.isLinux [
./netty-worktree.nix
];
}

85
home/prompt.nix Normal file
View file

@ -0,0 +1,85 @@
{
config,
lib,
pkgs,
...
}:
let
theme = import ../lib/theme.nix { inherit config; };
in
{
home.packages = [ pkgs.pure-prompt ];
programs.zsh.initContent = lib.mkMerge [
(lib.mkOrder 800 ''
fpath+=("${pkgs.pure-prompt}/share/zsh/site-functions")
autoload -Uz promptinit && promptinit
export PURE_PROMPT_SYMBOL=$'\xe2\x9d\xaf'
export PURE_PROMPT_VICMD_SYMBOL=$'\xe2\x9d\xae'
export PURE_GIT_DIRTY=""
export PURE_GIT_UP_ARROW="^"
export PURE_GIT_DOWN_ARROW="v"
export PURE_GIT_STASH_SYMBOL="="
export PURE_CMD_MAX_EXEC_TIME=5
export PURE_GIT_PULL=0
export PURE_GIT_UNTRACKED_DIRTY=1
zstyle ':prompt:pure:git:stash' show yes
${theme.renderPurePrompt "dark"}
typeset -g prompt_newline=' '
prompt pure
prompt_pure_preprompt_render() {
setopt localoptions noshwordsplit
unset prompt_pure_async_render_requested
typeset -g prompt_pure_git_branch_color=$prompt_pure_colors[git:branch]
[[ -n ''${prompt_pure_git_last_dirty_check_timestamp+x} ]] && prompt_pure_git_branch_color=$prompt_pure_colors[git:branch:cached]
# Branch + arrows turn yellow when dirty
if [[ -n $prompt_pure_git_dirty ]]; then
prompt_pure_git_branch_color=$prompt_pure_colors[git:dirty]
prompt_pure_colors[git:arrow]=$prompt_pure_colors[git:dirty]
else
prompt_pure_colors[git:arrow]=$_codex_pure_default_arrow
fi
psvar[12]=; ((''${(M)#jobstates:#suspended:*} != 0)) && psvar[12]=''${PURE_SUSPENDED_JOBS_SYMBOL:-✦}
psvar[13]=; [[ -n $prompt_pure_state[username] ]] && psvar[13]=1
psvar[14]=''${prompt_pure_vcs_info[branch]}
psvar[15]=
psvar[16]=''${prompt_pure_vcs_info[action]}
psvar[17]=''${prompt_pure_git_arrows}
psvar[18]=; [[ -n $prompt_pure_git_stash ]] && psvar[18]=1
psvar[19]=''${prompt_pure_cmd_exec_time}
local expanded_prompt
expanded_prompt="''${(S%%)PROMPT}"
if [[ $1 != precmd && $prompt_pure_last_prompt != $expanded_prompt ]]; then
prompt_pure_reset_prompt
fi
typeset -g prompt_pure_last_prompt=$expanded_prompt
}
typeset -g _codex_pure_default_arrow=$prompt_pure_colors[git:arrow]
_codex_apply_prompt_theme() {
local mode="$(_codex_read_theme_mode)"
[[ "$mode" == "''${_CODEX_LAST_PROMPT_THEME:-}" ]] && return
if [[ "$mode" == light ]]; then
${theme.renderPurePrompt "light"}
else
${theme.renderPurePrompt "dark"}
fi
typeset -g _codex_pure_default_arrow=$prompt_pure_colors[git:arrow]
typeset -g _CODEX_LAST_PROMPT_THEME="$mode"
}
'')
];
}

View file

@ -9,8 +9,6 @@ let
theme = import ../lib/theme.nix { inherit config; };
in
{
home.packages = [ pkgs.pure-prompt ];
programs.zsh = {
enable = true;
dotDir = config.home.homeDirectory;
@ -58,8 +56,6 @@ in
export NODE_NO_WARNINGS=1
''
+ lib.optionalString hostConfig.isDarwin ''
# Ghostty shell integration expects a resource directory; the Nix app
# bundle lives in the store instead of /Applications.
export GHOSTTY_RESOURCES_DIR="${pkgs.ghostty-bin}/Applications/Ghostty.app/Contents/Resources/ghostty"
''
+ ''
@ -68,32 +64,11 @@ in
initContent = lib.mkMerge [
(lib.mkOrder 550 ''
# Completions
autoload -U compinit && compinit -d "${config.xdg.stateHome}/zcompdump" -u
zmodload zsh/complist
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-za-z}'
'')
(lib.mkOrder 800 ''
# Pure prompt
fpath+=("${pkgs.pure-prompt}/share/zsh/site-functions")
autoload -Uz promptinit && promptinit
export PURE_PROMPT_SYMBOL=">"
export PURE_PROMPT_VICMD_SYMBOL="<"
export PURE_GIT_UP_ARROW="^"
export PURE_GIT_DOWN_ARROW="v"
export PURE_GIT_STASH_SYMBOL="="
export PURE_CMD_MAX_EXEC_TIME=5
export PURE_GIT_PULL=0
export PURE_GIT_UNTRACKED_DIRTY=1
zstyle ':prompt:pure:git:stash' show yes
${theme.renderPurePrompt "dark"}
prompt pure
'')
(lib.mkOrder 1000 ''
if [[ -f ~/.config/secrets/shell.zsh ]]; then
source ~/.config/secrets/shell.zsh
@ -132,39 +107,19 @@ in
return
fi
fi
printf 'dark'
}
_codex_apply_prompt_theme() {
local mode="$(_codex_read_theme_mode)"
if [[ "$mode" == "''${_CODEX_LAST_PROMPT_THEME:-}" ]]; then
return
fi
if [[ "$mode" == light ]]; then
${theme.renderPurePrompt "light"}
else
${theme.renderPurePrompt "dark"}
fi
typeset -g _CODEX_LAST_PROMPT_THEME="$mode"
}
_codex_apply_highlight_styles() {
local mode="$(_codex_read_theme_mode)"
if [[ "$mode" == "''${_CODEX_LAST_HIGHLIGHT_THEME:-}" ]]; then
return
fi
[[ "$mode" == "''${_CODEX_LAST_HIGHLIGHT_THEME:-}" ]] && return
typeset -gA ZSH_HIGHLIGHT_STYLES
if [[ "$mode" == light ]]; then
${theme.renderZshHighlights "light"}
else
${theme.renderZshHighlights "dark"}
fi
typeset -g _CODEX_LAST_HIGHLIGHT_THEME="$mode"
}
@ -173,7 +128,6 @@ in
git() {
command git "$@"
local exit_code=$?
case "$1" in
add|stage|reset|checkout)
if command -v critic >/dev/null 2>&1; then
@ -181,46 +135,23 @@ in
fi
;;
esac
return $exit_code
}
function _codex_set_cursor {
if [[ "$1" == block ]]; then
printf '\e[2 q'
else
printf '\e[6 q'
fi
}
function zle-keymap-select {
if [[ "$KEYMAP" == vicmd ]]; then
_codex_set_cursor block
else
_codex_set_cursor beam
fi
}
zle -N zle-keymap-select
function zle-line-init {
_codex_set_cursor beam
}
zle -N zle-line-init
function zle-line-finish {
_codex_set_cursor beam
}
zle -N zle-line-finish
autoload -Uz add-zle-hook-widget
_codex_cursor() { printf '\e[%s q' "''${1:-6}"; }
_codex_cursor_select() { [[ "$KEYMAP" == vicmd ]] && _codex_cursor 2 || _codex_cursor 6; }
_codex_cursor_beam() { _codex_cursor 6; }
add-zle-hook-widget zle-keymap-select _codex_cursor_select
add-zle-hook-widget zle-line-init _codex_cursor_beam
add-zle-hook-widget zle-line-finish _codex_cursor_beam
precmd() {
_codex_apply_prompt_theme
_codex_apply_highlight_styles
_codex_set_cursor beam
}
preexec() {
_codex_set_cursor beam
_codex_cursor_beam
}
preexec() { _codex_cursor_beam; }
_codex_apply_prompt_theme
_codex_apply_highlight_styles
@ -228,12 +159,7 @@ in
${lib.optionalString hostConfig.isDarwin ''
if command -v wt >/dev/null 2>&1; then
eval "$(command wt config shell init zsh)"
# `wt` changes directories by sourcing directives into the current shell,
# so wrappers around it must stay shell functions instead of scripts.
wtc() {
wt switch --create --base @ "$@"
}
wtc() { wt switch --create --base @ "$@"; }
fi
''}
'')

View file

@ -173,7 +173,11 @@ in
Type = "oneshot";
EnvironmentFile = "/etc/forgejo-mirror.env";
};
path = [ pkgs.curl pkgs.jq pkgs.coreutils ];
path = [
pkgs.curl
pkgs.jq
pkgs.coreutils
];
script = ''
set -euo pipefail

View file

@ -108,7 +108,7 @@ in
])
++ lib.optionals pkgs.stdenv.isDarwin [
agentcomputerPackage
texliveFull
pkgs.texliveFull
]
++ [
openspecPackage

View file

@ -144,29 +144,33 @@ let
mode:
let
theme = themes.${mode};
c = if mode == "light" then {
path = "#4261a5";
branch = "#427b58";
dirty = sharedPalette.yellow;
arrow = sharedPalette.purpleNeutral;
stash = sharedPalette.aquaNeutral;
success = "#427b58";
error = "#c5524a";
execTime = sharedPalette.gray;
host = sharedPalette.gray;
user = sharedPalette.gray;
} else {
path = sharedPalette.blue;
branch = sharedPalette.green;
dirty = sharedPalette.yellowBright;
arrow = sharedPalette.purple;
stash = sharedPalette.aqua;
success = sharedPalette.green;
error = sharedPalette.red;
execTime = sharedPalette.gray;
host = sharedPalette.gray;
user = sharedPalette.gray;
};
c =
if mode == "light" then
{
path = "#4261a5";
branch = "#427b58";
dirty = sharedPalette.yellow;
arrow = sharedPalette.purpleNeutral;
stash = sharedPalette.aquaNeutral;
success = "#427b58";
error = "#c5524a";
execTime = sharedPalette.gray;
host = sharedPalette.gray;
user = sharedPalette.gray;
}
else
{
path = sharedPalette.blue;
branch = sharedPalette.green;
dirty = sharedPalette.yellowBright;
arrow = sharedPalette.purple;
stash = sharedPalette.aqua;
success = sharedPalette.green;
error = sharedPalette.red;
execTime = sharedPalette.gray;
host = sharedPalette.gray;
user = sharedPalette.gray;
};
in
''
zstyle ':prompt:pure:path' color '${c.path}'
@ -228,7 +232,9 @@ let
ZSH_HIGHLIGHT_STYLES[bracket-level-5]='fg=${if mode == "light" then c.aqua else c.aqua},bold'
ZSH_HIGHLIGHT_STYLES[comment]='fg=${c.comment}'
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=${c.purple}'
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=${if mode == "light" then c.aqua else c.aqua}'
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=${
if mode == "light" then c.aqua else c.aqua
}'
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=${c.yellow}'
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=${c.yellow}'
ZSH_HIGHLIGHT_STYLES[global-alias]='fg=${if mode == "light" then c.aqua else c.aqua}'

View file

@ -22,6 +22,8 @@ in
username
];
use-xdg-base-directories = true;
max-jobs = "auto";
cores = 0;
};
nix.gc = {