Files
fish-config/functions/_fish_deps_marktext_appimage.fish
T
rootiest 3414f81cb6 feat(tests): add shadow-classification lint; fix real cp/mv/less bugs
New Phase 1b in tests/run-tests.fish: catches a bare C1-shadowed-command
call in a functions/*.fish body with no matching uses-shadow(name) or
self-limiting(name) in that function's own CLASSIFICATION header. This
is exactly the check discussed after the rm and cd audits -- runtime
auto-unwrapping isn't viable in fish (there's no hook finer than
shadowing itself, and rewriting behavior invisibly at runtime is its
own footgun); a static lint using the CLASSIFICATION tag as the
declared-intentional marker is. Scoped to functions/*.fish only: the
one-function-per-file convention there makes body extraction exact
with no block-depth parser needed.

Added a new self-limiting(name) tag to the schema for the case a bare
call is safe not because the caller did anything, but because the
shadow's own logic already neutralizes the override: rm's and mkdir's
flag checks (verified precisely -- rm falls back to command rm for any
flag except a bare -r/-R/--recursive alone, which still routes to
trash; mkdir falls back to command mkdir -p for any flag, no
exception), and grep/fgrep/egrep/dir/vdir/cat's own tty auto-detection
(--color=auto, and bat's default color behavior -- verified
byte-identical to stock cat when piped, since bat also auto-disables
highlighting on a non-terminal). Explicit and durable rather than a
silent lint exemption: if a shadow's bypass condition is ever
weakened, every self-limiting site is one grep away instead of
silently wrong.

Running the first draft of the lint surfaced three more real bugs,
none previously audited:

- config-help.fish's --man pager path checks `type -q less` (proving
  it wants the real less binary specifically, for less-only -R/+N
  flag syntax) then called it bare, routing through our own
  $PAGER -> ov -> less -> more -> cat fallback chain instead -- which
  could hand those less-specific flags to a completely different
  program. Now command less.
- _fish_deps_install.fish and _fish_deps_update.fish's binary-upgrade
  paths cp a freshly downloaded binary over an already-installed one
  with no existence guard -- the update flow's target is guaranteed to
  already exist. Our cp shadow forces -i unconditionally (a plain
  alias, not flag-aware like rm's), so this would hang waiting on a
  confirmation prompt in any non-interactive run. Now command cp.
  Same two files' lazydocker install path piped curl output into bare
  bash, invoking our shell-switch wrapper instead of a plain
  subshell. Now command bash.
- agents-init.fish's AGENTS.md/CLAUDE.md relocation calls mv bare in
  four places; each is already guarded by a preceding test -f check on
  the destination, so the -i alias was unlikely to ever fire in
  practice, but explicit command mv removes the reliance on that guard
  entirely rather than leaving it as the only thing standing between a
  file move and an unattended hang.

The remaining ~65 flagged call sites across ~24 files were reviewed
individually and tagged self-limiting(rm)/self-limiting(mkdir)
(verified flagged with -f/-rf or -p) and self-limiting(grep)/
self-limiting(cat) (verified piped, captured, or -q/-c; none display
color to a human), plus uses-shadow(ls) for two existence-check-only
calls (cffetch.fish, ffetch.fish) whose output is redirected to
/dev/null.
2026-09-21 21:26:55 -04:00

70 lines
2.2 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CLASSIFICATION
# self-limiting(rm,mkdir), bypasses-shadow(mv), destructive, network
#
# SYNOPSIS
# _fish_deps_marktext_appimage
#
# DESCRIPTION
# Installs (or upgrades in place) MarkText as an AppImage at
# ~/.local/bin/marktext. This is the install path for systems whose
# package manager does not carry MarkText at all -- upstream ships only
# the AUR package (marktext-bin) and its own GitHub release assets, so
# apt/dnf/brew have nothing to offer.
#
# The release assets embed their version in the filename, so there is no
# stable /releases/latest/download URL; the download URL is read from the
# GitHub API instead.
#
# Upstream builds the Linux AppImage for x86_64 only.
#
# EXIT STATUS
# 0 MarkText installed at ~/.local/bin/marktext
# 1 Unsupported architecture, or the download or install failed
#
# EXAMPLE
# _fish_deps_marktext_appimage
#
# NOTES
# An AppImage needs FUSE to self-mount. Where FUSE is unavailable, run it
# as `marktext --appimage-extract-and-run`.
function _fish_deps_marktext_appimage
set -l arch (uname -m)
if test "$arch" != x86_64
echo " MarkText publishes a Linux AppImage for x86_64 only (this is $arch)." >&2
return 1
end
if not type -q curl
echo " curl is required to download the MarkText AppImage." >&2
return 1
end
set -l url (curl -fsSL https://api.github.com/repos/marktext/marktext/releases/latest |
string match -r '"browser_download_url":\s*"([^"]*-linux-[^"]*\.AppImage)"')[2]
if test -z "$url"
echo " Could not find a Linux AppImage in the latest MarkText release." >&2
return 1
end
set -l dest "$HOME/.local/bin/marktext"
set -l tmp (mktemp -d)
set -l ok 0
curl -fL "$url" -o "$tmp/marktext"
and mkdir -p (dirname $dest)
and chmod +x "$tmp/marktext"
# Replace via mv, not a write into $dest: overwriting a running AppImage
# in place corrupts the live mount.
and command mv -f "$tmp/marktext" "$dest"
and set ok 1
rm -rf $tmp
if test $ok -eq 1
fish_add_path "$HOME/.local/bin"
end
test $ok -eq 1
end