Files
fish-config/functions/split.fish
T
rootiest 8dcbc62359 fix: guard and document the external tools PR #168 flagged as unguarded
PR #168's Notes section named several functions with a real
external-tool dependency that no `type -q`/`command -q`/`command -v`/
`which` guard covers anywhere in the tree, deliberately left out of
DEPENDENCIES to avoid breaking test_dependencies_resolve. Adds the
guard each was missing, then declares the dependency now that it
resolves:

- bkg, detach: nohup
- gitui: gitui (self-shadow; type -q -f to skip the function itself)
- play-media: mpv, vlc -- already guarded via `type -q -f $p` in a
  loop, just never recognized as one (see next point)
- steam-dl: systemd-inhibit, steam
- wake-lock: systemd-inhibit
- split, spwin, tab: wezterm, konsole (kitty already declared)

docs/verify-manual.py's guard-detection regex only matched `type -q
<name>` immediately, so `type -q -f $p` (the `-f` flag excludes
functions from the match, needed wherever a wrapper shadows a binary
of its own name) was invisible to it -- both as a direct guard and
through the loop-variable indirection. Broadened both patterns to
skip over any flags between `-q` and the name/variable.

split/spwin/tab dispatch on $TERM/$TERM_PROGRAM/$KONSOLE_VERSION to
pick which terminal-specific binary to call, per this repo's C4
convention -- but those env vars only prove the terminal type, not
that its CLI binary is on $PATH: they propagate over ssh, so sshing
out from Kitty/WezTerm inherits the var on a remote host that never
installed the binary. Same latent gap in clone/clonet, whose
clone-in-kitty is a function Kitty's own shell integration injects,
not present on a remote shell that only inherited $TERM. All five now
check the actual thing they are about to call, not just the env var
that selects it.

Also guards and documents three more real, previously-undeclared
dependencies found by the same audit, unrelated to PR #168's named
list but the identical pattern: fast-cli (fast), lock (loginctl),
ports (lsof), screensleep (busctl).

docs/fish-config.md regenerated to match.
2026-09-22 22:40:33 -04:00

97 lines
3.1 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 08-terminal-management
#
# COMPONENT
# integrations/window-mgmt
#
# DEPENDENCIES
# kitty, wezterm
#
# SYNOPSIS
# split [-h | -v] [command...]
#
# DESCRIPTION
# Opens a new pane split in Kitty or WezTerm, optionally running a
# command in it. Defaults to a horizontal (bottom) split. The new pane
# inherits the current working directory.
#
# ARGUMENTS
# -h, --horizontal Open a horizontal split (default)
# -v, --vertical Open a vertical split
# command... Command to run in the new pane; opens a bare fish
# shell if omitted
#
# EXIT STATUS
# 0 Pane opened successfully
# 1 Not running inside Kitty or WezTerm
#
# EXAMPLE
# split
# split -v nvim README.md
function split --description 'Run a command in a new terminal split'
# -h is --horizontal here (see this function's own ARGUMENTS),
# so only the long form may reach the renderer.
test "$argv[1]" = --help; and __fish_help_header (status current-function) --help; and return 0
# Opinionated guard (C4): integrations disabled
if not __fish_config_op_enabled (status current-function)
__fish_palette
echo "$c_err"'split: disabled by __fish_config_op_integrations'"$c_reset" >&2
return 1
end
set -l is_kitty 0
set -l is_wezterm 0
if test "$TERM" = xterm-kitty
set is_kitty 1
else if test "$TERM_PROGRAM" = WezTerm
set is_wezterm 1
else
echo "Error: The 'split' command requires Kitty or WezTerm terminal." >&2
return 1
end
# $TERM/$TERM_PROGRAM only prove the terminal type, not that its CLI
# binary is on $PATH -- e.g. sshing out from Kitty/WezTerm inherits the
# env var on the remote host without the binary. Check explicitly.
if test $is_kitty -eq 1; and not type -q kitty
echo "Error: 'split' detected Kitty but the kitty binary is not installed." >&2
return 1
else if test $is_wezterm -eq 1; and not type -q wezterm
echo "Error: 'split' detected WezTerm but the wezterm binary is not installed." >&2
return 1
end
set -l kitty_loc hsplit
set -l wez_loc --bottom
switch $argv[1]
case -h --horizontal
set kitty_loc hsplit
set wez_loc --bottom
set -e argv[1]
case -v --vertical
set kitty_loc vsplit
set wez_loc --right
set -e argv[1]
end
if test (count $argv) -gt 0
if test $is_kitty -eq 1
kitty @ launch --location=$kitty_loc --cwd=$PWD env HIDE_GREETING=1 fish -c "$argv; exec fish"
else if test $is_wezterm -eq 1
wezterm cli split-pane $wez_loc --cwd $PWD -- env HIDE_GREETING=1 fish -c "$argv; exec fish" >/dev/null
end
else
if test $is_kitty -eq 1
kitty @ launch --location=$kitty_loc --cwd=$PWD env HIDE_GREETING=1 fish -c "exec fish"
else if test $is_wezterm -eq 1
wezterm cli split-pane $wez_loc --cwd $PWD -- env HIDE_GREETING=1 fish -c "exec fish" >/dev/null
end
end
end