23 lines
844 B
Bash
Raw Normal View History

2026-03-09 00:07:31 -04:00
#!/usr/bin/env bash
set -eo pipefail
CWD=$(dirname "$1")
if [ -n "$TMUX" ]; then
if tmux list-panes -F "#{pane_title}" 2>/dev/null | grep -q "^$EDITOR$"; then
tmux send-keys -t "$EDITOR" ":e $1" Enter
else
tmux split-window -h -p 83 -c "$CWD" -P -F "#{pane_id}" "exec $EDITOR '$1'"
tmux select-pane -T "$EDITOR"
tmux split-window -v -p 20 -c "$CWD"
fi
elif [ -n "$KITTY_WINDOW_ID" ]; then
if kitty @ focus-window --match "title:$EDITOR" 2>/dev/null; then
kitty @ send-text --match "title:$EDITOR" ":e $1\x0d"
else
kitty @ launch --title "$EDITOR" --location=vsplit --bias=83 --cwd "$CWD" bash -c "'$EDITOR' '$1'; while true; do '$EDITOR'; done"
kitty @ launch --title "CLI" --dont-take-focus --location=hsplit --bias=20 --cwd "$CWD"
fi
else
"$EDITOR" "$1"
fi