Skip to content

Instantly share code, notes, and snippets.

@ghiden
Last active May 26, 2026 08:50
Show Gist options
  • Select an option

  • Save ghiden/e5061bd293c5df53c99a10ed79c3d0f9 to your computer and use it in GitHub Desktop.

Select an option

Save ghiden/e5061bd293c5df53c99a10ed79c3d0f9 to your computer and use it in GitHub Desktop.
zk edit interactive loop
# zk interactive loop
zkloop() {
# set current directory name
print -Pn "\e]2;%1~\a"
while true; do
local flag=$(mktemp)
local wrapper=$(mktemp)
# We hardcode your actual editor here (e.g., nvim) so nothing gets lost
cat <<-EOF > "$wrapper"
#!/bin/sh
echo 1 > "$flag"
exec nvim "\$@"
EOF
chmod +x "$wrapper"
# ZK_EDITOR overrides everything, including zk's config.toml
ZK_EDITOR="$wrapper" zk edit -i --sort modified-
local was_launched=$(cat "$flag")
rm -f "$flag" "$wrapper"
# If empty, the editor never launched (you pressed Esc/Ctrl-C)
if [ -z "$was_launched" ]; then
break
fi
clear
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment