Files
fish-config/functions/fc.fish
T
rootiest e651566e14 docs(functions): split RETURNS into EXIT STATUS and stdout RETURNS
RETURNS previously conflated fish's $status exit code with genuine
stdout/printed output, e.g. rm listing "0/1" as if they were print
values rather than exit codes. Rename RETURNS to EXIT STATUS across
all 83 documented functions, and reintroduce RETURNS as a distinct
label reserved for the 15 functions that actually print to stdout.

Update build-manual.py's ENTRY_HEADS to render Exit Status before
Returns, manualtools.py's SECTIONS constant, and AGENTS.md's label
order and label-usage guidance to match. Add two verify-manual.py
regression tests: EXIT STATUS bodies must never contain stray
stdout/printed language, and Returns: must always render after
Exit Status: when both are present. Regenerate docs/fish-config.md.
2026-07-26 16:41:57 -04:00

63 lines
1.8 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 03-editors-and-viewers
#
# SYNOPSIS
# fc [command_prefix]
#
# DESCRIPTION
# Edits the last shell command -- or the most recent one matching a
# prefix -- in $EDITOR, then executes the result. Bash-style fc
# behaviour. Falls back to vi when $EDITOR is unset, and aborts without
# executing if the buffer is left empty.
#
# ARGUMENTS
# command_prefix Search history for the newest command matching this
#
# EXIT STATUS
# The edited command's exit status, or a message when history lookup
# found nothing.
#
# EXAMPLE
# fc
# fc git
function fc --description 'Edit and execute the last command (Bash-style fc)'
set -l tmpfile (mktemp /tmp/fish_fc.XXXXXX).fish
if count $argv >/dev/null
# Search for a specific previous command
builtin history search --max=1 "$argv" | sed 's/^[0-9-]* [0-9:]* //' >$tmpfile
else
# Grab the last 2 commands, then take the 2nd one (the one before 'fc')
# This avoids the --skip flag entirely
builtin history --max=2 | sed 's/^[0-9-]* [0-9:]* //' | sed -n 2p >$tmpfile
end
# Set editor with fallback
set -l editor $EDITOR
if test -z "$editor"
set editor vi
end
# Only open editor if we actually got a command
if test -s $tmpfile
$editor $tmpfile
# Final check if user cleared the file in the editor
if test -s $tmpfile
set -l command (cat $tmpfile)
rm $tmpfile
commandline -r "$command"
commandline -f execute
else
rm $tmpfile
echo "fc: Aborted (empty file)"
end
else
rm $tmpfile
echo "fc: Could not retrieve history"
end
end