mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 09:01:16 +00:00
prompter coloring and theme
This commit is contained in:
parent
b224a23656
commit
4b436bdbfa
8 changed files with 146 additions and 123 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
./mise.nix
|
./mise.nix
|
||||||
./migration.nix
|
./migration.nix
|
||||||
./nvim.nix
|
./nvim.nix
|
||||||
|
./prompt.nix
|
||||||
./skills.nix
|
./skills.nix
|
||||||
./scripts.nix
|
./scripts.nix
|
||||||
./ssh.nix
|
./ssh.nix
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,15 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports =
|
imports = [
|
||||||
[
|
./common.nix
|
||||||
./common.nix
|
]
|
||||||
]
|
++ lib.optionals hostConfig.isDarwin [
|
||||||
++ lib.optionals hostConfig.isDarwin [
|
./colima.nix
|
||||||
./colima.nix
|
./rectangle.nix
|
||||||
./rectangle.nix
|
./karabiner.nix
|
||||||
./karabiner.nix
|
]
|
||||||
]
|
++ lib.optionals hostConfig.isLinux [
|
||||||
++ lib.optionals hostConfig.isLinux [
|
./netty-worktree.nix
|
||||||
./netty-worktree.nix
|
];
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
85
home/prompt.nix
Normal file
85
home/prompt.nix
Normal 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"
|
||||||
|
}
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
}
|
||||||
96
home/zsh.nix
96
home/zsh.nix
|
|
@ -9,8 +9,6 @@ let
|
||||||
theme = import ../lib/theme.nix { inherit config; };
|
theme = import ../lib/theme.nix { inherit config; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home.packages = [ pkgs.pure-prompt ];
|
|
||||||
|
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
dotDir = config.home.homeDirectory;
|
dotDir = config.home.homeDirectory;
|
||||||
|
|
@ -58,8 +56,6 @@ in
|
||||||
export NODE_NO_WARNINGS=1
|
export NODE_NO_WARNINGS=1
|
||||||
''
|
''
|
||||||
+ lib.optionalString hostConfig.isDarwin ''
|
+ 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"
|
export GHOSTTY_RESOURCES_DIR="${pkgs.ghostty-bin}/Applications/Ghostty.app/Contents/Resources/ghostty"
|
||||||
''
|
''
|
||||||
+ ''
|
+ ''
|
||||||
|
|
@ -68,32 +64,11 @@ in
|
||||||
|
|
||||||
initContent = lib.mkMerge [
|
initContent = lib.mkMerge [
|
||||||
(lib.mkOrder 550 ''
|
(lib.mkOrder 550 ''
|
||||||
# Completions
|
|
||||||
autoload -U compinit && compinit -d "${config.xdg.stateHome}/zcompdump" -u
|
autoload -U compinit && compinit -d "${config.xdg.stateHome}/zcompdump" -u
|
||||||
zmodload zsh/complist
|
zmodload zsh/complist
|
||||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-za-z}'
|
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 ''
|
(lib.mkOrder 1000 ''
|
||||||
if [[ -f ~/.config/secrets/shell.zsh ]]; then
|
if [[ -f ~/.config/secrets/shell.zsh ]]; then
|
||||||
source ~/.config/secrets/shell.zsh
|
source ~/.config/secrets/shell.zsh
|
||||||
|
|
@ -132,39 +107,19 @@ in
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'dark'
|
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() {
|
_codex_apply_highlight_styles() {
|
||||||
local mode="$(_codex_read_theme_mode)"
|
local mode="$(_codex_read_theme_mode)"
|
||||||
if [[ "$mode" == "''${_CODEX_LAST_HIGHLIGHT_THEME:-}" ]]; then
|
[[ "$mode" == "''${_CODEX_LAST_HIGHLIGHT_THEME:-}" ]] && return
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
typeset -gA ZSH_HIGHLIGHT_STYLES
|
typeset -gA ZSH_HIGHLIGHT_STYLES
|
||||||
|
|
||||||
if [[ "$mode" == light ]]; then
|
if [[ "$mode" == light ]]; then
|
||||||
${theme.renderZshHighlights "light"}
|
${theme.renderZshHighlights "light"}
|
||||||
else
|
else
|
||||||
${theme.renderZshHighlights "dark"}
|
${theme.renderZshHighlights "dark"}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
typeset -g _CODEX_LAST_HIGHLIGHT_THEME="$mode"
|
typeset -g _CODEX_LAST_HIGHLIGHT_THEME="$mode"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +128,6 @@ in
|
||||||
git() {
|
git() {
|
||||||
command git "$@"
|
command git "$@"
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
add|stage|reset|checkout)
|
add|stage|reset|checkout)
|
||||||
if command -v critic >/dev/null 2>&1; then
|
if command -v critic >/dev/null 2>&1; then
|
||||||
|
|
@ -181,46 +135,23 @@ in
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
return $exit_code
|
return $exit_code
|
||||||
}
|
}
|
||||||
|
|
||||||
function _codex_set_cursor {
|
autoload -Uz add-zle-hook-widget
|
||||||
if [[ "$1" == block ]]; then
|
_codex_cursor() { printf '\e[%s q' "''${1:-6}"; }
|
||||||
printf '\e[2 q'
|
_codex_cursor_select() { [[ "$KEYMAP" == vicmd ]] && _codex_cursor 2 || _codex_cursor 6; }
|
||||||
else
|
_codex_cursor_beam() { _codex_cursor 6; }
|
||||||
printf '\e[6 q'
|
add-zle-hook-widget zle-keymap-select _codex_cursor_select
|
||||||
fi
|
add-zle-hook-widget zle-line-init _codex_cursor_beam
|
||||||
}
|
add-zle-hook-widget zle-line-finish _codex_cursor_beam
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
precmd() {
|
precmd() {
|
||||||
_codex_apply_prompt_theme
|
_codex_apply_prompt_theme
|
||||||
_codex_apply_highlight_styles
|
_codex_apply_highlight_styles
|
||||||
_codex_set_cursor beam
|
_codex_cursor_beam
|
||||||
}
|
|
||||||
|
|
||||||
preexec() {
|
|
||||||
_codex_set_cursor beam
|
|
||||||
}
|
}
|
||||||
|
preexec() { _codex_cursor_beam; }
|
||||||
|
|
||||||
_codex_apply_prompt_theme
|
_codex_apply_prompt_theme
|
||||||
_codex_apply_highlight_styles
|
_codex_apply_highlight_styles
|
||||||
|
|
@ -228,12 +159,7 @@ in
|
||||||
${lib.optionalString hostConfig.isDarwin ''
|
${lib.optionalString hostConfig.isDarwin ''
|
||||||
if command -v wt >/dev/null 2>&1; then
|
if command -v wt >/dev/null 2>&1; then
|
||||||
eval "$(command wt config shell init zsh)"
|
eval "$(command wt config shell init zsh)"
|
||||||
|
wtc() { wt switch --create --base @ "$@"; }
|
||||||
# `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 @ "$@"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
''}
|
''}
|
||||||
'')
|
'')
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,11 @@ in
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
EnvironmentFile = "/etc/forgejo-mirror.env";
|
EnvironmentFile = "/etc/forgejo-mirror.env";
|
||||||
};
|
};
|
||||||
path = [ pkgs.curl pkgs.jq pkgs.coreutils ];
|
path = [
|
||||||
|
pkgs.curl
|
||||||
|
pkgs.jq
|
||||||
|
pkgs.coreutils
|
||||||
|
];
|
||||||
script = ''
|
script = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ in
|
||||||
])
|
])
|
||||||
++ lib.optionals pkgs.stdenv.isDarwin [
|
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||||
agentcomputerPackage
|
agentcomputerPackage
|
||||||
texliveFull
|
pkgs.texliveFull
|
||||||
]
|
]
|
||||||
++ [
|
++ [
|
||||||
openspecPackage
|
openspecPackage
|
||||||
|
|
|
||||||
|
|
@ -144,29 +144,33 @@ let
|
||||||
mode:
|
mode:
|
||||||
let
|
let
|
||||||
theme = themes.${mode};
|
theme = themes.${mode};
|
||||||
c = if mode == "light" then {
|
c =
|
||||||
path = "#4261a5";
|
if mode == "light" then
|
||||||
branch = "#427b58";
|
{
|
||||||
dirty = sharedPalette.yellow;
|
path = "#4261a5";
|
||||||
arrow = sharedPalette.purpleNeutral;
|
branch = "#427b58";
|
||||||
stash = sharedPalette.aquaNeutral;
|
dirty = sharedPalette.yellow;
|
||||||
success = "#427b58";
|
arrow = sharedPalette.purpleNeutral;
|
||||||
error = "#c5524a";
|
stash = sharedPalette.aquaNeutral;
|
||||||
execTime = sharedPalette.gray;
|
success = "#427b58";
|
||||||
host = sharedPalette.gray;
|
error = "#c5524a";
|
||||||
user = sharedPalette.gray;
|
execTime = sharedPalette.gray;
|
||||||
} else {
|
host = sharedPalette.gray;
|
||||||
path = sharedPalette.blue;
|
user = sharedPalette.gray;
|
||||||
branch = sharedPalette.green;
|
}
|
||||||
dirty = sharedPalette.yellowBright;
|
else
|
||||||
arrow = sharedPalette.purple;
|
{
|
||||||
stash = sharedPalette.aqua;
|
path = sharedPalette.blue;
|
||||||
success = sharedPalette.green;
|
branch = sharedPalette.green;
|
||||||
error = sharedPalette.red;
|
dirty = sharedPalette.yellowBright;
|
||||||
execTime = sharedPalette.gray;
|
arrow = sharedPalette.purple;
|
||||||
host = sharedPalette.gray;
|
stash = sharedPalette.aqua;
|
||||||
user = sharedPalette.gray;
|
success = sharedPalette.green;
|
||||||
};
|
error = sharedPalette.red;
|
||||||
|
execTime = sharedPalette.gray;
|
||||||
|
host = sharedPalette.gray;
|
||||||
|
user = sharedPalette.gray;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
zstyle ':prompt:pure:path' color '${c.path}'
|
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[bracket-level-5]='fg=${if mode == "light" then c.aqua else c.aqua},bold'
|
||||||
ZSH_HIGHLIGHT_STYLES[comment]='fg=${c.comment}'
|
ZSH_HIGHLIGHT_STYLES[comment]='fg=${c.comment}'
|
||||||
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=${c.purple}'
|
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[dollar-quoted-argument]='fg=${c.yellow}'
|
||||||
ZSH_HIGHLIGHT_STYLES[double-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}'
|
ZSH_HIGHLIGHT_STYLES[global-alias]='fg=${if mode == "light" then c.aqua else c.aqua}'
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ in
|
||||||
username
|
username
|
||||||
];
|
];
|
||||||
use-xdg-base-directories = true;
|
use-xdg-base-directories = true;
|
||||||
|
max-jobs = "auto";
|
||||||
|
cores = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
nix.gc = {
|
nix.gc = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue