update shell config
This commit is contained in:
@@ -9,10 +9,33 @@ zmodload zsh/datetime
|
||||
: ${uy_done_min_cmd_duration:=10}
|
||||
: ${uy_done_exclude:='^(nvim|helix|hx|vim|vi|nano|less|more|man|ssh|top|htop|btop|sudoedit)$'}
|
||||
|
||||
uy_done_get_focused_window_id() {
|
||||
(( $+commands[jq] )) || return
|
||||
niri msg --json focused-window 2>/dev/null | jq -r '.id // empty'
|
||||
}
|
||||
# Returns the id in $REPLY, empty if there is none or niri did not answer.
|
||||
if zmodload zsh/net/socket 2>/dev/null; then
|
||||
uy_done_get_focused_window_id() {
|
||||
setopt local_options extended_glob
|
||||
local fd line
|
||||
local -a match mbegin mend
|
||||
REPLY=
|
||||
|
||||
zsocket "$NIRI_SOCKET" 2>/dev/null || return
|
||||
fd=$REPLY
|
||||
REPLY=
|
||||
|
||||
if print -u $fd -r -- '"FocusedWindow"' 2>/dev/null; then
|
||||
read -t 1 -u $fd -r line 2>/dev/null
|
||||
fi
|
||||
exec {fd}>&-
|
||||
|
||||
# With no focused window the payload is null, so the id is simply absent.
|
||||
[[ $line == (#b)*'"FocusedWindow":'*'"id":'(<->)* ]] && REPLY=$match[1]
|
||||
}
|
||||
elif (( $+commands[jq] )); then
|
||||
uy_done_get_focused_window_id() {
|
||||
REPLY=$(niri msg --json focused-window 2>/dev/null | jq -r '.id // empty')
|
||||
}
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
uy_done_cmd_name() {
|
||||
local -a words
|
||||
@@ -33,9 +56,11 @@ uy_done_cmd_name() {
|
||||
}
|
||||
|
||||
uy_done_preexec() {
|
||||
local REPLY
|
||||
uy_done_cmd="$1"
|
||||
uy_done_start=$EPOCHSECONDS
|
||||
uy_done_window_id=$(uy_done_get_focused_window_id)
|
||||
uy_done_get_focused_window_id
|
||||
uy_done_window_id=$REPLY
|
||||
}
|
||||
|
||||
uy_done_precmd() {
|
||||
@@ -54,7 +79,8 @@ uy_done_precmd() {
|
||||
|
||||
# skip if window is still focused
|
||||
local current_id
|
||||
current_id=$(uy_done_get_focused_window_id)
|
||||
uy_done_get_focused_window_id
|
||||
current_id=$REPLY
|
||||
[[ -n "$uy_done_window_id" && "$uy_done_window_id" = "$current_id" ]] && return
|
||||
|
||||
# humanize duration
|
||||
|
||||
@@ -7,7 +7,7 @@ fi
|
||||
|
||||
# Editor
|
||||
|
||||
for _uy_app in nvim helix vim vi nano; do
|
||||
for _uy_app in helix nvim vim vi nano; do
|
||||
if (( $+commands[$_uy_app] )); then
|
||||
export EDITOR=$_uy_app
|
||||
export VISUAL=$_uy_app
|
||||
@@ -30,12 +30,6 @@ fi
|
||||
|
||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#6c7086"
|
||||
|
||||
# Vscode shell integration
|
||||
|
||||
if (( $+commands[code] )) && [[ "$TERM_PROGRAM" == "vscode" ]]; then
|
||||
source "$(code --locate-shell-integration-path zsh)"
|
||||
fi
|
||||
|
||||
# fnm
|
||||
|
||||
if (( $+commands[fnm] )); then
|
||||
|
||||
@@ -17,7 +17,7 @@ uy_oops_confirm() {
|
||||
# when the current one ends in a backslash; zsh writes a command that itself
|
||||
# ends in a backslash as "\ " (trailing space), so the marker is unambiguous.
|
||||
# Walking forward and remembering the start of each entry is exact for
|
||||
# entries of any length — scanning backwards over a fixed window is not.
|
||||
# entries of any length.
|
||||
local start
|
||||
start=$(awk '{ if (!cont) start = NR; cont = /\\$/ } END { print start + 0 }' "$HISTFILE")
|
||||
|
||||
@@ -49,11 +49,20 @@ uy_oops_confirm() {
|
||||
# one) correctly leaves an empty file.
|
||||
local n=${#ordered[@]}
|
||||
head -n $(( start - 1 )) "$HISTFILE" > "$HISTFILE.tmp" && mv "$HISTFILE.tmp" "$HISTFILE"
|
||||
# Replace the in-memory history with the updated file.
|
||||
# `fc -R` would *append* the file on top of what is already in memory,
|
||||
# which both duplicates every entry and leaves the deleted command in
|
||||
# memory — the next `fc -W` (e.g. the one at the top of this function
|
||||
# on a second `oops`) would then write it straight back to the file.
|
||||
# Replace the in-memory history with the updated file. `fc -p` is the
|
||||
# only primitive that replaces it: `fc -R` *appends* the file on top of
|
||||
# what is already in memory, which both duplicates every entry and
|
||||
# leaves the deleted command there for the next `fc -W` to write back.
|
||||
#
|
||||
# `fc -p` pushes a history layer, and each layer retains a full copy of
|
||||
# the history, so pop the layer the previous call left behind first —
|
||||
# that keeps exactly one live no matter how often `oops` runs. `fc -P`
|
||||
# only restores the old in-memory list, it does not write to $HISTFILE,
|
||||
# so it cannot undo the deletion above; and the push on the very next
|
||||
# line replaces that stale list immediately. Both must stay in this
|
||||
# branch: on the cancel path nothing was deleted, so memory already
|
||||
# matches the file and popping would corrupt it.
|
||||
fc -P 2>/dev/null
|
||||
fc -p "$HISTFILE" $HISTSIZE $SAVEHIST
|
||||
print -P "%F{green}Deleted ($n line(s) removed).%f"
|
||||
else
|
||||
|
||||
@@ -5,13 +5,42 @@ PROMPT='%F{blue}%n@%m%f %F{cyan}%~%f > '
|
||||
if (( $+commands[starship] )); then
|
||||
eval "$(starship init zsh)"
|
||||
|
||||
function uy_transient_prompt() {
|
||||
local file palette color
|
||||
file=${STARSHIP_CONFIG:-"$HOME/.config/starship.toml"}
|
||||
palette=$(sed -n "s/^palette\s*=\s*'\(.*\)'/\1/p" "$file")
|
||||
color=$(sed -n "/^\[palettes\.${palette}\]/,/^\[/{s/^accent\s*=\s*\"\(.*\)\"/\1/p}" "$file")
|
||||
# accent of the [palettes.<name>] named by the top-level `palette` key.
|
||||
function uy_starship_accent() {
|
||||
setopt local_options extended_glob
|
||||
local line palette in_palette=0
|
||||
local -a lines
|
||||
[[ -r $1 ]] || return 1
|
||||
lines=( ${(f)"$(<$1)"} )
|
||||
|
||||
PROMPT="%F{$color}#%f " zle .reset-prompt
|
||||
for line in $lines; do
|
||||
if [[ $line == palette[[:blank:]]#=[[:blank:]]#\'*\' ]]; then
|
||||
palette=${${line#*\'}%\'}
|
||||
break
|
||||
fi
|
||||
done
|
||||
[[ -n $palette ]] || return 1
|
||||
|
||||
for line in $lines; do
|
||||
if (( in_palette )); then
|
||||
[[ $line == \[* ]] && return 1
|
||||
if [[ $line == accent[[:blank:]]#=[[:blank:]]#\"*\" ]]; then
|
||||
REPLY=${${line#*\"}%\"}
|
||||
return 0
|
||||
fi
|
||||
elif [[ $line == "[palettes.$palette]" ]]; then
|
||||
in_palette=1
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function uy_transient_prompt() {
|
||||
local REPLY
|
||||
uy_starship_accent "${STARSHIP_CONFIG:-$HOME/.config/starship.toml}" &&
|
||||
uy_accent=$REPLY
|
||||
|
||||
PROMPT="%F{${uy_accent:-blue}}#%f " zle .reset-prompt
|
||||
}
|
||||
|
||||
autoload -Uz add-zle-hook-widget
|
||||
@@ -21,4 +50,3 @@ if (( $+commands[starship] )); then
|
||||
elif [[ -f "$HOME/.config/posh_theme.omp.json" ]] && (( $+commands[oh-my-posh] )); then
|
||||
eval "$(oh-my-posh init zsh --config "$HOME/.config/posh_theme.omp.json")"
|
||||
fi
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ if (( $+commands[fzf] )); then
|
||||
|
||||
# use fd if available (search cwd only, skip vcs/cache junk)
|
||||
if (( $+commands[fd] )); then
|
||||
export FD_CMD="fd"
|
||||
FD_CMD="fd"
|
||||
elif (( $+commands[fdfind] )); then
|
||||
export FD_CMD="fdfind"
|
||||
FD_CMD="fdfind"
|
||||
fi
|
||||
if [[ -n "$FD_CMD" ]]; then
|
||||
export FZF_DEFAULT_COMMAND="$FD_CMD --type f --hidden --exclude .git"
|
||||
@@ -225,8 +225,14 @@ if (( $+commands[jj] )); then
|
||||
|
||||
jjp() {
|
||||
default_branch() {
|
||||
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|.*/||' \
|
||||
|| git remote show origin | awk '/HEAD branch/ {print $NF}' || echo "master"
|
||||
local ref
|
||||
ref=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)
|
||||
if [[ -n "$ref" ]]; then
|
||||
print -r -- "${ref:t}"
|
||||
return
|
||||
fi
|
||||
ref=$(git remote show origin 2>/dev/null | awk '/HEAD branch/ {print $NF}')
|
||||
print -r -- "${ref:-master}"
|
||||
}
|
||||
local branch pos
|
||||
branch=${1:-$(default_branch)}
|
||||
|
||||
@@ -52,6 +52,10 @@ sixel)
|
||||
uy_fetch_args=(--logo-type raw --logo-width 42 --logo "$HOME/.config/fastfetch/logo_ros/42x.sixel" --color "$uy_fetch_color")
|
||||
uy_fetch_args_brief=(--logo-type raw --logo-width 28 --logo "$HOME/.config/fastfetch/logo_ros/28x.sixel" --color "$uy_fetch_color")
|
||||
;;
|
||||
unicode)
|
||||
uy_fetch_args=(--logo-type raw --logo-width 42 --logo "$HOME/.config/fastfetch/logo_ros/42x.unicode" --color "$uy_fetch_color")
|
||||
uy_fetch_args_brief=(--logo-type raw --logo-width 28 --logo "$HOME/.config/fastfetch/logo_ros/28x.unicode" --color "$uy_fetch_color")
|
||||
;;
|
||||
*) # kitty, auto, etc.
|
||||
uy_fetch_args=(--logo-type "$uy_fetch_logo_type" --logo-width 42 --logo "$HOME/.config/fastfetch/logo_ros/ros.png" --color "$uy_fetch_color")
|
||||
uy_fetch_args_brief=(--logo-type "$uy_fetch_logo_type" --logo-width 28 --logo "$HOME/.config/fastfetch/logo_ros/ros.png" --color "$uy_fetch_color")
|
||||
|
||||
Reference in New Issue
Block a user