Files
fish-config/functions/replay.fish
T
rootiest 859f14a6e9 feat(functions): tag CLASSIFICATION across functions/ and conf.d/
Audits every function's interaction with the C1-shadowed commands
(uses-shadow/bypasses-shadow) and general hazards (destructive,
network, blocking-prompt) per the CLASSIFICATION schema.

Delegated the initial mechanical sweep to agy, then reviewed every
file by hand: fixed a systemic double-blank-comment-line formatting
bug from the delegate pass, and corrected several judgment errors
found on review -- three false blocking-prompt tags where a fish
'read' was consuming piped input rather than waiting on a terminal
(open-url.fish, sbver.fish, play-media.fish, now untagged entirely),
a blocking-prompt tag on mkrep.fish despite its documented --yes
escape hatch, an untagged read in jobrunner.fish's own baseless
blocking-prompt claim (removed, along with a destructive tag on
cleanup of its own mktemp output -- the schema explicitly excludes
that), the same own-output-cleanup false positive on
_zellij_dump_log.fish's destructive tag, an interactive fzf-gated
confirmation on logs.fish and replay.fish's piped read misread the
same way as the first three, and a uses-shadow(mkdir) on mkcd.fish
that actually belongs to the _fish_mkdir_p helper it delegates to,
not to mkcd itself.
2026-09-21 21:26:44 -04:00

77 lines
2.9 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 14-miscellaneous
#
# CLASSIFICATION
# bypasses-shadow(bash,cd)
#
# SYNOPSIS
# replay <commands>
#
# DESCRIPTION
# Runs the given commands in Bash and replays any resulting environment
# variable, alias, and directory changes back into the current Fish
# session. Useful for sourcing Bash-only scripts.
#
# ARGUMENTS
# commands Bash command string to execute and replay
#
# EXIT STATUS
# 0 Commands ran successfully and changes were replayed
# 1 Bash command exited with a non-zero status
#
# EXAMPLE
# replay "source ~/.bashrc"
# replay "export FOO=bar"
function replay --description 'Run Bash commands replaying changes in Fish'
switch "$argv"
case -v --version
echo "replay, version 1.2.1"
case "" -h --help
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""replay$c_reset $c_arg""<commands>$c_reset Run Bash commands replaying changes in Fish"
echo "$c_head""Options:$c_reset"
echo " $c_flag-v$c_reset or $c_flag--version$c_reset Print version"
echo " $c_flag-h$c_reset or $c_flag--help$c_reset Print this help message"
case \*
set --local env
set --local sep @$fish_pid(random)(command date +%s)
set --local argv $argv[1] (string escape -- $argv[2..-1])
set --local out (command bash -c "
$argv
status=\$?
[ \$status -gt 0 ] && exit \$status
command compgen -e | command awk -v sep=$sep '{
gsub(/\n/, \"\\\n\", ENVIRON[\$0])
print \$0 sep ENVIRON[\$0]
}' && alias
") || return
string replace --all -- \\n \n (
for line in $out
if string split -- $sep $line | read --local --line name value
set --append env $name
contains -- $name SHLVL PS1 BASH_FUNC || test "$$name" = "$value" && continue
if test "$name" = PATH
echo set PATH (string split -- : $value | string replace --regex --all -- '(^.*$)' '"$1"')
else if test "$name" = PWD
echo builtin cd "\"$value\""
else
echo "set --global --export $name "(string escape -- $value)
end
else
set --query env[1] && string match --entire --regex -- "^alias" $line || echo "echo \"$line\""
end
end | string replace --all -- \$ \\\$
for name in (set --export --names)
contains -- $name $env || echo "set --erase $name"
end
) | source
end
end