Files
fish-shell/share/functions/psub.fish
Johannes Altmanninger d835c5252a Prepare to not localize private function descriptions
The overwhelming majority of localizable messages comes from
completions:

	$ ls share/completions/ | wc -l
	$ 1048

OTOH functions also contribute a small amount, mostly via their
descriptions (so usually just one per file).

	$ ls share/functions/ | wc -l
	$ 237

Most of these are private and almost never shown to the user, so it's
not worth bothering translators with them. So:

- Skip private (see the parent commit) and deprecated functions.
- Skip wrapper functions like grep (where the translation seems to
  be provided by apropos), and even the English description is not
  helpful.
  - Assume that most real systems have "seq", "realpath" etc.,
    so it's no use providing our own translations for our fallbacks.
- Mark fish's own functions as tier1, and some barely-used functiosn
  and completions as tier3, so we can order them that way in
  po/*.po. Most translators should only look at tier1 and tier2.
  In future we could disable localization for tier3.

See the explanation at the bottom of
tests/checks/message-localization-tier-is-declared.fish

Part of #11833
2025-09-30 11:47:26 +02:00

70 lines
2.1 KiB
Fish

# localization: tier1
function psub --description "Read from stdin into a file and output the filename. Remove the file when the command that called psub exits."
set -l options -x 'f,F' h/help f/file F/fifo 's/suffix=' T-testing
argparse -n psub --max-args=0 $options -- $argv
or return
if set -q _flag_help
__fish_print_help psub
return 0
end
set -l dirname
set -l filename
set -l funcname
if not status --is-command-substitution
printf (_ "%s: Not inside of command substitution") psub >&2
return 1
end
if set -q _flag_fifo
# Write output to pipe. This needs to be done in the background so
# that the command substitution exits without needing to wait for
# all the commands to exit.
set dirname (__fish_mktemp_relative -d .psub)
or return 1
set filename $dirname/psub.fifo"$_flag_suffix"
command mkfifo $filename
# Note that if we were to do the obvious `cat >$filename &`, we would deadlock
# because $filename may be opened before the fork. Use tee to ensure it is opened
# after the fork.
command tee $filename >/dev/null &
else if test -z "$_flag_suffix"
set filename (__fish_mktemp_relative .psub)
or return 1
command cat >$filename
else
set dirname (__fish_mktemp_relative -d .psub)
or return 1
set filename "$dirname/psub$_flag_suffix"
command cat >$filename
end
# Write filename to stdout
echo $filename
# This flag isn't documented. It's strictly for our unit tests.
if set -q _flag_testing
return
end
# Find unique function name
while true
set funcname __fish_psub_(random)
if not functions $funcname >/dev/null 2>/dev/null
break
end
end
# Make sure we erase file when caller exits
function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable dirname --inherit-variable funcname
command rm $filename
if test -n "$dirname"
command rmdir $dirname
end
functions -e $funcname
end
end