feat(config): integrate iris and streamline keybindings

This commit is contained in:
Prad Nukala committed 2026-10-05 09:15:20 -04:00
1 parent 43dfe48848
commit 0692ae332b
15 files changed
+268 -137

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
# czs: chezmoi re-add drifted files, then commit + push the source repo.
# Port of functions/czs.fish. Optional targets scope the status view and the
# re-add (e.g. `czs ~/.config/fish`); no args = all managed files.
czs() {
local drift src ahead
drift=$(chezmoi status "$@") || return
if [[ -n $drift ]]; then
print -r -- $drift
# re-add takes the local (destination) contents as truth for modified
# files; templates are never overwritten, non-file entries are ignored.
chezmoi re-add "$@" || return
else
echo "chs: in sync — nothing to re-add"
fi
# Commit + sync the source repo (~/.local/share/chezmoi).
src=$(chezmoi source-path)
if [[ -n $(git -C $src status --porcelain) ]]; then
git -C $src add -A &&
git -C $src commit --quiet -m 'chs: re-add drifted files' || return
echo "chs: committed $(git -C $src rev-parse --short HEAD)"
fi
# Push anything unpushed: this commit and leftovers from a failed push.
# --autostash tolerates post-commit hooks re-dirtying the tree mid-sync.
ahead=$(git -C $src rev-list --count @{upstream}..HEAD 2>/dev/null || echo 0)
if (( ahead > 0 )); then
git -C $src pull --rebase --autostash --quiet &&
git -C $src push --quiet &&
echo "chs: pushed $ahead commit(s) to $(git -C $src remote get-url origin)"
else
echo "chs: remote up to date"
fi
}
+2
View File
@@ -0,0 +1,2 @@
# y: same as yy (fish has both names) — yazi, then cd to its exit directory.
y() { yy "$@"; }
+68 -16
View File
@@ -5,6 +5,20 @@
bindkey -e # pin emacs keymap ($EDITOR containing "vi" would pick viins)
unsetopt flow_control # free ^Q/^S in zle so the ctrl-q exit bind fires
# iris (~/.config/iris) learns a command is running from the preexec/precmd
# hooks, which never fire for programs a widget starts. Without this, iris
# keeps treating the screen as an idle prompt while tv, yazi or lazygit run:
# it swallows up/down/tab and can draw its menu over them. Same messages as
# iris's own hooks; a no-op outside iris. fish: functions/_iris_busy.fish.
_iris_busy() {
[[ -n $IRIS_FD ]] || return 0
case $1 in
start) print -u $IRIS_FD -N -r -- IRIS_CMD_START 2>/dev/null ;;
stop) print -u $IRIS_FD -N -r -- IRIS_CMD_STOP:0 2>/dev/null ;;
esac
return 0
}
# Generic runner: widget `run-<cmd>` executes <cmd> (function or binary) with
# the tty as stdin, then repaints — fish's `commandline -f repaint`.
# cwd changes from gho/yy persist: widgets run in the shell process.
@@ -13,7 +27,9 @@ unsetopt flow_control # free ^Q/^S in zle so the ctrl-q exit bind fires
_zle-run() {
local cmd=${WIDGET#run-}
zle -I
_iris_busy start
$cmd </dev/tty
_iris_busy stop
zle reset-prompt
}
for _cmd in purple clip-last omp-session yy lazygit; do
@@ -31,7 +47,9 @@ unset _cmd
# cursor to tv's line).
_zle-tv-git-files() {
zle -I
_iris_busy start
tv git-files --inline </dev/tty
_iris_busy stop
printf '\033[A' >/dev/tty
zle reset-prompt
}
@@ -42,7 +60,9 @@ zle -N tv-git-files _zle-tv-git-files
_zle-gho() {
local before=$PWD
zle -I
_iris_busy start
gho </dev/tty
_iris_busy stop
if [[ $PWD == "$before" ]]; then
printf '\033[A' >/dev/tty
zle reset-prompt
@@ -50,23 +70,15 @@ _zle-gho() {
}
zle -N gho-inline _zle-gho
# ctrl-p, and down on an idle empty prompt (fish's _pj_bind_down; otherwise
# normal history / multiline movement). pj reports through $PJ_STATE: `open`
# = cancelled, `ran` = a task printed output, empty = no task sources
# (PJ_QUIET keeps down silent outside projects).
# ctrl-p: pj. pj reports through $PJ_STATE: `open` = cancelled, `ran` = a task
# printed output, empty = no task sources.
_zle-pj() {
if [[ $WIDGET == pj-down && -n $BUFFER ]]; then
zle down-line-or-history
return
fi
local state
state=$(mktemp) || return
zle -I
if [[ $WIDGET == pj-down ]]; then
PJ_STATE=$state PJ_QUIET=1 pj </dev/tty
else
PJ_STATE=$state pj </dev/tty
fi
_iris_busy start
PJ_STATE=$state pj </dev/tty
_iris_busy stop
case $(<$state) in
open) printf '\033[A' >/dev/tty; zle reset-prompt ;;
ran) ;;
@@ -75,7 +87,48 @@ _zle-pj() {
rm -f $state
}
zle -N pj-inline _zle-pj
zle -N pj-down _zle-pj
# ctrl-z at the prompt (fish's _jobs_bind): fg the only job, or pick one from
# the `jobs` tv cable, which reads the job table from $TV_JOBS (records:
# "%<id> <state> <command>", id, process group). While a job holds the
# terminal ctrl-z is still the tty's suspend, so the key toggles.
# fg runs as a real command line (push-input keeps typed text for the next
# prompt); __jobs_bind_fg erases that echoed line and fg's "[1] continued"
# notice. The leading space keeps it out of history (HIST_IGNORE_SPACE).
__jobs_bind_fg() {
printf '\033[A\033[2K\r' >/dev/tty
fg %$1 2>/dev/null
}
_zle-jobs() {
local -a ids recs
local id pick file
ids=(${(On)${(k)jobstates}})
(( $#ids )) || return 0
for id in $ids; do
recs+=("$(printf '%%%s %-9s %s\t%s\t%s' $id ${jobstates[$id]%%:*} \
"${jobtexts[$id]}" $id ${${jobstates[$id]#*:*:}%%=*})")
done
if (( $#ids == 1 )); then
pick=$ids[1]
else
file=$(mktemp) || return
print -rl -- $recs >$file
zle -I
_iris_busy start
pick=$(TV_JOBS=$file tv jobs --inline </dev/tty)
_iris_busy stop
printf '\033[A' >/dev/tty
rm -f $file
if [[ -z $pick ]]; then
zle reset-prompt
return
fi
fi
zle push-input
BUFFER=" __jobs_bind_fg $pick"
zle accept-line
}
zle -N jobs-fg _zle-jobs
bindkey '^E' tv-git-files
bindkey '^B' run-purple
@@ -88,8 +141,7 @@ bindkey '^A' run-omp-session
# ctrl-f: yazi; yy cd's to yazi's exit dir on quit.
bindkey '^F' run-yy
bindkey '^G' run-lazygit
bindkey '^[[B' pj-down
bindkey '^[OB' pj-down
bindkey '^Z' jobs-fg
# ctrl-q mirrors ctrl-d's preset (`exit`) — quit the shell.
_zle-exit() { exit }