terminal tool colours

This commit is contained in:
2026-02-24 20:00:53 +00:00
parent e8165041d9
commit faad821c77
7 changed files with 139 additions and 33 deletions

View File

@@ -73,9 +73,16 @@ _dots_abbrev_path() {
}
_dots_session() {
[[ -n "$CODESPACE_NAME" ]] && { print -r -- "$CODESPACE_NAME"; return }
[[ -n "$SSH_CONNECTION" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]] && { print -r -- "%n@%m"; return }
[[ -f /.dockerenv ]] && { print -r -- "${DEVCONTAINER_ID:-$(</etc/hostname)}"; return }
local name=""
if [[ -n "$CODESPACE_NAME" ]]; then
# Strip final random suffix (e.g. "redesigned-couscous-jp5676rpq5h5wrj" -> "redesigned-couscous")
name="${CODESPACE_NAME%-*}"
elif [[ -n "$SSH_CONNECTION" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
name="%n@%m"
elif [[ -f /.dockerenv ]]; then
name="${DEVCONTAINER_ID:-$(</etc/hostname)}"
fi
[[ -n "$name" ]] && print -r -- "$name"
}
_dots_git_info_sync() {
@@ -260,7 +267,7 @@ _dots_precmd() {
(( e )) && rp_parts+=("${_dots_pc[red]}[${e}]${_dots_pc[reset]}")
local session="$(_dots_session)"
[[ -n "$session" ]] && rp_parts+=("${_dots_pc[orange]}[${session}]${_dots_pc[reset]}")
[[ -n "$session" ]] && rp_parts+=("${_dots_pc[dark_bg]}${_dots_pc[dark]}[${_dots_pc[orange]}${session}${_dots_pc[reset]}${_dots_pc[dark_bg]}${_dots_pc[dark]}]${_dots_pc[reset]}")
RPROMPT="${(j: :)rp_parts}"

View File

@@ -26,11 +26,48 @@ _dots_load_keybindings() {
zle -N _dots_git_branch_widget
bindkey '^B' _dots_git_branch_widget
# Ctrl+E: edit file
# Ctrl+E: edit file (frecency + git status boost)
_dots_edit_widget() {
local file
file="$(rg --files --hidden --glob '!.git' 2>/dev/null \
| fzf --preview 'bat --color=always --style=numbers --line-range=:100 {} || head -100 {}')" || { zle reset-prompt; return; }
local file edit_log="${XDG_DATA_HOME:-$HOME/.local/share}/edit/log"
file="$({
awk -v logfile="$edit_log" '
BEGIN {
while ((getline line < logfile) > 0) {
idx = index(line, "\t")
if (idx) { f = substr(line, idx+1); cnt[f]++; ts[f] = substr(line, 1, idx-1)+0 }
}
close(logfile)
cmd = "git status --porcelain 2>/dev/null"
while ((cmd | getline line) > 0) {
st = substr(line, 1, 2); f = substr(line, 4)
if ((i = index(f, " -> ")) > 0) f = substr(f, i+4)
gsub(/^"|"$/, "", f)
if (st !~ /D/) git[f] = st
}
close(cmd)
for (f in cnt) {
s = cnt[f] * 1000 + ts[f]
if (f in git) { s += 100000; printf "%d\t%s\t%s\n", s, clr(git[f]), f; delete git[f] }
else printf "%d\t \t%s\n", s, f
}
for (f in git) printf "100000\t%s\t%s\n", clr(git[f]), f
}
function clr(st) {
if (st ~ /^\?\?/) return "\033[90m?\033[0m"
if (st ~ /^R/) return "\033[36mR\033[0m"
if (st ~ /^A/) return "\033[32mA\033[0m"
if (st ~ /M/) return "\033[33mM\033[0m"
return "\033[90m~\033[0m"
}' /dev/null 2>/dev/null | sort -rn | cut -f2-
rg --files --hidden --glob '!.git' 2>/dev/null | awk '{print " \t" $0}'
} | awk -F'\t' '!seen[$2]++' \
| fzf --ansi --delimiter='\t' --nth=2 \
--preview 'bat --color=always --style=numbers --line-range=:100 {2} 2>/dev/null || head -100 {2}')" \
|| { zle reset-prompt; return; }
file="$(printf '%s' "$file" | cut -f2)"
[[ -z "$file" ]] && { zle reset-prompt; return; }
mkdir -p "${edit_log:h}"
printf '%s\t%s\n' "$(date +%s)" "$file" >> "$edit_log"
BUFFER="${EDITOR:-vim} ${(q)file}"
zle reset-prompt
zle accept-line