aboutsummaryrefslogtreecommitdiff
path: root/dot_config/herdr/plugins/github/herdr-splits-d880c4924f2b/scripts/executable_herdr-nav.sh
blob: 9cdbbb7b9d0d61f7384a4d05f12dc7e2075fba7c (generated by cgit 1.3.1 (git 2.54.0) at 2026-10-12 15:15:41 +0000
>herdr="${HERDR_BIN_PATH:-herdr}" case "$dir" in left) key="ctrl+h"; config_key="nav_key_left"; opp="right" ;; down) key="ctrl+j"; config_key="nav_key_down"; opp="up" ;; up) key="ctrl+k"; config_key="nav_key_up"; opp="down" ;; right) key="ctrl+l"; config_key="nav_key_right"; opp="left" ;; *) echo "herdr-nav.sh: unknown direction: $dir" >&2; exit 2 ;; esac # Resolve `unzoom_on_nav` and `nav_at_edge` from the shared config file. # Defaults: unzoom enabled, nav_at_edge=wrap (backward compatible). unzoom=1 nav_at_edge=wrap config_path="${HERDR_SPLITS_CONFIG:-${HERDR_PLUGIN_CONFIG_DIR:-$HOME/.config/herdr/plugins/config/herdr-splits}/herdr-splits.conf}" if [ -r "$config_path" ]; then configured_key=$(sed -n -E "s/^[[:space:]]*${config_key}[[:space:]]*=[[:space:]]*([^[:space:]#]+).*$/\\1/p" "$config_path" | tail -n 1) if [ -n "$configured_key" ]; then key="$configured_key" fi if grep -Eq '^[[:space:]]*unzoom_on_nav[[:space:]]*=[[:space:]]*false' "$config_path"; then unzoom=0 fi if grep -Eq '^[[:space:]]*nav_at_edge[[:space:]]*=[[:space:]]*stop' "$config_path"; then nav_at_edge=stop fi fi # Get focused pane ID from server (best-effort; empty is fine — we fall # through to the non-vim path below, which uses --current directly). pane_id=$("$herdr" pane current --current 2>/dev/null | grep -o '"pane_id"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true) # Check if focused pane is running vim/nvim as foreground process. is_vim=0 if [ -n "$pane_id" ] && pane_info=$("$herdr" pane process-info --current 2>/dev/null); then if echo "$pane_info" | grep -qiE '"name"[[:space:]]*:[[:space:]]*"(g?(view|l?n?vim?x?)(diff)?)"' 2>/dev/null; then is_vim=1 fi fi # Vim pane: forward the chord; the Neovim plugin decides movement + unzoom. if [ "$is_vim" -eq 1 ]; then exec "$herdr" pane send-keys "$pane_id" "$key" fi # --- Non-vim Herdr pane: unzoom if needed, then focus (wrapping at edges) --- # `pane edges` reports both edge flags and the zoomed state in one call. edges_out=$("$herdr" pane edges --current 2>/dev/null || true) # A zoomed pane fills the tab and reports itself at every edge, so the edge # flags are useless for the wrap decision. Unzoom (if enabled) so we can # trust them. If unzoom is disabled we leave zoom untouched and must NOT use # the (all-true) edge flags — wrap is skipped below in that case. edges_trusted=1 if printf '%s' "$edges_out" | grep -q '"zoomed"[[:space:]]*:[[:space:]]*true'; then if [ "$unzoom" -eq 1 ]; then "$herdr" pane zoom --off --current 2>/dev/null || true # Layout changed; re-read edges so the wrap check is accurate. edges_out=$("$herdr" pane edges --current 2>/dev/null || true) else edges_trusted=0 fi fi # Move to the neighbor in the requested direction. When already at the # requested edge (no neighbor there): wrap to the opposite side, or — when # nav_at_edge=stop — do nothing. Skip the edge check when the flags are # unreliable (still zoomed, unzoom disabled); in that case we can't tell # whether we're at an edge, so we just focus in the requested direction. if [ "$edges_trusted" -eq 1 ] && printf '%s' "$edges_out" | grep -q "\"$dir\"[[:space:]]*:[[:space:]]*true"; then if [ "$nav_at_edge" = stop ]; then exit 0 fi exec "$herdr" pane focus --direction "$opp" --current else exec "$herdr" pane focus --direction "$dir" --current fi